2025-02-21 11:25:46 +00:00
|
|
|
import { validateRequestDTO } from "@common/presentation";
|
2025-03-04 17:08:33 +00:00
|
|
|
import {
|
2025-03-18 08:05:00 +00:00
|
|
|
ICreateAccountRequestSchema,
|
|
|
|
|
IGetAccountRequestSchema,
|
|
|
|
|
IUpdateAccountRequestSchema,
|
|
|
|
|
ListAccountsRequestSchema,
|
2025-03-04 17:08:33 +00:00
|
|
|
} from "@contexts/accounts/presentation";
|
|
|
|
|
import {
|
|
|
|
|
createAccountController,
|
|
|
|
|
getAccountController,
|
|
|
|
|
listAccountsController,
|
|
|
|
|
updateAccountController,
|
|
|
|
|
} from "@contexts/accounts/presentation/controllers";
|
2025-02-21 11:25:46 +00:00
|
|
|
import { checkTabContext } from "@contexts/auth/infraestructure";
|
|
|
|
|
import { NextFunction, Request, Response, Router } from "express";
|
|
|
|
|
|
2025-02-25 17:47:42 +00:00
|
|
|
export const accountsRouter = (appRouter: Router) => {
|
2025-02-24 19:00:28 +00:00
|
|
|
const routes: Router = Router({ mergeParams: true });
|
2025-02-21 11:25:46 +00:00
|
|
|
|
2025-02-24 19:00:28 +00:00
|
|
|
routes.get(
|
2025-02-21 11:25:46 +00:00
|
|
|
"/",
|
2025-03-18 08:05:00 +00:00
|
|
|
validateRequestDTO(ListAccountsRequestSchema),
|
2025-02-21 11:25:46 +00:00
|
|
|
checkTabContext,
|
|
|
|
|
//checkUser,
|
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
2025-02-25 17:47:42 +00:00
|
|
|
listAccountsController().execute(req, res, next);
|
2025-02-21 11:25:46 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-03-04 17:08:33 +00:00
|
|
|
routes.get(
|
2025-03-18 08:05:00 +00:00
|
|
|
"/:invoiceId",
|
|
|
|
|
validateRequestDTO(IGetAccountRequestSchema),
|
2025-03-04 17:08:33 +00:00
|
|
|
checkTabContext,
|
|
|
|
|
//checkUser,
|
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
getAccountController().execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.post(
|
|
|
|
|
"/",
|
2025-03-18 08:05:00 +00:00
|
|
|
validateRequestDTO(ICreateAccountRequestSchema),
|
2025-03-04 17:08:33 +00:00
|
|
|
checkTabContext,
|
|
|
|
|
//checkUser,
|
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
createAccountController().execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.put(
|
2025-03-18 08:05:00 +00:00
|
|
|
"/:invoiceId",
|
|
|
|
|
validateRequestDTO(IUpdateAccountRequestSchema),
|
2025-03-04 17:08:33 +00:00
|
|
|
checkTabContext,
|
|
|
|
|
//checkUser,
|
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
updateAccountController().execute(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-25 17:47:42 +00:00
|
|
|
appRouter.use("/accounts", routes);
|
2025-02-21 11:25:46 +00:00
|
|
|
};
|