From 19fc13613522a678bfa1176ace0ea98664b791ef Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 18 Jun 2024 17:20:39 -0600 Subject: [PATCH 1/2] fixed update and delate --- src/auth/auth.controller.ts | 12 +++++------- src/auth/auth.service.ts | 8 ++++++++ src/users/users.service.ts | 14 -------------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index d706461..2aa714e 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -37,16 +37,14 @@ export class AuthController { return req.user; } - @UseGuards(AuthGuard) @Put('Modificacion/:id') - async update(@Param('id') id: number, @Body() updateUserDto: Record) { - return this.authService.update(id, updateUserDto); + async update(@Param('id') userId: number, @Body() updateUserDto: Record) { + return this.authService.update(userId, updateUserDto); } - @UseGuards(AuthGuard) - @Delete('Borrado/:id') - async remove(@Param('id') id: number) { - await this.authService.remove(id); + @Delete(':id') + async remove(@Param('id') userId: number) { + await this.authService.remove(userId); return { message: 'User successfully deleted' }; } diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 801ab29..6a2e42c 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -66,6 +66,14 @@ export class AuthService { } async update(userId, updateUserDto) { + + const{contraseña}=updateUserDto; + + if(contraseña){ + const hashedpassword = await hash(contraseña, 10); + updateUserDto = {...updateUserDto,contraseña:hashedpassword}; + } + return await this.userRepository.update(userId, updateUserDto); } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index bf6736b..9b17aa0 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -14,20 +14,6 @@ export class UsersService { async findOne(usuario: string): Promise { return this.users.findOne({ where: { usuario } }); } - - async create(user: User): Promise { - const newUser = this.users.create(user); - return this.users.save(newUser); - } - - //async update(userId: number, updateUserDto: UserDto): Promise { - //return await this.users.update(userId, updateUserDto); - //} - - async remove(userId: number): Promise { - await this.users.delete(userId); - } - async updateTokenAndDates( id: number, token: string, From bfa5afd0f09aa7607af7e1e9913897f5af2ac378 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 18 Jun 2024 17:22:51 -0600 Subject: [PATCH 2/2] just in case --- src/auth/auth.controller.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 2aa714e..86fe81d 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -14,7 +14,6 @@ import { 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 {