71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import type { Criteria } from "@repo/rdx-criteria/server";
|
|
import type { TINNumber, 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 { CustomerSummary } from "../models";
|
|
import type { ICustomerRepository } from "../repositories";
|
|
|
|
export interface ICustomerFinder {
|
|
findCustomerById(
|
|
companyId: UniqueID,
|
|
customerId: UniqueID,
|
|
transaction?: Transaction
|
|
): Promise<Result<Customer, Error>>;
|
|
|
|
findCustomerByTIN(
|
|
companyId: UniqueID,
|
|
tin: TINNumber,
|
|
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<CustomerSummary>, 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);
|
|
}
|
|
|
|
findCustomerByTIN(
|
|
companyId: UniqueID,
|
|
tin: TINNumber,
|
|
transaction?: Transaction
|
|
): Promise<Result<Customer, Error>> {
|
|
return this.repository.getByTINInCompany(companyId, tin, 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<CustomerSummary>, Error>> {
|
|
return this.repository.findByCriteriaInCompany(companyId, criteria, transaction);
|
|
}
|
|
}
|