Commit 86e6f874 authored by Diego Iván's avatar Diego Iván
Browse files

agregando auth user controller con sign in y sign up

parent cd77dcf4
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
import { Body, Controller, Post } 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';
import { LoginUserDto } from './dto/login-user.dto';

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

  @ApiBody({ type: CreateUserDto })
  @ApiBearerAuth()
  @ApiCreatedResponse({
    content: {
      'application/json': {
        example: {
          token: 'token',
        },
      },
    },
  })
  @Post('user/signup')
  async signUp(@Body() createAdminDto: CreateUserDto) {
    try {
      const accessToken = await this.authUserService.signUp(createAdminDto);
      return { token: accessToken };
    } catch (e) {
      throw e;
    }
  }
  @ApiBody({ type: LoginUserDto })
  @ApiUnauthorizedResponse()
  @Post('user/signin')
  async signIn(@Body() loginAdminDto: LoginUserDto) {
    try {
      const adminSigninResDto =
        await this.authUserService.signIn(loginAdminDto);
      return adminSigninResDto;
    } catch (e) {
      throw e;
    }
  }
}