47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { Customers, Prisma } from "@prisma/client";
|
|
import CustomersRepository from "@Repositories/CustomersRepository";
|
|
import ContactRepository from "@Repositories/ContactRepository";
|
|
import BaseService from "@Services/BaseService";
|
|
import { Service } from "typedi";
|
|
|
|
@Service()
|
|
export default class CustomersService extends BaseService {
|
|
constructor(private customerRepository: CustomersRepository, private contactRepository: ContactRepository) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @description : Get all Customers
|
|
* @throws {Error} If Customers cannot be get
|
|
*/
|
|
public async get(query: Prisma.CustomersFindManyArgs): Promise<Customers[]> {
|
|
return this.customerRepository.findMany(query);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a customer by uid
|
|
* @throws {Error} If customer cannot be get by uid
|
|
*/
|
|
public async getByUid(uid: string, query?: Prisma.CustomersInclude): Promise<Customers | null> {
|
|
return this.customerRepository.findOneByUid(uid, query);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a customer by contact uid
|
|
* @throws {Error} If customer cannot be get by contact uid
|
|
*/
|
|
public async getByContact(contactUid: string): Promise<Customers | null> {
|
|
return this.customerRepository.findOneByContact(contactUid);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a customer by contact uid
|
|
* @throws {Error} If customer cannot be get by contact uid
|
|
*/
|
|
public async getByEmail(contactUid: string) {
|
|
return this.contactRepository.findOneByEmail(contactUid);
|
|
}
|
|
|
|
|
|
}
|