Skip to content
Snippets Groups Projects
Select Git revision
  • d450d44c79acda0262f74e3093a384822f6be733
  • dev default protected
  • renovate/bitnami-mongodb-8.x
  • renovate/ghcr.io-browserless-chromium-2.x
  • renovate/major-nest-monorepo
  • renovate/luxon-3.x
  • renovate/gouvfr-anct-timetable-to-osm-opening-hours-2.x
  • renovate/major-typescript-eslint-monorepo
  • renovate/npm-11.x
  • renovate/mysql-9.x
  • renovate/mongo-express-1.x
  • renovate/major-jest-monorepo
  • renovate/tsconfig-paths-4.x
  • renovate/jest-junit-16.x
  • renovate/express-5.x
  • renovate/elastic-elasticsearch-8.x
  • renovate/ghost-5.x
  • renovate/elasticsearch-7.x
  • renovate/devdependencies-(non-major)
  • 714-label-cafe-ia
  • master protected
  • v4.0.3
  • v4.0.1
  • v4.0.0
  • v3.4.3
  • v3.4.2
  • v3.4.1
  • v3.4.0
  • v3.3.1
  • v3.3.0
  • v3.2.0
  • v3.1.0
  • v3.0.1
  • v3.0.0
  • v2.5.0
  • v2.4.2
  • v2.4.1
  • v2.4.0
  • v2.3.2
  • v2.3.1
  • v2.3.0
41 results

users.controller.ts

Blame
  • users.controller.ts 2.55 KiB
    import { Body, Controller, Get, Param, Post, Query, Request, UseGuards } from '@nestjs/common';
    import { ApiOperation, ApiParam, ApiResponse } from '@nestjs/swagger';
    import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
    import { PasswordChangeDto } from './change-password.dto';
    import { EmailChangeDto } from './change-email.dto';
    import { CreateUserDto } from './create-user.dto';
    import { UsersService } from './users.service';
    
    @Controller('users')
    export class UsersController {
      constructor(private usersService: UsersService) {}
    
      @UseGuards(JwtAuthGuard)
      @ApiOperation({ description: 'Get user profile' })
      @ApiResponse({ status: 200, description: 'Return user profil' })
      @ApiResponse({ status: 401, description: 'User does not have sufficient rights' })
      @Get('profile')
      public getProfile(@Request() req) {
        return req.user;
      }
    
      @Post()
      @ApiResponse({ status: 201, description: 'User created' })
      public async create(@Body() createUserDto: CreateUserDto) {
        return this.usersService.create(createUserDto);
      }
    
      @Post('verify/:id')
      @ApiParam({ name: 'id', type: String, required: true })
      @ApiResponse({ status: 201, description: 'User verified' })
      @ApiResponse({ status: 401, description: "This token does'nt exist or is not associate to this user." })
      public async validateUser(@Param() params, @Query('token') token: string) {
        return this.usersService.validateUser(params.id, token);
      }
    
      @UseGuards(JwtAuthGuard)
      @Post('change-password')
      @ApiResponse({ status: 201, description: 'Password changed' })
      @ApiResponse({ status: 401, description: 'Invalid password' })
      @ApiResponse({ status: 422, description: 'Weak password' })
      public async changePassword(@Request() req, @Body() passwordChangeDto: PasswordChangeDto) {
        return this.usersService.changeUserPassword(
          req.user._id,
          passwordChangeDto.oldPassword,
          passwordChangeDto.newPassword
        );
      }
    
      @UseGuards(JwtAuthGuard)
      @Post('change-email')
      @ApiResponse({ status: 201, description: 'Email confirmation send' })
      @ApiResponse({ status: 401, description: 'Invalid Email' })
      public async changeEmail(@Request() req, @Body() emailChangeDto: EmailChangeDto) {
        return this.usersService.changeUserEmail(emailChangeDto);
      }
    
      @UseGuards(JwtAuthGuard)
      @Post('verify-change-email')
      @ApiResponse({ status: 201, description: 'Email changed' })
      @ApiResponse({ status: 401, description: 'Invalid Token' })
      public async verifyAndUpdateEmail(@Request() req, @Query('token') token: string) {
        return this.usersService.verifyAndUpdateUserEmail(token);
      }
    }