2025-06-11 13:13:21 +00:00
|
|
|
import { ITransactionManager } from "@erp/core/api";
|
2025-05-27 17:47:03 +00:00
|
|
|
import { Criteria } from "@repo/rdx-criteria/server";
|
2025-05-09 10:45:32 +00:00
|
|
|
import { Collection, Result } from "@repo/rdx-utils";
|
2025-05-26 10:38:45 +00:00
|
|
|
import { Transaction } from "sequelize";
|
2025-06-11 15:13:44 +00:00
|
|
|
import { ICustomerInvoiceService, CustomerInvoice } from "../domain";
|
2025-03-18 08:05:00 +00:00
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
export class ListCustomerInvoicesUseCase {
|
2025-03-18 08:05:00 +00:00
|
|
|
constructor(
|
2025-06-11 15:13:44 +00:00
|
|
|
private readonly customerCustomerInvoiceService: ICustomerInvoiceService,
|
2025-03-18 08:05:00 +00:00
|
|
|
private readonly transactionManager: ITransactionManager
|
|
|
|
|
) {}
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
public execute(criteria: Criteria): Promise<Result<Collection<CustomerInvoice>, Error>> {
|
2025-05-26 10:38:45 +00:00
|
|
|
return this.transactionManager.complete(async (transaction: Transaction) => {
|
2025-03-18 08:05:00 +00:00
|
|
|
try {
|
2025-06-11 15:13:44 +00:00
|
|
|
return await this.customerCustomerInvoiceService.findCustomerInvoices(criteria, transaction);
|
2025-03-18 08:05:00 +00:00
|
|
|
} catch (error: unknown) {
|
|
|
|
|
return Result.fail(error as Error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|