From 6493d85196da63aac998d5f8c0018b69f28b5619 Mon Sep 17 00:00:00 2001 From: Lucas Charrier Date: Mon, 15 Jan 2024 15:17:58 +0100 Subject: [PATCH] chore(routes/users.ts): use distinct router for user api endpoint --- src/index.ts | 10 ++++++ src/routes/users.ts | 87 +++++++++++++++++++++++++-------------------- 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/index.ts b/src/index.ts index a19616cc6..fc1727038 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,6 +59,13 @@ import { } from './controllers/startupController/getStartupInfoCreate'; import { getBadgeRenewalPage } from './controllers/accountController/getBadgeRenewalPage'; import { postBadgeRenewalRequest } from './controllers/badgeRequestsController/postBadgeRenewalRequest'; +import { + userRoutes, + userApiRoutes, + userApiRouter, + userPublicApiRouter, +} from './routes/users'; + export const app = express(); app.set('trust proxy', 1); @@ -249,6 +256,9 @@ app.post( app.post(routes.SIGNIN, loginController.postSignIn); app.get(routes.LOGOUT, logoutController.getLogout); app.get(routes.LOGOUT_API, logoutController.getLogoutApi); +app.use('/users', userRoutes); +app.use('/api/users', userApiRouter); +app.use('/api/public/users', userPublicApiRouter); // que ce passe-t-il app.get( diff --git a/src/routes/users.ts b/src/routes/users.ts index 605f652fe..124a981ed 100644 --- a/src/routes/users.ts +++ b/src/routes/users.ts @@ -4,75 +4,84 @@ import routes from './routes'; import { publicGetRouteRateLimiter } from '@/middlewares/rateLimiter'; const router = express.Router(); +const apiRouter = express.Router(); +const publicApiRouter = express.Router(); // users router.post(routes.USER_CREATE_EMAIL, usersController.createEmailForUser); -router.post( - routes.USER_CREATE_EMAIL_API, - express.json({ type: '*/*' }), - usersController.createEmailApi -); + router.post(routes.USER_DELETE_EMAIL, usersController.deleteEmailForUser); -router.post( - routes.USER_DELETE_EMAIL_API, - express.json({ type: '*/*' }), - usersController.deleteEmailForUserApi -); router.post(routes.USER_UPGRADE_EMAIL, usersController.upgradeEmailForUser); -router.post( - routes.USER_UPGRADE_EMAIL_API, - express.json({ type: '*/*' }), - usersController.upgradeEmailForUserApi -); + router.post( routes.USER_CREATE_REDIRECTION, usersController.createRedirectionForUser ); -router.post( - routes.USER_CREATE_REDIRECTION_API, - express.json({ type: '*/*' }), - usersController.createRedirectionForUserApi -); router.post( routes.USER_DELETE_REDIRECTION, usersController.deleteRedirectionForUser ); -router.delete( - routes.USER_DELETE_REDIRECTION_API, - express.json({ type: '*/*' }), - usersController.deleteRedirectionForUserApi -); router.post(routes.USER_UPDATE_PASSWORD, usersController.updatePasswordForUser); -router.post( - routes.USER_UPDATE_PASSWORD_API, - express.json({ type: '*/*' }), - usersController.updatePasswordForUserApi -); router.post( routes.USER_UPDATE_SECONDARY_EMAIL, usersController.manageSecondaryEmailForUser ); -router.post( - routes.USER_UPDATE_SECONDARY_EMAIL_API, - express.json({ type: '*/*' }), - usersController.manageSecondaryEmailForUserApi -); router.post( routes.USER_UPDATE_PRIMARY_EMAIL, usersController.managePrimaryEmailForUser ); -router.put( +router.post(routes.USER_UPDATE_END_DATE, usersController.updateEndDateForUser); + +apiRouter.post( + routes.USER_DELETE_EMAIL_API, + express.json({ type: '*/*' }), + usersController.deleteEmailForUserApi +); +apiRouter.put( routes.USER_UPDATE_PRIMARY_EMAIL_API, express.json({ type: '*/*' }), usersController.managePrimaryEmailForUserApi ); -router.post(routes.USER_UPDATE_END_DATE, usersController.updateEndDateForUser); +apiRouter.post( + routes.USER_UPDATE_SECONDARY_EMAIL_API, + express.json({ type: '*/*' }), + usersController.manageSecondaryEmailForUserApi +); +apiRouter.post( + routes.USER_UPDATE_PASSWORD_API, + express.json({ type: '*/*' }), + usersController.updatePasswordForUserApi +); +apiRouter.delete( + routes.USER_DELETE_REDIRECTION_API, + express.json({ type: '*/*' }), + usersController.deleteRedirectionForUserApi +); +apiRouter.post( + routes.USER_CREATE_REDIRECTION_API, + express.json({ type: '*/*' }), + usersController.createRedirectionForUserApi +); +apiRouter.post( + routes.USER_UPGRADE_EMAIL_API, + express.json({ type: '*/*' }), + usersController.upgradeEmailForUserApi +); +apiRouter.post( + routes.USER_CREATE_EMAIL_API, + express.json({ type: '*/*' }), + usersController.createEmailApi +); -router.get( +publicApiRouter.get( routes.API_GET_PUBLIC_USER_INFO, publicGetRouteRateLimiter, usersController.getUserInfo ); -export default router; +export { + router as userRouter, + apiRouter as userApiRouter, + publicApiRouter as userPublicApiRouter, +};