2025-11-27 18:48:32 -06:00
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
NotFoundException,
|
|
|
|
|
Patch,
|
|
|
|
|
Post,
|
|
|
|
|
Req,
|
|
|
|
|
UseGuards,
|
|
|
|
|
} from '@nestjs/common';
|
2025-10-21 14:01:53 -06:00
|
|
|
import { AuthService } from './auth.service';
|
|
|
|
|
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
|
|
|
|
import { LoginDto } from './dto/login.dto';
|
2025-11-21 11:51:30 -06:00
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
|
import { UpdateUsuarioDto } from 'src/usuarios/dto/update-usuario.dto';
|
2025-11-27 18:48:32 -06:00
|
|
|
import { not } from 'rxjs/internal/util/not';
|
2025-10-21 14:01:53 -06:00
|
|
|
|
|
|
|
|
@Controller('auth')
|
|
|
|
|
export class AuthController {
|
2025-11-21 11:51:30 -06:00
|
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@Post('registro')
|
|
|
|
|
registro(@Body() registroDto: CreateUsuarioDto) {
|
|
|
|
|
return this.authService.registro(registroDto);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-28 16:04:44 -06:00
|
|
|
@Post('registro/Masivo')
|
|
|
|
|
registroMasivo(@Body() registroDto: CreateUsuarioDto[]) {
|
|
|
|
|
return this.authService.registroMasivo(registroDto);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-25 11:31:22 -06:00
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@Get('buscar')
|
|
|
|
|
search() {
|
|
|
|
|
return this.authService.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-21 11:51:30 -06:00
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@Patch('update')
|
2025-11-27 18:48:32 -06:00
|
|
|
update(@Body() registroDto: UpdateUsuarioDto, @Req() req: any) {
|
|
|
|
|
const id_usuario = req.user.id;
|
|
|
|
|
|
|
|
|
|
if (!id_usuario) {
|
|
|
|
|
throw new NotFoundException('token sin id_usuario');
|
|
|
|
|
}
|
2025-11-28 16:04:44 -06:00
|
|
|
|
|
|
|
|
return this.authService.update(registroDto, id_usuario);
|
2025-11-21 11:51:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('login')
|
|
|
|
|
login(@Body() loginDto: LoginDto) {
|
|
|
|
|
return this.authService.login(loginDto);
|
|
|
|
|
}
|
2025-10-21 14:01:53 -06:00
|
|
|
}
|