Files
api_directorio/src/auth/auth.controller.ts
T
TuNombreDeUsuario 6516439270 EP
2024-06-07 13:46:18 -06:00

49 lines
1.1 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';
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
@HttpCode(HttpStatus.OK)
@Post('login')
signIn(@Body() signInDto: Record<string, any>) {
return this.authService.signIn(signInDto.username, signInDto.password);
}
@UseGuards(AuthGuard)
@Get('profile')
getProfile(@Request() req) {
return req.user;
}
@Post('Alta')
async create(@Body() createUserDto: Record<string, any>) {
return this.authService.create(createUserDto.username,createUserDto.password);
}
@Put('Modificacion/:id')
async update(@Param('id') id: number, @Body() updateUserDto: Record<string, any>) {
return this.authService.update(id, updateUserDto);
}
@Delete('Borrado/:id')
async remove(@Param('id') id: number) {
await this.authService.remove(id);
return { message: 'User successfully deleted' };
}
}