Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
refacto(users.ts): seperate file for user routes location (#2332)
Browse files Browse the repository at this point in the history
* refacto(users.ts): seperate file for user routes location

* chore(routes/users.ts): use distinct router for user api endpoint

* chore: don't use base path for routers
  • Loading branch information
LucasCharrier authored Jan 15, 2024
1 parent 8bdd0bf commit d61952c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 70 deletions.
75 changes: 5 additions & 70 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { MARRAINAGE_EVENTS_VALUES } from '@models/marrainage';
import routes from './routes/routes';
import permit, { MemberRole } from './middlewares/authorization';
import {
publicGetRouteRateLimiter,
publicPostRouteRateLimiter,
rateLimiter,
} from './middlewares/rateLimiter';
Expand Down Expand Up @@ -60,6 +59,8 @@ import {
} from './controllers/startupController/getStartupInfoCreate';
import { getBadgeRenewalPage } from './controllers/accountController/getBadgeRenewalPage';
import { postBadgeRenewalRequest } from './controllers/badgeRequestsController/postBadgeRenewalRequest';
import { userRouter, userApiRouter, userPublicApiRouter } from './routes/users';

export const app = express();
app.set('trust proxy', 1);

Expand Down Expand Up @@ -250,6 +251,9 @@ app.post(
app.post(routes.SIGNIN, loginController.postSignIn);
app.get(routes.LOGOUT, logoutController.getLogout);
app.get(routes.LOGOUT_API, logoutController.getLogoutApi);
app.use(userRouter);
app.use(userApiRouter);
app.use(userPublicApiRouter);

// que ce passe-t-il
app.get(
Expand All @@ -263,75 +267,6 @@ app.get(routes.WHAT_IS_GOING_ON_WITH_MEMBER_SIMPLE, (req, res) =>
res.redirect(routes.WHAT_IS_GOING_ON_WITH_MEMBER)
);

// users
app.post(routes.USER_CREATE_EMAIL, usersController.createEmailForUser);
app.post(
routes.USER_CREATE_EMAIL_API,
express.json({ type: '*/*' }),
usersController.createEmailApi
);
app.post(routes.USER_DELETE_EMAIL, usersController.deleteEmailForUser);
app.post(
routes.USER_DELETE_EMAIL_API,
express.json({ type: '*/*' }),
usersController.deleteEmailForUserApi
);
app.post(routes.USER_UPGRADE_EMAIL, usersController.upgradeEmailForUser);
app.post(
routes.USER_UPGRADE_EMAIL_API,
express.json({ type: '*/*' }),
usersController.upgradeEmailForUserApi
);
app.post(
routes.USER_CREATE_REDIRECTION,
usersController.createRedirectionForUser
);
app.post(
routes.USER_CREATE_REDIRECTION_API,
express.json({ type: '*/*' }),
usersController.createRedirectionForUserApi
);
app.post(
routes.USER_DELETE_REDIRECTION,
usersController.deleteRedirectionForUser
);
app.delete(
routes.USER_DELETE_REDIRECTION_API,
express.json({ type: '*/*' }),
usersController.deleteRedirectionForUserApi
);
app.post(routes.USER_UPDATE_PASSWORD, usersController.updatePasswordForUser);
app.post(
routes.USER_UPDATE_PASSWORD_API,
express.json({ type: '*/*' }),
usersController.updatePasswordForUserApi
);

app.post(
routes.USER_UPDATE_SECONDARY_EMAIL,
usersController.manageSecondaryEmailForUser
);
app.post(
routes.USER_UPDATE_SECONDARY_EMAIL_API,
express.json({ type: '*/*' }),
usersController.manageSecondaryEmailForUserApi
);
app.post(
routes.USER_UPDATE_PRIMARY_EMAIL,
usersController.managePrimaryEmailForUser
);
app.put(
routes.USER_UPDATE_PRIMARY_EMAIL_API,
express.json({ type: '*/*' }),
usersController.managePrimaryEmailForUserApi
);
app.post(routes.USER_UPDATE_END_DATE, usersController.updateEndDateForUser);

app.get(
routes.API_GET_PUBLIC_USER_INFO,
publicGetRouteRateLimiter,
usersController.getUserInfo
);
app.get(routes.PULL_REQUEST_GET_PRS, pullRequestsController.getAllPullRequests);
//
app.post(
Expand Down
87 changes: 87 additions & 0 deletions src/routes/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import express from 'express';
import * as usersController from '../controllers/usersController';
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_DELETE_EMAIL, usersController.deleteEmailForUser);
router.post(routes.USER_UPGRADE_EMAIL, usersController.upgradeEmailForUser);

router.post(
routes.USER_CREATE_REDIRECTION,
usersController.createRedirectionForUser
);
router.post(
routes.USER_DELETE_REDIRECTION,
usersController.deleteRedirectionForUser
);
router.post(routes.USER_UPDATE_PASSWORD, usersController.updatePasswordForUser);

router.post(
routes.USER_UPDATE_SECONDARY_EMAIL,
usersController.manageSecondaryEmailForUser
);
router.post(
routes.USER_UPDATE_PRIMARY_EMAIL,
usersController.managePrimaryEmailForUser
);
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
);
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
);

publicApiRouter.get(
routes.API_GET_PUBLIC_USER_INFO,
publicGetRouteRateLimiter,
usersController.getUserInfo
);

export {
router as userRouter,
apiRouter as userApiRouter,
publicApiRouter as userPublicApiRouter,
};

0 comments on commit d61952c

Please sign in to comment.