2025-09-16 22:37:25 -06:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Body,
|
|
|
|
|
UseGuards,
|
|
|
|
|
Request,
|
|
|
|
|
Res,
|
2025-09-24 11:04:08 -04:00
|
|
|
Req,
|
2025-09-16 22:37:25 -06:00
|
|
|
} from '@nestjs/common';
|
2025-09-12 20:41:51 -06:00
|
|
|
import type { Response } from 'express';
|
2025-09-04 21:04:15 -04:00
|
|
|
import { UserService } from './user.service';
|
2025-09-24 11:34:50 -06:00
|
|
|
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
|
2025-09-12 13:18:11 -04:00
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
2025-09-24 11:04:08 -04:00
|
|
|
import { JwtAuthGuard } from './jwt.guard';
|
2025-09-04 21:04:15 -04:00
|
|
|
|
|
|
|
|
@Controller('user')
|
|
|
|
|
export class UserController {
|
2025-09-16 22:37:25 -06:00
|
|
|
constructor(private readonly userService: UserService) {}
|
2025-09-12 20:41:51 -06:00
|
|
|
|
2025-09-16 22:37:25 -06:00
|
|
|
@Post()
|
2025-09-24 11:00:56 -06:00
|
|
|
async Login(@Body() data: Login, @Res() res: Response) {
|
2025-09-16 22:37:25 -06:00
|
|
|
return this.userService.Login(data, res);
|
|
|
|
|
}
|
2025-09-12 13:18:11 -04:00
|
|
|
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@Get('/validate-token')
|
2025-09-24 11:04:08 -04:00
|
|
|
getProfile(@Req() req) {
|
2025-09-16 22:37:25 -06:00
|
|
|
return req.user;
|
2025-09-12 13:18:11 -04:00
|
|
|
}
|
2025-09-24 11:00:56 -06:00
|
|
|
|
|
|
|
|
@Post('/create')
|
|
|
|
|
async createUser(@Body() data: CreateUserDto) {
|
|
|
|
|
return this.userService.create(data);
|
|
|
|
|
}
|
2025-09-24 11:34:50 -06:00
|
|
|
|
2025-09-24 11:04:08 -04:00
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Post('/change-password')
|
|
|
|
|
async changePassword(@Body() data: changePasswordDto, @Req() req) {
|
|
|
|
|
const id_usuario = req.user.id;
|
|
|
|
|
await this.userService.changePassword(data, id_usuario);
|
|
|
|
|
return { message: 'Contraseña actualizada correctamente' };
|
|
|
|
|
}
|
2025-09-04 21:04:15 -04:00
|
|
|
}
|
2025-09-16 22:37:25 -06:00
|
|
|
//IO
|