Skip to content

Commit

Permalink
fix: possible error for not logged in users
Browse files Browse the repository at this point in the history
  • Loading branch information
apalchys committed Nov 20, 2023
1 parent 841a569 commit 2e77cb0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions server/src/routes/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function registryRouter(logger?: ILogger) {
});

router.post('/mentor', async (ctx: Router.RouterContext) => {
const { githubId, id } = ctx.state!.user as IUserSession;
if (!ctx.state.user) {
setResponse(ctx, BAD_REQUEST);
return;
}
const { githubId, id } = ctx.state.user as IUserSession;
await repository.register(githubId, ctx.request.body);
await sendNotification({
notificationId: 'mentorRegistrationApproval:submit',
Expand All @@ -44,7 +48,12 @@ export function registryRouter(logger?: ILogger) {
});

router.get('/mentor', async (ctx: Router.RouterContext) => {
const { id: userId } = ctx.state!.user as IUserSession;
if (!ctx.state.user) {
setResponse(ctx, BAD_REQUEST);
return;
}

const { id: userId } = ctx.state.user as IUserSession;

const mentorRegistry = await getRepository(MentorRegistry).findOne({ where: { userId } });
if (mentorRegistry == null) {
Expand Down Expand Up @@ -81,7 +90,12 @@ export function registryRouter(logger?: ILogger) {
router.get('/:id', adminGuard, createGetRoute(Registry, logger));

router.post('/', async (ctx: Router.RouterContext) => {
const { githubId, id: userId } = ctx.state!.user as IUserSession;
if (!ctx.state.user) {
setResponse(ctx, BAD_REQUEST);
return;
}

const { githubId, id: userId } = ctx.state.user as IUserSession;
const { courseId, type, maxStudentsLimit, experienceInYears } = ctx.request.body;

if (!githubId || !courseId || !type) {
Expand Down

0 comments on commit 2e77cb0

Please sign in to comment.