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

67 lines
1.5 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-24 16:12:23 -06:00
import {Roles} from '../permissions/roles.decorator'
import {RolesGuard} from '../permissions/roles.guard'
import {Role} from '../permissions/role.enum'
2024-06-05 14:35:05 -06:00
@Controller('auth')
2024-06-24 17:02:02 -06:00
//@UseGuards(RolesGuard)
2024-06-05 14:35:05 -06:00
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-24 16:12:23 -06:00
2024-06-24 17:02:02 -06:00
//@UseGuards()
2024-06-12 11:40:20 -06:00
@Post("register")
2024-06-24 17:02:02 -06:00
//@Roles(Role.Admin)
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-24 17:02:02 -06:00
//@UseGuards(AuthGuard)
2024-06-06 20:32:46 -06:00
@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-24 17:02:02 -06:00
//@UseGuards(AuthGuard)
2024-06-07 13:46:18 -06:00
@Put('Modificacion/:id')
2024-06-24 17:02:02 -06:00
//@Roles(Role.Admin)
2024-06-19 12:49:28 -06:00
async update(@Param('id') userId: number, @Body() data: registerDto) {
return this.authService.update(userId, data);
2024-06-07 13:46:18 -06:00
}
2024-06-24 17:02:02 -06:00
//@UseGuards(AuthGuard)
2024-06-18 19:34:55 -06:00
@Delete('Borrado/:id')
2024-06-24 17:02:02 -06:00
//@Roles(Role.Admin)
2024-06-18 19:34:55 -06:00
async remove(@Param('id') id: number) {
await this.authService.remove(id);
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
}