modified update user
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import { Body, Controller, Get, Patch, Post, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
NotFoundException,
|
||||
Patch,
|
||||
Post,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { UpdateUsuarioDto } from 'src/usuarios/dto/update-usuario.dto';
|
||||
import { not } from 'rxjs/internal/util/not';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
@@ -23,8 +33,14 @@ export class AuthController {
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Patch('update')
|
||||
update(@Body() registroDto: UpdateUsuarioDto) {
|
||||
return this.authService.update(registroDto);
|
||||
update(@Body() registroDto: UpdateUsuarioDto, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
|
||||
if (!id_usuario) {
|
||||
throw new NotFoundException('token sin id_usuario');
|
||||
}
|
||||
|
||||
return this.authService.update(registroDto,id_usuario);
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
|
||||
@@ -18,9 +18,9 @@ export class AuthService {
|
||||
private readonly jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
async update(registroDto: UpdateUsuarioDto) {
|
||||
async update(registroDto: UpdateUsuarioDto, id_User:number) {
|
||||
const update_data = await this.usuarioService.actualizarUsuario(
|
||||
registroDto.id_User,
|
||||
id_User,
|
||||
{
|
||||
nombre: registroDto.nombre,
|
||||
contraseñaN: registroDto.contraseñaN,
|
||||
|
||||
@@ -9,10 +9,6 @@ import {
|
||||
} from 'class-validator';
|
||||
|
||||
export class UpdateUsuarioDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
id_User: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
nombre?: string;
|
||||
|
||||
Reference in New Issue
Block a user