change-password.controller.ts 1.0 KB

123456789101112131415161718192021222324252627
  1. import { Controller, Post, Body, HttpStatus, BadRequestException } from '@nestjs/common'
  2. import { ChangePasswordService } from './change-password.service'
  3. import { ChangePasswordDto } from './dto/change-password.dto'
  4. import { ApiTags } from '@nestjs/swagger'
  5. import { AuthGuard } from '../login/decorators/auth-guard.decorator'
  6. import { AuthType } from '../login/enums/auth-type.enum'
  7. @ApiTags('auth')
  8. @AuthGuard(AuthType.Bearer)
  9. @Controller('auth/change-password')
  10. export class ChangePasswordController {
  11. constructor(private readonly changePasswordService: ChangePasswordService) {}
  12. @Post()
  13. public async changePassword(@Body() changePasswordDto: ChangePasswordDto): Promise<any> {
  14. try {
  15. await this.changePasswordService.changePassword(changePasswordDto)
  16. return {
  17. message: 'Request Change Password Successfully!',
  18. status: HttpStatus.OK
  19. }
  20. } catch (err) {
  21. throw new BadRequestException(err, 'Error: Change password failed!')
  22. }
  23. }
  24. }