feat: add user profile retrieval to Me module
This commit is contained in:
parent
7fc3e14612
commit
db88a24028
@ -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' })
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user