Files
api_directorio/src/auth/auth.controller.ts
T

65 lines
1.4 KiB
TypeScript
Raw Normal View History

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-12 11:40:20 -06:00
import { UserDto } from 'src/users/dto/userDto.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-06 20:32:46 -06:00
2024-06-12 11:40:20 -06:00
@Post("register")
async postRegister(@Body() data: registerDto){
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
2024-06-12 11:40:20 -06:00
@UseGuards(AuthGuard)
2024-06-07 13:46:18 -06:00
@Post('Alta')
2024-06-12 11:40:20 -06:00
async create(@Body() data: UserDto) {
return this.authService.create(data);
2024-06-07 13:46:18 -06:00
}
2024-06-12 11:40:20 -06:00
@UseGuards(AuthGuard)
2024-06-07 13:46:18 -06:00
@Put('Modificacion/:id')
async update(@Param('id') id: number, @Body() updateUserDto: Record<string, any>) {
return this.authService.update(id, updateUserDto);
}
2024-06-12 11:40:20 -06:00
@UseGuards(AuthGuard)
2024-06-07 13:46:18 -06:00
@Delete('Borrado/:id')
async remove(@Param('id') id: number) {
await this.authService.remove(id);
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
}