fixed orderBy and added roles

This commit is contained in:
2026-03-17 12:07:26 -05:00
3 changed files with 53 additions and 5 deletions
+32 -3
View File
@@ -19,7 +19,36 @@ export class UserService {
@InjectRepository(Perfil)
private perfilRepository: Repository<Perfil>,
private jwtService: JwtService,
) {}
) { }
async toggleActivo(id: number) {
const usuario = await this.userRepository.findOne({
where: { id_usuario: id }
});
if (!usuario) {
throw new NotFoundException("no se encontro usuario")
}
usuario.activo = usuario.activo === 1 ? 0 : 1;
return this.userRepository.save(usuario);
}
async getactive(id: number) {
const user = await this.userRepository.findOne({
where: { id_usuario: id },
});
if (!user) {
throw new NotFoundException('Usuario no encontrado');
}
user.activo = user.activo === 1 ? 0 : 1;
return this.userRepository.save(user);
}
async findOneByNameandPassword(data: Login): Promise<User> {
const { usuario, password } = data;
@@ -28,7 +57,7 @@ export class UserService {
where: { usuario, password },
});
if(user?.activo === 0){
if (user?.activo === 0) {
throw new NotFoundException(`El usuario se encuentra desactivado`);
}
@@ -115,7 +144,7 @@ export class UserService {
}
async getAll() {
return this.userRepository.find();
return this.userRepository.find({select:['id_usuario','nombre','usuario','perfil','activo','password']});
}
async getAllPerfil() {