89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
|
|
import type { CustomerInvoiceListDTO } from "@erp/customer-invoices/api/infrastructure";
|
||
|
|
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 { CustomerInvoice, ICustomerInvoiceRepository } from "../../../domain";
|
||
|
|
|
||
|
|
export interface IIssuedInvoiceFinder {
|
||
|
|
findIssuedInvoiceById(
|
||
|
|
companyId: UniqueID,
|
||
|
|
invoiceId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<CustomerInvoice, Error>>;
|
||
|
|
|
||
|
|
issuedInvoiceExists(
|
||
|
|
companyId: UniqueID,
|
||
|
|
invoiceId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<boolean, Error>>;
|
||
|
|
|
||
|
|
findIssuedInvoicesByCriteria(
|
||
|
|
companyId: UniqueID,
|
||
|
|
criteria: Criteria,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<Collection<CustomerInvoiceListDTO>, Error>>;
|
||
|
|
}
|
||
|
|
|
||
|
|
export class IssuedInvoiceFinder implements IIssuedInvoiceFinder {
|
||
|
|
constructor(private readonly repository: ICustomerInvoiceRepository) {}
|
||
|
|
|
||
|
|
async findIssuedInvoiceById(
|
||
|
|
companyId: UniqueID,
|
||
|
|
invoiceId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<CustomerInvoice, Error>> {
|
||
|
|
return this.repository.getIssuedInvoiceByIdInCompany(companyId, invoiceId, transaction, {});
|
||
|
|
}
|
||
|
|
|
||
|
|
async findProformaById(
|
||
|
|
companyId: UniqueID,
|
||
|
|
proformaId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<CustomerInvoice, Error>> {
|
||
|
|
return this.repository.getProformaByIdInCompany(companyId, proformaId, transaction, {});
|
||
|
|
}
|
||
|
|
|
||
|
|
async issuedInvoiceExists(
|
||
|
|
companyId: UniqueID,
|
||
|
|
invoiceId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<boolean, Error>> {
|
||
|
|
return this.repository.existsByIdInCompany(companyId, invoiceId, transaction, {
|
||
|
|
is_proforma: false,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
async proformaExists(
|
||
|
|
companyId: UniqueID,
|
||
|
|
proformaId: UniqueID,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<boolean, Error>> {
|
||
|
|
return this.repository.existsByIdInCompany(companyId, proformaId, transaction, {
|
||
|
|
is_proforma: true,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
async findIssuedInvoicesByCriteria(
|
||
|
|
companyId: UniqueID,
|
||
|
|
criteria: Criteria,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<Collection<CustomerInvoiceListDTO>, Error>> {
|
||
|
|
return this.repository.findIssuedInvoicesByCriteriaInCompany(
|
||
|
|
companyId,
|
||
|
|
criteria,
|
||
|
|
transaction,
|
||
|
|
{}
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
async findProformasByCriteria(
|
||
|
|
companyId: UniqueID,
|
||
|
|
criteria: Criteria,
|
||
|
|
transaction?: Transaction
|
||
|
|
): Promise<Result<Collection<CustomerInvoiceListDTO>, Error>> {
|
||
|
|
return this.repository.findProformasByCriteriaInCompany(companyId, criteria, transaction, {});
|
||
|
|
}
|
||
|
|
}
|