miinventario-backend-v2/src/modules/auth/auth.controller.ts
rckrdmrd 5a1c966ed2 Migración desde miinventario/backend - Estándar multi-repo v2
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:12:15 -06:00

53 lines
1.9 KiB
TypeScript

import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { RegisterDto } from './dto/register.dto';
import { LoginDto } from './dto/login.dto';
import { VerifyOtpDto } from './dto/verify-otp.dto';
import { RefreshTokenDto } from './dto/refresh-token.dto';
@ApiTags('auth')
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('register')
@ApiOperation({ summary: 'Iniciar registro con OTP' })
@ApiResponse({ status: 201, description: 'OTP enviado exitosamente' })
async register(@Body() registerDto: RegisterDto) {
return this.authService.initiateRegistration(registerDto);
}
@Post('verify-otp')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Verificar OTP y crear cuenta' })
@ApiResponse({ status: 200, description: 'Cuenta creada exitosamente' })
async verifyOtp(@Body() verifyOtpDto: VerifyOtpDto) {
return this.authService.verifyOtpAndCreateAccount(verifyOtpDto);
}
@Post('login')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Iniciar sesion' })
@ApiResponse({ status: 200, description: 'Login exitoso' })
async login(@Body() loginDto: LoginDto) {
return this.authService.login(loginDto);
}
@Post('refresh')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Renovar tokens' })
@ApiResponse({ status: 200, description: 'Tokens renovados' })
async refresh(@Body() refreshTokenDto: RefreshTokenDto) {
return this.authService.refreshTokens(refreshTokenDto);
}
@Post('logout')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Cerrar sesion' })
@ApiResponse({ status: 200, description: 'Sesion cerrada' })
async logout(@Body() body: { refreshToken: string }) {
return this.authService.logout(body.refreshToken);
}
}