This commit is contained in:
TioSam77
2024-06-18 17:24:08 -06:00
3 changed files with 13 additions and 22 deletions
+5 -8
View File
@@ -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 {
@@ -37,16 +36,14 @@ export class AuthController {
return req.user;
}
@UseGuards(AuthGuard)
@Put('Modificacion/:id')
async update(@Param('id') id: number, @Body() updateUserDto: Record<string, any>) {
return this.authService.update(id, updateUserDto);
async update(@Param('id') userId: number, @Body() updateUserDto: Record<string, any>) {
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' };
}
+8
View File
@@ -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);
}
-14
View File
@@ -14,20 +14,6 @@ export class UsersService {
async findOne(usuario: string): Promise<User | undefined> {
return this.users.findOne({ where: { usuario } });
}
async create(user: User): Promise<User> {
const newUser = this.users.create(user);
return this.users.save(newUser);
}
//async update(userId: number, updateUserDto: UserDto): Promise<User> {
//return await this.users.update(userId, updateUserDto);
//}
async remove(userId: number): Promise<void> {
await this.users.delete(userId);
}
async updateTokenAndDates(
id: number,
token: string,