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

Commit

Permalink
refacto: create account router (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCharrier authored Jan 15, 2024
1 parent 9b4aceb commit 68949c9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 85 deletions.
88 changes: 3 additions & 85 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import session from 'express-session';
import path from 'path';
import cors from 'cors';
import config from '@config';
import * as accountController from '@controllers/accountController';
import * as adminController from '@/controllers/adminController';
import * as communityController from '@controllers/communityController';
import * as githubNotificationController from '@controllers/githubNotificationController';
Expand All @@ -20,7 +19,6 @@ import * as newsletterController from '@controllers/newsletterController';
import * as onboardingController from '@controllers/onboardingController';
import * as resourceController from '@controllers/resourceController';
import * as startupController from '@controllers/startupController';
import * as usersController from '@controllers/usersController';
import * as mapController from '@controllers/mapController';
import * as hookController from '@controllers/hookController';
import * as pullRequestsController from '@controllers/pullRequestsController';
Expand All @@ -30,19 +28,12 @@ import EventBus from '@infra/eventBus/eventBus';
import { MARRAINAGE_EVENTS_VALUES } from '@models/marrainage';
import routes from './routes/routes';
import permit, { MemberRole } from './middlewares/authorization';
import {
publicPostRouteRateLimiter,
rateLimiter,
} from './middlewares/rateLimiter';
import { rateLimiter } from './middlewares/rateLimiter';
import {
getStartupInfoUpdate,
getStartupInfoUpdateApi,
postStartupInfoUpdate,
} from './controllers/startupController';
import {
getBadgePage,
getBadgePageApi,
} from './controllers/accountController/getBadgePage';
import { postBadgeRequest } from './controllers/badgeRequestsController/postBadgeRequest';
import {
updateBadgeRenewalRequestStatus,
Expand All @@ -56,10 +47,10 @@ import {
getStartupInfoCreate,
getStartupInfoCreateApi,
} from './controllers/startupController/getStartupInfoCreate';
import { getBadgeRenewalPage } from './controllers/accountController/getBadgeRenewalPage';
import { postBadgeRenewalRequest } from './controllers/badgeRequestsController/postBadgeRenewalRequest';
import { userRouter, userApiRouter, userPublicApiRouter } from './routes/users';
import { marrainageRouter } from './routes/marrainage';
import { accountRouter } from './routes/account';

export const app = express();
app.set('trust proxy', 1);
Expand Down Expand Up @@ -154,7 +145,6 @@ app.use(
)
);

// app.use(cookieParser(config.secret));
app.use(
session({
store: process.env.NODE_ENV !== 'test' ? makeSessionStore() : null,
Expand All @@ -174,8 +164,6 @@ app.use(
); // Only used for Flash not safe for others purposes
app.use(flash());
app.use(expressSanitizer());
// const router = express.Router()
// router.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(rateLimiter);

Expand Down Expand Up @@ -255,6 +243,7 @@ app.use(userRouter);
app.use(userApiRouter);
app.use(userPublicApiRouter);
app.use(marrainageRouter);
app.use(accountRouter);

// que ce passe-t-il
app.get(
Expand All @@ -275,52 +264,6 @@ app.post(
githubNotificationController.processNotification
);

app.get(
routes.ME,
express.json({ type: '*/*' }),
accountController.getCurrentUser
);
app.get(routes.ACCOUNT_GET, accountController.getCurrentAccount);
app.get(routes.ACCOUNT_GET_API, accountController.getCurrentAccountApi);

app.get(
routes.ACCOUNT_GET_DETAIL_INFO_FORM,
accountController.getDetailInfoUpdate
);
app.get(
routes.ACCOUNT_GET_DETAIL_INFO_FORM_API,
accountController.getDetailInfoUpdateApi
);
app.post(
routes.ACCOUNT_POST_DETAIL_INFO_FORM,
accountController.postCurrentInfo
);
app.post(
routes.ACCOUNT_POST_DETAIL_INFO_FORM_API,
express.json({ type: '*/*' }),
accountController.postCurrentInfo
);
app.get(routes.ACCOUNT_GET_BASE_INFO_FORM, usersController.getBaseInfoUpdate);
app.get(
routes.ACCOUNT_GET_BASE_INFO_FORM_API,
usersController.getBaseInfoUpdateApi
);

app.post(
routes.ACCOUNT_POST_BASE_INFO_FORM,
express.json({ type: '*/*' }),
usersController.postBaseInfoUpdate
);
app.post(
routes.API_PUBLIC_POST_BASE_INFO_FORM,
publicPostRouteRateLimiter,
express.json({ type: '*/*' }),
usersController.publicPostBaseInfoUpdate
);
app.get(routes.ACCOUNT_GET_BADGE_RENEWAL_REQUEST_PAGE_API, getBadgeRenewalPage);
app.get(routes.ACCOUNT_GET_BADGE_REQUEST_PAGE, getBadgePage);
app.get(routes.ACCOUNT_GET_BADGE_REQUEST_PAGE_API, getBadgePageApi);

app.post(
routes.API_POST_BADGE_REQUEST,
express.json({ type: '*/*' }),
Expand Down Expand Up @@ -424,31 +367,6 @@ app.post(
onboardingController.postOnboardingFormApi
);
app.get('/onboardingSuccess/:prNumber', onboardingController.getConfirmation);
app.post(
'/account/delete_email_responder',
accountController.deleteEmailResponder
);
app.post(
'/api/account/delete_email_responder',
express.json({ type: '*/*' }),
accountController.deleteEmailResponderApi
);
app.post('/account/set_email_responder', accountController.setEmailResponder);
app.post(
'/api/account/set_email_responder',
express.json({ type: '*/*' }),
accountController.setEmailResponderApi
);

app.post(
routes.USER_UPDATE_COMMUNICATION_EMAIL,
accountController.updateCommunicationEmail
);
app.put(
routes.USER_UPDATE_COMMUNICATION_EMAIL_API,
express.json({ type: '*/*' }),
accountController.updateCommunicationEmailApi
);

app.get(routes.NEWSLETTERS, newsletterController.getNewsletterPage);
app.get(routes.NEWSLETTERS_API, newsletterController.getNewsletterApi);
Expand Down
96 changes: 96 additions & 0 deletions src/routes/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import express from 'express';
import routes from './routes';
import * as usersController from '@controllers/usersController';
import * as accountController from '@controllers/accountController';
import { publicPostRouteRateLimiter } from '../middlewares/rateLimiter';
import {
getBadgePage,
getBadgePageApi,
} from '@controllers/accountController/getBadgePage';
import { getBadgeRenewalPage } from '@controllers/accountController/getBadgeRenewalPage';

const router = express.Router();

router.get(routes.ACCOUNT_GET, accountController.getCurrentAccount);
router.get(routes.ACCOUNT_GET_API, accountController.getCurrentAccountApi);

router.get(
routes.ACCOUNT_GET_DETAIL_INFO_FORM,
accountController.getDetailInfoUpdate
);
router.get(
routes.ACCOUNT_GET_DETAIL_INFO_FORM_API,
accountController.getDetailInfoUpdateApi
);
router.post(
routes.ACCOUNT_POST_DETAIL_INFO_FORM,
accountController.postCurrentInfo
);
router.post(
routes.ACCOUNT_POST_DETAIL_INFO_FORM_API,
express.json({ type: '*/*' }),
accountController.postCurrentInfo
);
router.get(
routes.ACCOUNT_GET_BASE_INFO_FORM,
usersController.getBaseInfoUpdate
);
router.get(
routes.ACCOUNT_GET_BASE_INFO_FORM_API,
usersController.getBaseInfoUpdateApi
);

router.post(
routes.ACCOUNT_POST_BASE_INFO_FORM,
express.json({ type: '*/*' }),
usersController.postBaseInfoUpdate
);
router.post(
routes.API_PUBLIC_POST_BASE_INFO_FORM,
publicPostRouteRateLimiter,
express.json({ type: '*/*' }),
usersController.publicPostBaseInfoUpdate
);
router.get(
routes.ACCOUNT_GET_BADGE_RENEWAL_REQUEST_PAGE_API,
getBadgeRenewalPage
);
router.get(routes.ACCOUNT_GET_BADGE_REQUEST_PAGE, getBadgePage);
router.get(routes.ACCOUNT_GET_BADGE_REQUEST_PAGE_API, getBadgePageApi);

router.post(
'/account/delete_email_responder',
accountController.deleteEmailResponder
);
router.post(
'/api/account/delete_email_responder',
express.json({ type: '*/*' }),
accountController.deleteEmailResponderApi
);
router.post(
'/account/set_email_responder',
accountController.setEmailResponder
);
router.post(
'/api/account/set_email_responder',
express.json({ type: '*/*' }),
accountController.setEmailResponderApi
);

router.post(
routes.USER_UPDATE_COMMUNICATION_EMAIL,
accountController.updateCommunicationEmail
);
router.put(
routes.USER_UPDATE_COMMUNICATION_EMAIL_API,
express.json({ type: '*/*' }),
accountController.updateCommunicationEmailApi
);

router.get(
routes.ME,
express.json({ type: '*/*' }),
accountController.getCurrentUser
);

export { router as accountRouter };

0 comments on commit 68949c9

Please sign in to comment.