Files
api_directorio/src/auth/auth.controller.ts
T
TioSam77 c7f3b2713f FRED3
2024-06-19 12:51:48 -06:00

59 lines
1.3 KiB
TypeScript

import {
Body,
Param,
Controller,
Get,
HttpCode,
HttpStatus,
Post,
Put,
Request,
UseGuards,
Delete
} from '@nestjs/common';
import { AuthGuard } from './auth.guard';
import { AuthService } from './auth.service';
import { registerDto } from './dto/registerDto.dto';
import { UserDto } from 'src/users/dto/userDto.dto';
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
@HttpCode(HttpStatus.OK)
@Post('login')
async signIn(@Body() data: registerDto) {
return this.authService.signIn(data);
}
//@UseGuards()
@Post("register")
async register(@Body() data: registerDto){
return this.authService.register(data)
}
@UseGuards(AuthGuard)
@Get('profile')
async getProfile(@Request() req) {
return req.user;
}
//@UseGuards(AuthGuard)
@Put('Modificacion/:id')
async update(@Param('id') id: number, @Body() updateUserDto: Record<string, any>) {
return this.authService.update(id, updateUserDto);
}
//@UseGuards(AuthGuard)
@Delete('Borrado/:id')
async remove(@Param('id') id: number) {
await this.authService.remove(id);
return { message: 'User successfully deleted' };
}
@HttpCode(HttpStatus.OK)
@Post('validate')
async validateToken(@Body('token') token: string) {
return this.authService.validateToken(token);
}
}