42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { Controller, Get, UseGuards, Patch, Body, ValidationPipe } from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
|
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(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Get the current authenticated user profile' })
|
|
@Get('/me')
|
|
async getUser(@UserId() userId: string) {
|
|
const user = await this.userService.findById(userId);
|
|
return {
|
|
message: `GET request: Retrieving profile for authenticated user`,
|
|
user,
|
|
userId,
|
|
};
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Update the authenticated user profile' })
|
|
@Patch('/')
|
|
async updateUser(
|
|
@UserId() userId: string,
|
|
@Body(new ValidationPipe({ transform: true, whitelist: true })) dto: UpdateUserDto,
|
|
) {
|
|
const user = await this.userService.updateUser(userId, dto);
|
|
return {
|
|
message: `PATCH request: Updating profile for user ${userId}`,
|
|
userId,
|
|
user,
|
|
};
|
|
}
|
|
}
|