FactuGES_ERP/modules/factuges/src/api/infraestructure/express/factuges.routes.ts
2026-07-05 11:44:10 +02:00

47 lines
1.7 KiB
TypeScript

import { type StartParams, validateRequest } from "@erp/core/api";
import type { IProformaPublicServices } from "@erp/customer-invoices/api";
import type { ICustomerPublicServices } from "@erp/customers/api";
import { CreateProformaFromFactugesRequestSchema } from "@erp/factuges/common";
import { requireIdentityTenant } from "@erp/identity/api";
import { type NextFunction, type Request, type Response, Router } from "express";
import type { FactugesInternalDeps } from "../di/factuges.di";
import { CreateProformaFromFactugesController } from "./controllers";
export const factugesRouter = (params: StartParams) => {
const { app, config, getInternal, getService } = params;
// Recuperamos el dominio interno del módulo
const deps = getInternal<FactugesInternalDeps>("factuges");
// Recuperamos servicios externos que necesitemos
const customerServices = getService<ICustomerPublicServices>("customers:general");
const proformaServices = getService<IProformaPublicServices>("customer-invoices:proformas");
const publicServices = {
customerServices,
proformaServices,
};
const router: Router = Router({ mergeParams: true });
// 🔐 Autenticación + Tenancy para TODO el router
router.use(...requireIdentityTenant(params));
// ----------------------------------------------
router.post(
"/",
//checkTabContext,
validateRequest(CreateProformaFromFactugesRequestSchema, "body"),
(req: Request, res: Response, next: NextFunction) => {
const useCase = deps.useCases.createProforma(publicServices);
const controller = new CreateProformaFromFactugesController(useCase);
return controller.execute(req, res, next);
}
);
app.use(`${config.server.apiBasePath}/factuges`, router);
};