Commit 9ae7809c authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Se agregó el servicio de emails

parent 3cc04a3c
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
import { Body, Controller, Patch, Post, Req, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Patch, Post, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiCreatedResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { AuthUserService } from './authUserservice';
import { CreateUserDto } from 'src/user/dto/create-user.dto';
@@ -7,11 +7,14 @@ import { UserSigninResDto } from './dto/user-signin-res.dto';
import { AuthUserGuard } from './authUser.guard';
import { CustomUserRequest } from './interface/customUserReq';
import { UpdatePwdDto } from './dto/update-pwd.dto';
import { UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto } from './dto/user-reset-password.dto';
import { GetResetCode } from './dto/get-reset-code.dto';
import { EmailService } from 'src/email/email.service';

@Controller('')
@ApiTags('Create user account and sign in as user')
export class AuthUserController {
  constructor(private readonly authUserService: AuthUserService) {}
  constructor(private readonly authUserService: AuthUserService, private readonly mailService: EmailService) {}

  @ApiBody({ type: CreateUserDto })
  @ApiCreatedResponse({
@@ -47,4 +50,21 @@ export class AuthUserController {
  async changePassword(@Req() req: CustomUserRequest, @Body() updatePwdDto: UpdatePwdDto) {
    return this.authUserService.changePassword(req.user.email, updatePwdDto);
  }

  @ApiBody({ type: UserResetPasswordBody })
  @Post('user/reset-password')
  async resetPassword(@Body() resetPasswordDto: UserResetPasswordDto) {
    return this.authUserService.resetPassword(resetPasswordDto);
  }

  @ApiBody({ type: UserRequestCodeBody })
  @Post('user/get-reset-code')
  async getResetCode(@Body() resetPasswordInfo: GetResetCode) {
    try{
      const code = await this.authUserService.getResetPasswordCode(resetPasswordInfo.email);
      await this.mailService.sendResetPasswordEmail(resetPasswordInfo.email, code);
    } catch (e) {
      throw e;
    }
  }
}