134 lines
4.1 KiB
TypeScript
134 lines
4.1 KiB
TypeScript
|
|
// modules/invoice/infrastructure/invoice-dependencies.factory.ts
|
|||
|
|
|
|||
|
|
import {
|
|||
|
|
type IDocumentSigningService,
|
|||
|
|
type ITransactionManager,
|
|||
|
|
type ModuleParams,
|
|||
|
|
buildCoreDocumentsDI,
|
|||
|
|
buildTransactionManager,
|
|||
|
|
} from "@erp/core/api";
|
|||
|
|
|
|||
|
|
import {
|
|||
|
|
type GetIssuedInvoiceByIdUseCase,
|
|||
|
|
type ListIssuedInvoicesUseCase,
|
|||
|
|
type ReportIssuedInvoiceUseCase,
|
|||
|
|
buildGetIssuedInvoiceByIdUseCase,
|
|||
|
|
buildIssuedInvoiceFinder,
|
|||
|
|
buildIssuedInvoiceSnapshotBuilders,
|
|||
|
|
buildListIssuedInvoicesUseCase,
|
|||
|
|
buildReportIssuedInvoiceUseCase,
|
|||
|
|
} from "../../application/issued-invoices";
|
|||
|
|
import { IssuedInvoiceDocumentPipelineFactory } from "../documents";
|
|||
|
|
|
|||
|
|
import { buildRepository } from "./repositories.di";
|
|||
|
|
|
|||
|
|
export type IssuedInvoicesDeps = {
|
|||
|
|
useCases: {
|
|||
|
|
list_issued_invoices: () => ListIssuedInvoicesUseCase;
|
|||
|
|
get_issued_invoice_by_id: () => GetIssuedInvoiceByIdUseCase;
|
|||
|
|
report_issued_invoice: () => ReportIssuedInvoiceUseCase;
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
export function buildIssuedInvoicesDI(params: ModuleParams) {
|
|||
|
|
const { database, env } = params;
|
|||
|
|
const { documentRenderers, documentSigning, documentStorage } = buildCoreDocumentsDI(env);
|
|||
|
|
|
|||
|
|
const transactionManager = buildTransactionManager(database);
|
|||
|
|
const repository = buildRepository(database);
|
|||
|
|
|
|||
|
|
// --------------------------------------------------------------------------
|
|||
|
|
// 4️⃣ Finder + snapshot builders (APPLICATION)
|
|||
|
|
// --------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
const finder = buildIssuedInvoiceFinder(repository);
|
|||
|
|
const snapshotBuilders = buildIssuedInvoiceSnapshotBuilders();
|
|||
|
|
|
|||
|
|
const issuedInvoiceDocumentPipeline = new IssuedInvoiceDocumentPipelineFactory({
|
|||
|
|
renderer: documentRenderers.fastReportRenderer,
|
|||
|
|
}).create;
|
|||
|
|
|
|||
|
|
// --------------------------------------------------------------------------
|
|||
|
|
// 5️⃣ Use Case
|
|||
|
|
// --------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
useCases: {
|
|||
|
|
list_issued_invoices: () =>
|
|||
|
|
buildListIssuedInvoicesUseCase({
|
|||
|
|
finder,
|
|||
|
|
itemSnapshotBuilder: snapshotBuilders.list,
|
|||
|
|
transactionManager,
|
|||
|
|
}),
|
|||
|
|
get_issued_invoice_by_id: () =>
|
|||
|
|
buildGetIssuedInvoiceByIdUseCase({
|
|||
|
|
finder,
|
|||
|
|
fullSnapshotBuilder: snapshotBuilders.full,
|
|||
|
|
transactionManager,
|
|||
|
|
}),
|
|||
|
|
report_issued_invoice: () =>
|
|||
|
|
buildReportIssuedInvoiceUseCase({
|
|||
|
|
finder,
|
|||
|
|
fullSnapshotBuilder: snapshotBuilders.full,
|
|||
|
|
reportSnapshotBuilder: snapshotBuilders.report,
|
|||
|
|
documentService: issuedInvoiceDocumentService,
|
|||
|
|
transactionManager,
|
|||
|
|
}),
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
reportIssuedInvoiceUseCase,
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function buildIssuedInvoicesDependencies(deps: {
|
|||
|
|
documentSigningService: IDocumentSigningService;
|
|||
|
|
certificateResolver: ICertificateResolver;
|
|||
|
|
|
|||
|
|
transactionManager: ITransactionManager;
|
|||
|
|
}): IssuedInvoicesDeps {
|
|||
|
|
const { database, env } = params;
|
|||
|
|
const templateRootPath = env.TEMPLATES_PATH;
|
|||
|
|
const documentRootPath = env.DOCUMENTS_PATH;
|
|||
|
|
|
|||
|
|
/** Infraestructura */
|
|||
|
|
const repository = buildRepository(database);
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
const snapshotBuilders = buildIssuedInvoiceSnapshotBuilders();
|
|||
|
|
const finder = buildIssuedInvoiceFinder(repository);
|
|||
|
|
const renderers = buildIssuedInvoiceReportRenderers(templateRootPath, documentRootPath);
|
|||
|
|
|
|||
|
|
const reportService = buildIssuedInvoiceReportService(
|
|||
|
|
renderers.fastReportPDFRenderer,
|
|||
|
|
signingService,
|
|||
|
|
certificateResolver
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
useCases: {
|
|||
|
|
list_issued_invoices: () =>
|
|||
|
|
buildListIssuedInvoicesUseCase({
|
|||
|
|
finder,
|
|||
|
|
itemSnapshotBuilder: snapshotBuilders.list,
|
|||
|
|
transactionManager,
|
|||
|
|
}),
|
|||
|
|
get_issued_invoice_by_id: () =>
|
|||
|
|
buildGetIssuedInvoiceByIdUseCase({
|
|||
|
|
finder,
|
|||
|
|
fullSnapshotBuilder: snapshotBuilders.full,
|
|||
|
|
transactionManager,
|
|||
|
|
}),
|
|||
|
|
report_issued_invoice: () =>
|
|||
|
|
buildReportIssuedInvoiceUseCase({
|
|||
|
|
finder,
|
|||
|
|
fullSnapshotBuilder: snapshotBuilders.full,
|
|||
|
|
reportSnapshotBuilder: snapshotBuilders.report,
|
|||
|
|
documentService: renderers.reportRenderer,
|
|||
|
|
transactionManager,
|
|||
|
|
}),
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
}
|