Informe de factura
This commit is contained in:
parent
29b06a316e
commit
13e2ca5235
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -3,19 +3,20 @@ import path from "node:path";
|
||||
import { Presenter } from "@erp/core/api";
|
||||
import * as handlebars from "handlebars";
|
||||
import { CustomerInvoice } from "../../../../domain";
|
||||
import { CustomerInvoiceReportPresenter, CustomerInvoiceFullPresenter } from "../../../presenters";
|
||||
|
||||
export class CustomerInvoiceReportHTMLPresenter extends Presenter {
|
||||
toOutput(customerInvoice: CustomerInvoice): string {
|
||||
const dtoPresenter = this.presenterRegistry.getPresenter({
|
||||
resource: "customer-invoice",
|
||||
projection: "FULL",
|
||||
});
|
||||
}) as CustomerInvoiceFullPresenter;
|
||||
|
||||
const prePresenter = this.presenterRegistry.getPresenter({
|
||||
resource: "customer-invoice",
|
||||
projection: "REPORT",
|
||||
format: "JSON",
|
||||
});
|
||||
}) as CustomerInvoiceReportPresenter;
|
||||
|
||||
const invoiceDTO = dtoPresenter.toOutput(customerInvoice);
|
||||
const prettyDTO = prePresenter.toOutput(invoiceDTO);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user