From db88a240282307b26903b0251cc11e4587e1ce2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Thu, 2 Jan 2025 22:11:13 +0100 Subject: [PATCH] feat: add user profile retrieval to Me module --- src/modules/me/me.controller.ts | 12 +++++++++++- src/modules/me/me.service.ts | 4 +++- src/modules/user/user.service.ts | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/modules/me/me.controller.ts b/src/modules/me/me.controller.ts index f60473a..0509bb0 100644 --- a/src/modules/me/me.controller.ts +++ b/src/modules/me/me.controller.ts @@ -6,6 +6,7 @@ import { JwtAuthGuard } from '../auth/guards/jwt.guard'; import { RolesGuard } from '../auth/guards/role.guard'; import { isUserInClassGuard } from './guards/isUserInClass.guard'; import { MeService } from './me.service'; +import { UserService } from '../user/user.service'; @Controller('@me') @UseGuards(RolesGuard) @@ -13,7 +14,16 @@ import { MeService } from './me.service'; @ApiBearerAuth() @ApiUnauthorizedResponse(UnauthorizedResponse) export class MeController { - constructor(private readonly meService: MeService) { } + constructor( + private readonly meService: MeService, + private readonly userService: UserService, + ) { } + + @Get() + @ApiOkResponse({ description: 'Get my profile' }) + async getMyProfile(@Req() req: Request) { + return await this.userService.getProfile(req.user.id); + } @Get("/class") @ApiOkResponse({ description: 'Get all classes' }) diff --git a/src/modules/me/me.service.ts b/src/modules/me/me.service.ts index f061392..4ce2e59 100644 --- a/src/modules/me/me.service.ts +++ b/src/modules/me/me.service.ts @@ -3,7 +3,9 @@ import { ClassService } from '../class/class.service'; @Injectable() export class MeService { - constructor(private readonly classService: ClassService) { } + constructor( + private readonly classService: ClassService, + ) { } async getMyClasses(userId: string) { return await this.classService.getUserClasses(userId); diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index 96df9f3..370e832 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -100,4 +100,15 @@ export class UserService { }, }); } + + async getProfile(id: string) { + return await this.prisma.user.findUnique({ + where: { id }, + select: { + id: true, + username: true, + role: true + } + }); + } }