fixed update user

This commit is contained in:
IO
2024-07-27 21:03:38 -06:00
parent 896631ef5e
commit 28aba967b1
3 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
console.log("it's ok ")
console.log("it's ok IO")
return "hei verden";
}
+11 -6
View File
@@ -73,13 +73,18 @@ export class AuthService {
}
//update user
async update(id_usuario, data:registerDto) {
async update(id_usuario: number, data: registerDto) {
const { contraseña } = data;
const{contraseña}=data;
if(contraseña){
if (contraseña) {
const hashedpassword = await hash(contraseña, 10);
data = {...data,contraseña:hashedpassword};
data = { ...data, contraseña: hashedpassword };
} else {
const user = await this.userRepository.findOne({ where: { id_usuario } });
if (!user) {
throw new HttpException('User not found', 404);
}
data = { ...data, contraseña: user.contraseña };
}
return await this.userRepository.update(id_usuario, data);
@@ -108,7 +113,7 @@ export class AuthService {
throw new UnauthorizedException('Token has expired');
}
return user;
return ;
} catch (error) {
throw new UnauthorizedException('validation token failed');
}
+6 -3
View File
@@ -44,11 +44,14 @@ export class RolesGuard implements CanActivate {
);
const userRole: Role = userPayload.id_tipo_usuario;
if (userRole === undefined) {
return false; // Si el token no contiene roles, se niega el acceso
const userId: number = userPayload.id_usuario;
const paramId = parseInt(request.params.id_usuario, 10);
if (requiredRoles.includes(userRole) || userId === paramId) {
return true;
}
return requiredRoles.includes(userRole);
return false;
} catch (error) {
throw new UnauthorizedException('Invalid token');
}