Skip to content
17 changes: 15 additions & 2 deletions packages/backend/src/auth/guards/roles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ export class RolesGuard implements CanActivate {
}

const { user } = context.switchToHttp().getRequest();
return requiredRoles.some((role) =>
user?.roles?.includes(users_roles[role]),
const rawUserRoles = user?.roles ?? user?.role;

// Normalize to an array of uppercased strings for robust comparison
const normalizedUserRoles: string[] = Array.isArray(rawUserRoles)
? rawUserRoles.map((r: any) => String(r).toUpperCase())
: rawUserRoles
? [String(rawUserRoles).toUpperCase()]
: [];

const normalizedRequiredRoles = requiredRoles.map((r) =>
String(users_roles[r]).toUpperCase(),
);

return normalizedRequiredRoles.some((req) =>
normalizedUserRoles.includes(req),
);
}
}
68 changes: 62 additions & 6 deletions packages/backend/src/mentee/mentee.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class MenteeController {
description:
'Fetch any mentee applications. \n\n REQUIRED ROLES: **ADMIN**',
})
@ApiBearerAuth()
@ApiBearerAuth('JWT')
findAll(@Body() filters: FilterMenteeDto) {
return this.menteeService.findAll(filters);
}
Expand All @@ -69,7 +69,7 @@ export class MenteeController {
description:
'There is no mentee application for this user (USER ID: #`:id` )',
})
@ApiBearerAuth()
@ApiBearerAuth('JWT')
findMyApplication(@GetUser() user: JwtPayload) {
return this.menteeService.findOneByUserId(user.sub);
}
Expand All @@ -88,7 +88,7 @@ export class MenteeController {
description:
'There is no mentee application with ID: `:menteeApplicationId`. Make sure you are not using a user ID',
})
@ApiBearerAuth()
@ApiBearerAuth('JWT')
findOne(@Param('menteeApplicationId') menteeApplicationId: string) {
return this.menteeService.findOneById(+menteeApplicationId);
}
Expand All @@ -108,7 +108,7 @@ export class MenteeController {
})
@ApiBadRequestResponse({ description: 'Mentee already exists' })
@ApiNotFoundResponse({ description: 'The associated user does not exists' })
@ApiBearerAuth()
@ApiBearerAuth('JWT')
async create(
@GetUser() user: JwtPayload,
@Body() createMenteeDto: CreateMenteeDto,
Expand Down Expand Up @@ -136,7 +136,7 @@ export class MenteeController {
@ApiNotFoundResponse({
description: 'Mentee application for user with ID: `user_id` not found',
})
@ApiBearerAuth()
@ApiBearerAuth('JWT')
update(
@GetUser() user: JwtPayload,
@Body() updateMenteeDto: UpdateMenteeDto,
Expand Down Expand Up @@ -169,7 +169,7 @@ export class MenteeController {
@ApiBadRequestResponse({
description: 'Error updating mentee application status: `[ERROR MESSAGE]`',
})
@ApiBearerAuth()
@ApiBearerAuth('JWT')
updateStatus(
@Param('menteeApplicationId') menteeApplicationId: string,
@Body() updateMenteeStatusDto: UpdateMenteeStatusDto,
Expand All @@ -180,6 +180,62 @@ export class MenteeController {
return this.menteeService.updateStatus(+menteeApplicationId, updatedMentee);
}

@Get('my-dashboard')
@Roles('USER', 'MENTEE', 'ADMIN')
@ApiOkResponse({ description: 'Mentee dashboard payload' })
@ApiInternalServerErrorResponse({ description: 'Internal server error' })
@ApiOperation({
summary: 'Get mentee dashboard',
description:
'Returns current mentor profile, statistics, and next session info for the logged mentee. REQUIRED ROLES: USER | MENTEE | ADMIN',
})
@ApiBearerAuth('JWT')
getMyDashboard(@GetUser() user: JwtPayload) {
return this.menteeService.getMyDashboard(user.sub);
}

@Get('my-past-mentors')
@Roles('USER', 'MENTEE', 'ADMIN')
@ApiOkResponse({ description: 'List of past mentors' })
@ApiInternalServerErrorResponse({ description: 'Internal server error' })
@ApiOperation({
summary: 'Get past mentors',
description:
'Returns mentors previously matched with the mentee. REQUIRED ROLES: USER | MENTEE | ADMIN',
})
@ApiBearerAuth('JWT')
async getMyPastMentors(@GetUser() user: JwtPayload) {
return await this.menteeService.getMyPastMentors(user.sub);
}

@Get('my-notes')
@Roles('USER', 'MENTEE', 'ADMIN')
@ApiOkResponse({ description: 'List of mentee notes across sessions' })
@ApiInternalServerErrorResponse({ description: 'Internal server error' })
@ApiOperation({
summary: 'Get mentee notes',
description:
'Returns notes the mentee took for mentorship sessions. REQUIRED ROLES: USER | MENTEE | ADMIN',
})
@ApiBearerAuth('JWT')
async getMyNotes(@GetUser() user: JwtPayload) {
return await this.menteeService.getMyNotes(user.sub);
}

@Get('my-upcoming-session')
@Roles('USER', 'MENTEE', 'ADMIN')
@ApiOkResponse({ description: 'Next upcoming session for mentee' })
@ApiInternalServerErrorResponse({ description: 'Internal server error' })
@ApiOperation({
summary: 'Get mentee upcoming session',
description:
'Returns the next upcoming session for the mentee. REQUIRED ROLES: USER | MENTEE | ADMIN',
})
@ApiBearerAuth('JWT')
async getMyUpcomingSession(@GetUser() user: JwtPayload) {
return await this.menteeService.getMyUpcomingSession(user.sub);
}

// TO-DO: REMOVE MENTEE INFORMATION? OR CHANGE STATUS TO "REJECTED" OR "DELETED" TO KEEP THE INFORMATION?

@Delete(':id')
Expand Down
Loading