FactuGES_ERP/modules/customer-invoices/src/api/application/get-customer-invoice.use-case.ts
2025-06-12 08:55:17 +02:00

27 lines
916 B
TypeScript

import { UniqueID } from "@/core/common/domain";
import { ITransactionManager } from "@/core/common/infrastructure/database";
import { logger } from "@/lib/logger";
import { Result } from "@repo/rdx-utils";
import { CustomerInvoice, ICustomerInvoiceService } from "../domain";
export class GetCustomerInvoiceUseCase {
constructor(
private readonly customerInvoiceService: ICustomerInvoiceService,
private readonly transactionManager: ITransactionManager
) {}
public execute(customerInvoiceID: UniqueID): Promise<Result<CustomerInvoice, Error>> {
return this.transactionManager.complete(async (transaction) => {
try {
return await this.customerInvoiceService.findCustomerInvoiceById(
customerInvoiceID,
transaction
);
} catch (error: unknown) {
logger.error(error as Error);
return Result.fail(error as Error);
}
});
}
}