users.controller.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {
  2. Controller,
  3. Get,
  4. Body,
  5. Param,
  6. HttpStatus,
  7. NotFoundException,
  8. BadRequestException,
  9. Req,
  10. Post
  11. } from '@nestjs/common'
  12. import { UsersService } from './users.service'
  13. import { UserProfileDto } from './dto/user-profile.dto'
  14. import { IUsers } from './interfaces/users.interface'
  15. import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
  16. import { Users } from './entities/users.entity'
  17. @ApiTags('users')
  18. @Controller('users')
  19. @ApiBearerAuth()
  20. export class UsersController {
  21. constructor(private readonly usersService: UsersService) {}
  22. @Get('/my')
  23. public async my(@Req() req) {
  24. return this.usersService.findById(req.user.userId)
  25. }
  26. @Post('/update')
  27. public async update(@Body() userProfileDto: UserProfileDto, @Req() req): Promise<any> {
  28. try {
  29. await this.usersService.updateProfileUser(req.user.userId, userProfileDto)
  30. return {
  31. message: 'User Updated successfully!',
  32. status: HttpStatus.OK
  33. }
  34. } catch (err) {
  35. throw new BadRequestException(err, 'Error: User not updated!')
  36. }
  37. }
  38. @Get('/invites')
  39. public async invites(@Req() req) {
  40. return this.usersService.getInvites(req.user.id)
  41. }
  42. @Get('/:userId')
  43. public async findOneUser(@Param('userId') userId: string): Promise<IUsers> {
  44. return this.usersService.findById(userId)
  45. }
  46. @Get('/:userId/profile')
  47. public async getUser(@Param('userId') userId: string): Promise<any> {
  48. const user = await this.findOneUser(userId)
  49. if (!user) {
  50. throw new NotFoundException('User does not exist!')
  51. }
  52. return {
  53. user: user,
  54. status: HttpStatus.OK
  55. }
  56. }
  57. }