45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { Customers } from "@prisma/client";
|
|
import CustomersRepository from "@Repositories/CustomersRepository";
|
|
import BaseService from "@Services/BaseService";
|
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
|
import { Service } from "typedi";
|
|
|
|
@Service()
|
|
export default class CustomersService extends BaseService {
|
|
constructor(private customerRepository: CustomersRepository) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @description : Get all Customers
|
|
* @throws {Error} If Customers cannot be get
|
|
*/
|
|
public async get(query: any) {
|
|
return this.customerRepository.findMany(query);
|
|
}
|
|
|
|
/**
|
|
* @description : Create a new customer
|
|
* @throws {Error} If customer cannot be created
|
|
*/
|
|
public async create(customerEntity: Customer): Promise<Customers> {
|
|
return this.customerRepository.create(customerEntity);
|
|
}
|
|
|
|
/**
|
|
* @description : Modify a customer
|
|
* @throws {Error} If customer cannot be modified
|
|
*/
|
|
public async update(uid: string, customerEntity: Customer): Promise<Customers> {
|
|
return this.customerRepository.update(uid, customerEntity);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a customer by uid
|
|
* @throws {Error} If customer cannot be get by uid
|
|
*/
|
|
public async getByUid(uid: string, query?: any): Promise<Customers> {
|
|
return this.customerRepository.findOneByUid(uid, query);
|
|
}
|
|
}
|