lecoffre-back/src/common/repositories/ContactRepository.ts
2023-07-04 18:09:45 +02:00

30 lines
751 B
TypeScript

import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { Contacts, Customers } from "@prisma/client";
@Service()
export default class ContactRepository extends BaseRepository {
constructor(private database: Database) {
super();
}
protected get model() {
return this.database.getClient().contacts;
}
protected get instanceDb() {
return this.database.getClient();
}
/**
* @description : Find unique customer by email
*/
public async findOneByEmail(email: string): Promise<(Contacts & {customers: Customers | null}) | null> {
return this.model.findUnique({
where: {
email: email,
},
include: { customers: true }
});
}
}