57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
|
|
import type { Criteria } from "@repo/rdx-criteria/server";
|
||
|
|
import type { UniqueID } from "@repo/rdx-ddd";
|
||
|
|
import type { Collection, Result } from "@repo/rdx-utils";
|
||
|
|
import type { Transaction } from "sequelize";
|
||
|
|
|
||
|
|
import type { Customer } from "../../domain";
|
||
|
|
import type { CustomerListDTO } from "../dtos";
|
||
|
|
import type { ICustomerRepository } from "../repositories";
|
||
|
|
|
||
|
|
export interface ICustomerFinder {
|
||
|
|
findCustomerById(
|
||
|
|
companyId: UniqueID,
|
||
|
|
invoiceId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<Customer, Error>>;
|
||
|
|
|
||
|
|
customerExists(
|
||
|
|
companyId: UniqueID,
|
||
|
|
invoiceId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<boolean, Error>>;
|
||
|
|
|
||
|
|
findCustomersByCriteria(
|
||
|
|
companyId: UniqueID,
|
||
|
|
criteria: Criteria,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<Collection<CustomerListDTO>, Error>>;
|
||
|
|
}
|
||
|
|
|
||
|
|
export class CustomerFinder implements ICustomerFinder {
|
||
|
|
constructor(private readonly repository: ICustomerRepository) {}
|
||
|
|
|
||
|
|
async findCustomerById(
|
||
|
|
companyId: UniqueID,
|
||
|
|
customerId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<Customer, Error>> {
|
||
|
|
return this.repository.getByIdInCompany(companyId, customerId, transaction);
|
||
|
|
}
|
||
|
|
|
||
|
|
async customerExists(
|
||
|
|
companyId: UniqueID,
|
||
|
|
customerId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<boolean, Error>> {
|
||
|
|
return this.repository.existsByIdInCompany(companyId, customerId, transaction);
|
||
|
|
}
|
||
|
|
|
||
|
|
async findCustomersByCriteria(
|
||
|
|
companyId: UniqueID,
|
||
|
|
criteria: Criteria,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<Collection<CustomerListDTO>, Error>> {
|
||
|
|
return this.repository.findByCriteriaInCompany(companyId, criteria, transaction);
|
||
|
|
}
|
||
|
|
}
|