2025-08-11 17:49:52 +00:00
|
|
|
import { ILogger, ModuleParams, validateRequest } from "@erp/core/api";
|
|
|
|
|
import { Application, NextFunction, Request, Response, Router } from "express";
|
|
|
|
|
import { Sequelize } from "sequelize";
|
|
|
|
|
import {
|
2025-08-12 11:23:50 +00:00
|
|
|
CreateCustomerRequestSchema,
|
|
|
|
|
CustomerListRequestSchema,
|
|
|
|
|
DeleteCustomerByIdRequestSchema,
|
|
|
|
|
GetCustomerByIdRequestSchema,
|
2025-08-11 17:49:52 +00:00
|
|
|
} from "../../../common/dto";
|
|
|
|
|
import {
|
|
|
|
|
buildCreateCustomersController,
|
|
|
|
|
buildDeleteCustomerController,
|
|
|
|
|
buildGetCustomerController,
|
|
|
|
|
buildListCustomersController,
|
|
|
|
|
} from "../../controllers";
|
|
|
|
|
|
|
|
|
|
export const customersRouter = (params: ModuleParams) => {
|
|
|
|
|
const { app, database, baseRoutePath, logger } = params as {
|
|
|
|
|
app: Application;
|
|
|
|
|
database: Sequelize;
|
|
|
|
|
baseRoutePath: string;
|
|
|
|
|
logger: ILogger;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const routes: Router = Router({ mergeParams: true });
|
|
|
|
|
|
|
|
|
|
routes.get(
|
|
|
|
|
"/",
|
|
|
|
|
//checkTabContext,
|
|
|
|
|
//checkUser,
|
2025-08-12 11:23:50 +00:00
|
|
|
validateRequest(CustomerListRequestSchema, "params"),
|
2025-08-11 17:49:52 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
buildListCustomersController(database).execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.get(
|
|
|
|
|
"/:id",
|
|
|
|
|
//checkTabContext,
|
|
|
|
|
//checkUser,
|
2025-08-12 11:23:50 +00:00
|
|
|
validateRequest(GetCustomerByIdRequestSchema, "params"),
|
2025-08-11 17:49:52 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
buildGetCustomerController(database).execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.post(
|
|
|
|
|
"/",
|
|
|
|
|
//checkTabContext,
|
|
|
|
|
//checkUser,
|
2025-08-12 11:23:50 +00:00
|
|
|
validateRequest(CreateCustomerRequestSchema),
|
2025-08-11 17:49:52 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
buildCreateCustomersController(database).execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/*routes.put(
|
|
|
|
|
"/:customerId",
|
|
|
|
|
validateAndParseBody(IUpdateCustomerRequestSchema),
|
|
|
|
|
checkTabContext,
|
|
|
|
|
//checkUser,
|
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
buildUpdateCustomerController().execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);*/
|
|
|
|
|
|
|
|
|
|
routes.delete(
|
|
|
|
|
"/:id",
|
|
|
|
|
//checkTabContext,
|
|
|
|
|
//checkUser,
|
2025-08-12 11:23:50 +00:00
|
|
|
validateRequest(DeleteCustomerByIdRequestSchema, "params"),
|
2025-08-11 17:49:52 +00:00
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
buildDeleteCustomerController(database).execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
app.use(`${baseRoutePath}/customers`, routes);
|
|
|
|
|
};
|