2024-06-06 20:32:46 -06:00
|
|
|
import {
|
|
|
|
|
Body,
|
2024-06-07 13:46:18 -06:00
|
|
|
Param,
|
2024-06-06 20:32:46 -06:00
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
HttpCode,
|
|
|
|
|
HttpStatus,
|
|
|
|
|
Post,
|
2024-06-07 13:46:18 -06:00
|
|
|
Put,
|
2024-06-06 20:32:46 -06:00
|
|
|
Request,
|
2024-06-07 13:46:18 -06:00
|
|
|
UseGuards,
|
|
|
|
|
Delete
|
2024-06-06 20:32:46 -06:00
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { AuthGuard } from './auth.guard';
|
2024-06-05 14:35:05 -06:00
|
|
|
import { AuthService } from './auth.service';
|
2024-06-11 19:58:36 -06:00
|
|
|
import { registerDto } from './dto/registerDto.dto';
|
2024-06-05 14:35:05 -06:00
|
|
|
|
|
|
|
|
@Controller('auth')
|
|
|
|
|
export class AuthController {
|
|
|
|
|
constructor(private authService: AuthService) {}
|
|
|
|
|
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@Post('login')
|
2024-06-12 11:40:20 -06:00
|
|
|
async signIn(@Body() data: registerDto) {
|
2024-06-11 15:14:05 -06:00
|
|
|
return this.authService.signIn(data);
|
2024-06-05 14:35:05 -06:00
|
|
|
}
|
2024-06-18 17:23:30 -06:00
|
|
|
//@UseGuards()
|
2024-06-12 11:40:20 -06:00
|
|
|
@Post("register")
|
2024-06-18 16:24:50 -06:00
|
|
|
async register(@Body() data: registerDto){
|
2024-06-12 11:40:20 -06:00
|
|
|
return this.authService.register(data)
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 20:32:46 -06:00
|
|
|
@UseGuards(AuthGuard)
|
|
|
|
|
@Get('profile')
|
2024-06-12 11:40:20 -06:00
|
|
|
async getProfile(@Request() req) {
|
2024-06-06 20:32:46 -06:00
|
|
|
return req.user;
|
|
|
|
|
}
|
2024-06-07 13:46:18 -06:00
|
|
|
|
|
|
|
|
@Put('Modificacion/:id')
|
2024-06-18 17:20:39 -06:00
|
|
|
async update(@Param('id') userId: number, @Body() updateUserDto: Record<string, any>) {
|
|
|
|
|
return this.authService.update(userId, updateUserDto);
|
2024-06-07 13:46:18 -06:00
|
|
|
}
|
|
|
|
|
|
2024-06-18 17:20:39 -06:00
|
|
|
@Delete(':id')
|
|
|
|
|
async remove(@Param('id') userId: number) {
|
|
|
|
|
await this.authService.remove(userId);
|
2024-06-07 13:46:18 -06:00
|
|
|
return { message: 'User successfully deleted' };
|
|
|
|
|
}
|
2024-06-12 11:40:20 -06:00
|
|
|
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@Post('validate')
|
|
|
|
|
async validateToken(@Body('token') token: string) {
|
|
|
|
|
return this.authService.validateToken(token);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 20:32:46 -06:00
|
|
|
}
|