Informe de factura

This commit is contained in:
David Arranz 2025-11-04 19:43:37 +01:00
parent 29b06a316e
commit 13e2ca5235
2 changed files with 3 additions and 56 deletions

View File

@ -1,54 +0,0 @@
import { EntityNotFoundError, ITransactionManager } from "@erp/core/api";
import { UniqueID } from "@repo/rdx-ddd";
import { Result } from "@repo/rdx-utils";
import { CustomerInvoiceApplicationService } from "../../../domain";
type DeleteCustomerInvoiceUseCaseInput = {
companyId: UniqueID;
invoice_id: string;
};
export class DeleteCustomerInvoiceUseCase {
constructor(
private readonly service: CustomerInvoiceApplicationService,
private readonly transactionManager: ITransactionManager
) {}
public execute(params: DeleteCustomerInvoiceUseCaseInput) {
const { invoice_id, companyId } = params;
const idOrError = UniqueID.create(invoice_id);
if (idOrError.isFailure) {
return Result.fail(idOrError.error);
}
const invoiceId = idOrError.data;
return this.transactionManager.complete(async (transaction) => {
try {
const existsCheck = await this.service.existsByIdInCompany(
companyId,
invoiceId,
transaction
);
if (existsCheck.isFailure) {
return Result.fail(existsCheck.error);
}
const invoiceExists = existsCheck.data;
if (!invoiceExists) {
return Result.fail(
new EntityNotFoundError("Customer invoice", "id", invoiceId.toString())
);
}
return await this.service.deleteInvoiceByIdInCompany(companyId, invoiceId, transaction);
} catch (error: unknown) {
return Result.fail(error as Error);
}
});
}
}

View File

@ -3,19 +3,20 @@ import path from "node:path";
import { Presenter } from "@erp/core/api"; import { Presenter } from "@erp/core/api";
import * as handlebars from "handlebars"; import * as handlebars from "handlebars";
import { CustomerInvoice } from "../../../../domain"; import { CustomerInvoice } from "../../../../domain";
import { CustomerInvoiceReportPresenter, CustomerInvoiceFullPresenter } from "../../../presenters";
export class CustomerInvoiceReportHTMLPresenter extends Presenter { export class CustomerInvoiceReportHTMLPresenter extends Presenter {
toOutput(customerInvoice: CustomerInvoice): string { toOutput(customerInvoice: CustomerInvoice): string {
const dtoPresenter = this.presenterRegistry.getPresenter({ const dtoPresenter = this.presenterRegistry.getPresenter({
resource: "customer-invoice", resource: "customer-invoice",
projection: "FULL", projection: "FULL",
}); }) as CustomerInvoiceFullPresenter;
const prePresenter = this.presenterRegistry.getPresenter({ const prePresenter = this.presenterRegistry.getPresenter({
resource: "customer-invoice", resource: "customer-invoice",
projection: "REPORT", projection: "REPORT",
format: "JSON", format: "JSON",
}); }) as CustomerInvoiceReportPresenter;
const invoiceDTO = dtoPresenter.toOutput(customerInvoice); const invoiceDTO = dtoPresenter.toOutput(customerInvoice);
const prettyDTO = prePresenter.toOutput(invoiceDTO); const prettyDTO = prePresenter.toOutput(invoiceDTO);