- Removed authentication and company context guards from multiple controllers in the customer, proforma, document series, and supplier modules. - Consolidated guard registration logic in routes to enforce company ID restrictions globally. - Cleaned up imports and ensured consistent error handling across controllers.
100 lines
3.0 KiB
TypeScript
100 lines
3.0 KiB
TypeScript
import { type StartParams, forbidQueryFieldGuard, validateRequest } from "@erp/core/api";
|
|
import { requireIdentityTenant } from "@erp/identity/api";
|
|
import { type NextFunction, type Request, type Response, Router } from "express";
|
|
|
|
import {
|
|
CreateCustomerRequestSchema,
|
|
CustomerListRequestSchema,
|
|
GetCustomerByIdRequestSchema,
|
|
UpdateCustomerByIdParamsRequestSchema,
|
|
UpdateCustomerByIdRequestSchema,
|
|
} from "../../../common/dto";
|
|
import type { CustomersInternalDeps } from "../di";
|
|
|
|
import {
|
|
CreateCustomerController,
|
|
GetCustomerController,
|
|
ListCustomersController,
|
|
UpdateCustomerController,
|
|
} from "./controllers";
|
|
|
|
export const customersRouter = (params: StartParams) => {
|
|
const { app, config, getInternal } = params;
|
|
|
|
// Recuperamos el dominio interno del módulo
|
|
const deps = getInternal<CustomersInternalDeps>("customers");
|
|
|
|
const router: Router = Router({ mergeParams: true });
|
|
|
|
// ----------------------------------------------
|
|
|
|
// 🔐 Autenticación + Tenancy para TODO el router
|
|
router.use(...requireIdentityTenant(params));
|
|
router.use(forbidQueryFieldGuard("companyId"));
|
|
|
|
// ----------------------------------------------
|
|
|
|
router.get(
|
|
"/",
|
|
//checkTabContext,
|
|
|
|
validateRequest(CustomerListRequestSchema, "params"),
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const useCase = deps.useCases.listCustomers();
|
|
const controller = new ListCustomersController(useCase /*, deps.presenters.list */);
|
|
return controller.execute(req, res, next);
|
|
}
|
|
);
|
|
|
|
router.get(
|
|
"/:customer_id",
|
|
//checkTabContext,
|
|
|
|
validateRequest(GetCustomerByIdRequestSchema, "params"),
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const useCase = deps.useCases.getCustomerById();
|
|
const controller = new GetCustomerController(useCase);
|
|
return controller.execute(req, res, next);
|
|
}
|
|
);
|
|
|
|
router.post(
|
|
"/",
|
|
//checkTabContext,
|
|
|
|
validateRequest(CreateCustomerRequestSchema, "body"),
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const useCase = deps.useCases.createCustomer();
|
|
const controller = new CreateCustomerController(useCase);
|
|
return controller.execute(req, res, next);
|
|
}
|
|
);
|
|
|
|
router.put(
|
|
"/:customer_id",
|
|
//checkTabContext,
|
|
|
|
validateRequest(UpdateCustomerByIdParamsRequestSchema, "params"),
|
|
validateRequest(UpdateCustomerByIdRequestSchema, "body"),
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const useCase = deps.useCases.updateCustomer();
|
|
const controller = new UpdateCustomerController(useCase);
|
|
return controller.execute(req, res, next);
|
|
}
|
|
);
|
|
|
|
/*router.delete(
|
|
"/:customer_id",
|
|
//checkTabContext,
|
|
|
|
validateRequest(DeleteCustomerByIdRequestSchema, "params"),
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const useCase = deps.build.delete();
|
|
const controller = new DeleteCustomerController(useCase);
|
|
return controller.execute(req, res, next);
|
|
}
|
|
);*/
|
|
|
|
app.use(`${config.server.apiBasePath}/customers`, router);
|
|
};
|