| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import {
- Controller,
- Put,
- Get,
- Body,
- Param,
- HttpStatus,
- NotFoundException,
- Delete,
- BadRequestException,
- } from '@nestjs/common';
- import { UsersService } from './users.service';
- import { UserProfileDto } from './dto/user-profile.dto';
- import { UserUpdateDto } from './dto/user-update.dto';
- import { IUsers } from './interfaces/users.interface';
- import { ApiTags } from '@nestjs/swagger';
- import { AuthGuard } from '../iam/login/decorators/auth-guard.decorator';
- import { AuthType } from '../iam/login/enums/auth-type.enum';
- @ApiTags('users')
- @AuthGuard(AuthType.Bearer)
- @Controller('users')
- export class UsersController {
- constructor(private readonly usersService: UsersService) {}
- @Get()
- public async findAllUser(): Promise<IUsers[]> {
- return this.usersService.findAll();
- }
- @Get('/:userId')
- public async findOneUser(@Param('userId') userId: string): Promise<IUsers> {
- return this.usersService.findById(userId);
- }
- @Get('/:userId/profile')
- public async getUser(@Param('userId') userId: string): Promise<any> {
- const user = await this.findOneUser(userId);
- if (!user) {
- throw new NotFoundException('User does not exist!');
- }
- return {
- user: user,
- status: HttpStatus.OK,
- };
- }
- @Put('/:userId/profile')
- public async updateProfileUser(
- @Param('userId') userId: string,
- @Body() userProfileDto: UserProfileDto,
- ): Promise<any> {
- try {
- await this.usersService.updateProfileUser(userId, userProfileDto);
- return {
- message: 'User Updated successfully!',
- status: HttpStatus.OK,
- };
- } catch (err) {
- throw new BadRequestException(err, 'Error: User not updated!');
- }
- }
- @Put('/:userId')
- public async updateUser(
- @Param('userId') userId: string,
- @Body() userUpdateDto: UserUpdateDto,
- ) {
- try {
- await this.usersService.updateUser(userId, userUpdateDto);
- return {
- message: 'User Updated successfully!',
- status: HttpStatus.OK,
- };
- } catch (err) {
- throw new BadRequestException(err, 'Error: User not updated!');
- }
- }
- @Delete('/:userId')
- public async deleteUser(@Param('userId') userId: string): Promise<void> {
- await this.usersService.deleteUser(userId);
- }
- }
|