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

Commit

Permalink
chore(routes/users.ts): use distinct router for user api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCharrier committed Jan 15, 2024
1 parent c0b470e commit 6493d85
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 39 deletions.
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down
87 changes: 48 additions & 39 deletions src/routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit 6493d85

Please sign in to comment.