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

55 lines
1.2 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 15:14:05 -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-11 15:14:05 -06:00
signIn(@Body() data: registerDto) {
return this.authService.signIn(data);
2024-06-05 14:35:05 -06:00
}
2024-06-06 20:32:46 -06:00
@UseGuards(AuthGuard)
@Get('profile')
getProfile(@Request() req) {
return req.user;
}
2024-06-07 13:46:18 -06:00
2024-06-11 15:14:05 -06:00
@Post("register")
postRegister(@Body() data: registerDto){
return this.authService.register(data)
}
2024-06-07 13:46:18 -06:00
@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' };
}
2024-06-06 20:32:46 -06:00
}