| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import {
- Controller,
- Get,
- Body,
- Param,
- HttpStatus,
- NotFoundException,
- BadRequestException,
- Req,
- Post
- } from '@nestjs/common'
- import { UsersService } from './users.service'
- import { UserProfileDto } from './dto/user-profile.dto'
- import { IUsers } from './interfaces/users.interface'
- import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
- import { Users } from './entities/users.entity'
- @ApiTags('users')
- @Controller('users')
- @ApiBearerAuth()
- export class UsersController {
- constructor(private readonly usersService: UsersService) {}
- @Get('/my')
- public async my(@Req() req) {
- return this.usersService.findById(req.user.userId)
- }
- @Post('/update')
- public async update(@Body() userProfileDto: UserProfileDto, @Req() req): Promise<any> {
- try {
- await this.usersService.updateProfileUser(req.user.userId, userProfileDto)
- return {
- message: 'User Updated successfully!',
- status: HttpStatus.OK
- }
- } catch (err) {
- throw new BadRequestException(err, 'Error: User not updated!')
- }
- }
- @Get('/invites')
- public async invites(@Req() req) {
- return this.usersService.getInvites(req.user.id)
- }
- @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
- }
- }
- }
|