2025-05-02 21:43:51 +00:00
|
|
|
import { ITransactionManager } from "@/core/common/infrastructure/database";
|
2025-05-20 10:08:24 +00:00
|
|
|
import { logger } from "@/lib/logger";
|
2025-05-09 10:45:32 +00:00
|
|
|
import { Collection, Result } from "@repo/rdx-utils";
|
2025-04-01 14:26:15 +00:00
|
|
|
import { IInvoiceService, Invoice } from "../domain";
|
2025-03-18 08:05:00 +00:00
|
|
|
|
|
|
|
|
export class ListInvoicesUseCase {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly invoiceService: IInvoiceService,
|
|
|
|
|
private readonly transactionManager: ITransactionManager
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
public execute(): Promise<Result<Collection<Invoice>, Error>> {
|
|
|
|
|
return this.transactionManager.complete(async (transaction) => {
|
|
|
|
|
try {
|
|
|
|
|
return await this.invoiceService.findInvoices(transaction);
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
logger.error(error as Error);
|
|
|
|
|
return Result.fail(error as Error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|