feat: add user profile retrieval to Me module

This commit is contained in:
Rémi 2025-01-02 22:11:13 +01:00
parent 7fc3e14612
commit db88a24028
3 changed files with 25 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import { JwtAuthGuard } from '../auth/guards/jwt.guard';
import { RolesGuard } from '../auth/guards/role.guard'; import { RolesGuard } from '../auth/guards/role.guard';
import { isUserInClassGuard } from './guards/isUserInClass.guard'; import { isUserInClassGuard } from './guards/isUserInClass.guard';
import { MeService } from './me.service'; import { MeService } from './me.service';
import { UserService } from '../user/user.service';
@Controller('@me') @Controller('@me')
@UseGuards(RolesGuard) @UseGuards(RolesGuard)
@ -13,7 +14,16 @@ import { MeService } from './me.service';
@ApiBearerAuth() @ApiBearerAuth()
@ApiUnauthorizedResponse(UnauthorizedResponse) @ApiUnauthorizedResponse(UnauthorizedResponse)
export class MeController { 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") @Get("/class")
@ApiOkResponse({ description: 'Get all classes' }) @ApiOkResponse({ description: 'Get all classes' })

View File

@ -3,7 +3,9 @@ import { ClassService } from '../class/class.service';
@Injectable() @Injectable()
export class MeService { export class MeService {
constructor(private readonly classService: ClassService) { } constructor(
private readonly classService: ClassService,
) { }
async getMyClasses(userId: string) { async getMyClasses(userId: string) {
return await this.classService.getUserClasses(userId); return await this.classService.getUserClasses(userId);

View File

@ -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
}
});
}
} }