2025-08-14 14:58:13 +00:00
|
|
|
import { RequestWithAuth, enforceTenant } from "@erp/auth/api";
|
2025-06-24 18:38:57 +00:00
|
|
|
import { ILogger, ModuleParams, validateRequest } from "@erp/core/api";
|
2025-05-04 20:06:57 +00:00
|
|
|
import { Application, NextFunction, Request, Response, Router } from "express";
|
|
|
|
|
import { Sequelize } from "sequelize";
|
2025-06-24 18:38:57 +00:00
|
|
|
import {
|
2025-08-12 15:12:44 +00:00
|
|
|
CreateCustomerInvoiceRequestSchema,
|
2025-08-12 11:23:50 +00:00
|
|
|
CustomerInvoiceListRequestSchema,
|
2025-08-12 15:12:44 +00:00
|
|
|
DeleteCustomerInvoiceByIdRequestSchema,
|
|
|
|
|
GetCustomerInvoiceByIdRequestSchema,
|
2025-06-24 18:38:57 +00:00
|
|
|
} from "../../../common/dto";
|
2025-08-14 14:58:13 +00:00
|
|
|
import { getInvoiceDependencies } from "../dependencies";
|
2025-06-26 14:35:53 +00:00
|
|
|
import {
|
2025-08-14 14:58:13 +00:00
|
|
|
CreateCustomerInvoiceController,
|
|
|
|
|
DeleteCustomerInvoiceController,
|
|
|
|
|
GetCustomerInvoiceController,
|
|
|
|
|
ListCustomerInvoicesController,
|
|
|
|
|
} from "./controllers";
|
2025-05-04 20:06:57 +00:00
|
|
|
|
2025-06-12 06:55:17 +00:00
|
|
|
export const customerInvoicesRouter = (params: ModuleParams) => {
|
|
|
|
|
const { app, database, baseRoutePath, logger } = params as {
|
2025-05-04 20:06:57 +00:00
|
|
|
app: Application;
|
|
|
|
|
database: Sequelize;
|
|
|
|
|
baseRoutePath: string;
|
2025-06-12 06:55:17 +00:00
|
|
|
logger: ILogger;
|
2025-05-04 20:06:57 +00:00
|
|
|
};
|
|
|
|
|
|
2025-08-14 14:58:13 +00:00
|
|
|
const router: Router = Router({ mergeParams: true });
|
|
|
|
|
const deps = getInvoiceDependencies(params);
|
2025-05-04 20:06:57 +00:00
|
|
|
|
2025-08-14 14:58:13 +00:00
|
|
|
// 🔐 Autenticación + Tenancy para TODO el router
|
|
|
|
|
router.use(/* authenticateJWT(), */ enforceTenant() /*checkTabContext*/);
|
|
|
|
|
|
|
|
|
|
router.get(
|
2025-05-04 20:06:57 +00:00
|
|
|
"/",
|
|
|
|
|
//checkTabContext,
|
2025-08-12 11:23:50 +00:00
|
|
|
validateRequest(CustomerInvoiceListRequestSchema, "params"),
|
2025-08-14 14:58:13 +00:00
|
|
|
async (req: RequestWithAuth, res: Response, next: NextFunction) => {
|
|
|
|
|
const useCase = deps.build.list();
|
|
|
|
|
const controller = new ListCustomerInvoicesController(useCase /*, deps.presenters.list */);
|
|
|
|
|
return controller.execute(req, res, next);
|
2025-05-04 20:06:57 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-08-14 14:58:13 +00:00
|
|
|
router.get(
|
2025-06-26 18:05:33 +00:00
|
|
|
"/:id",
|
2025-05-04 20:06:57 +00:00
|
|
|
//checkTabContext,
|
2025-08-12 15:12:44 +00:00
|
|
|
validateRequest(GetCustomerInvoiceByIdRequestSchema, "params"),
|
2025-05-04 20:06:57 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
2025-08-14 14:58:13 +00:00
|
|
|
const useCase = deps.build.get();
|
|
|
|
|
const controller = new GetCustomerInvoiceController(useCase);
|
|
|
|
|
return controller.execute(req, res, next);
|
2025-05-04 20:06:57 +00:00
|
|
|
}
|
2025-06-26 18:05:33 +00:00
|
|
|
);
|
2025-05-04 20:06:57 +00:00
|
|
|
|
2025-08-14 14:58:13 +00:00
|
|
|
router.post(
|
2025-05-04 20:06:57 +00:00
|
|
|
"/",
|
|
|
|
|
//checkTabContext,
|
2025-08-14 14:58:13 +00:00
|
|
|
|
2025-08-12 15:12:44 +00:00
|
|
|
validateRequest(CreateCustomerInvoiceRequestSchema),
|
2025-05-04 20:06:57 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
2025-08-14 14:58:13 +00:00
|
|
|
const useCase = deps.build.create();
|
|
|
|
|
const controller = new CreateCustomerInvoiceController(useCase);
|
|
|
|
|
return controller.execute(req, res, next);
|
2025-05-04 20:06:57 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-06-24 18:38:57 +00:00
|
|
|
/*routes.put(
|
2025-06-12 06:55:17 +00:00
|
|
|
"/:customerInvoiceId",
|
2025-06-11 15:13:44 +00:00
|
|
|
validateAndParseBody(IUpdateCustomerInvoiceRequestSchema),
|
2025-05-04 20:06:57 +00:00
|
|
|
checkTabContext,
|
2025-08-14 14:58:13 +00:00
|
|
|
|
2025-05-04 20:06:57 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
2025-06-11 15:13:44 +00:00
|
|
|
buildUpdateCustomerInvoiceController().execute(req, res, next);
|
2025-05-04 20:06:57 +00:00
|
|
|
}
|
2025-06-26 18:25:38 +00:00
|
|
|
);*/
|
2025-05-04 20:06:57 +00:00
|
|
|
|
2025-08-14 14:58:13 +00:00
|
|
|
router.delete(
|
2025-06-26 18:25:38 +00:00
|
|
|
"/:id",
|
|
|
|
|
//checkTabContext,
|
2025-08-14 14:58:13 +00:00
|
|
|
|
2025-08-12 15:12:44 +00:00
|
|
|
validateRequest(DeleteCustomerInvoiceByIdRequestSchema, "params"),
|
2025-05-04 20:06:57 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
2025-08-14 14:58:13 +00:00
|
|
|
const useCase = deps.build.delete();
|
|
|
|
|
const controller = new DeleteCustomerInvoiceController(useCase);
|
|
|
|
|
return controller.execute(req, res, next);
|
2025-05-04 20:06:57 +00:00
|
|
|
}
|
2025-06-26 18:25:38 +00:00
|
|
|
);
|
2025-06-24 18:38:57 +00:00
|
|
|
|
2025-08-14 14:58:13 +00:00
|
|
|
app.use(`${baseRoutePath}/customer-invoices`, router);
|
2025-05-04 20:06:57 +00:00
|
|
|
};
|