fixed update user
This commit is contained in:
+1
-1
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user