add recorator
This commit is contained in:
@@ -1,39 +1,36 @@
|
||||
import { Controller, Get, Req, UseGuards, Patch, Body, ValidationPipe } from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards, Patch, Body, ValidationPipe } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { AuthGuard, type AuthRequest } from 'src/modules/auth/guards/auth.guard';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { UserService } from './user.service';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { UserId } from 'src/common/decorators/user-id.decorator';
|
||||
|
||||
@ApiTags('User')
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get the current authenticated user profile' })
|
||||
@Get('/me')
|
||||
async getUser(@Req() req: AuthRequest) {
|
||||
const userId = req.userId;
|
||||
const restId = req.restId;
|
||||
async getUser(@UserId() userId: string) {
|
||||
const user = await this.userService.findById(userId);
|
||||
return {
|
||||
message: `GET request: Retrieving profile for authenticated user `,
|
||||
message: `GET request: Retrieving profile for authenticated user`,
|
||||
user,
|
||||
userId,
|
||||
restId,
|
||||
};
|
||||
}
|
||||
// 2. Update User Specification (PATCH /user)
|
||||
@UseGuards(AuthGuard)
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Update the authenticated user profile' })
|
||||
@Patch('/')
|
||||
async updateUser(
|
||||
@Req() req: AuthRequest,
|
||||
@UserId() userId: string,
|
||||
@Body(new ValidationPipe({ transform: true, whitelist: true })) dto: UpdateUserDto,
|
||||
) {
|
||||
const userId = req.userId;
|
||||
const user = await this.userService.updateUser(userId, dto);
|
||||
return {
|
||||
message: `PATCH request: Updating profile for user ${userId}`,
|
||||
@@ -41,16 +38,4 @@ export class UserController {
|
||||
user,
|
||||
};
|
||||
}
|
||||
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @ApiBearerAuth()
|
||||
// @ApiOperation({ summary: 'Users : Admin Route' })
|
||||
// @Get('/admin/users')
|
||||
// async findAll(
|
||||
// // Use ValidationPipe to validate and transform the DTO
|
||||
// @Query(new ValidationPipe({ transform: true, whitelist: true }))
|
||||
// query: FindUsersDto,
|
||||
// ) {
|
||||
// return this.userService.findAll(query);
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user