Compare commits
6 Commits
Lino
...
645c4ed6c1
| Author | SHA1 | Date | |
|---|---|---|---|
| 645c4ed6c1 | |||
| 4bd78578a7 | |||
| 5f5295dcb4 | |||
| 70e1e2d7bf | |||
| 3bb95a3d50 | |||
| 81ad881d6a |
+5
-1
@@ -86,6 +86,10 @@ import { Costo } from './costo/entities/costo.entity';
|
||||
Costo,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
|
||||
extra: {
|
||||
connectionLimit: 10,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
UserModule,
|
||||
@@ -113,5 +117,5 @@ import { Costo } from './costo/entities/costo.entity';
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
export class AppModule { }
|
||||
//IO
|
||||
|
||||
@@ -51,7 +51,7 @@ export class EquipoService {
|
||||
.innerJoin('equipo.plataforma', 'p')
|
||||
.innerJoin('equipo.areaUbicacion', 'a')
|
||||
.where('equipo.activo = 1')
|
||||
.orderBy('equipo.ubicacion', 'ASC')
|
||||
.orderBy('equipo.ubicacion + 0', 'ASC')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ export class EquipoService {
|
||||
return `equipo.id_equipo NOT IN ${subQuery}`;
|
||||
})
|
||||
|
||||
.orderBy('equipo.ubicacion', 'ASC')
|
||||
.orderBy('equipo.ubicacion + 0', 'ASC')
|
||||
|
||||
.getMany();
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ export class ProgramaEquipoController {
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('programas/:id')
|
||||
findAllProgramByNumber(@Param('id') id: number) {
|
||||
return this.programaEquipoService.findAllProgramByNumber(+id);
|
||||
async findAllProgramByNumber(@Param('id') id: number) {
|
||||
return await this.programaEquipoService.findAllProgramByNumber(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@@ -28,7 +28,7 @@ export class ProgramaEquipoController {
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.programaEquipoService.findOne(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ export class ProgramaEquipoService {
|
||||
return this.programaEquipoRepository.find();
|
||||
}
|
||||
|
||||
async findOne(ubicacion: string) {
|
||||
async findOne(id_equipo: number) {
|
||||
const equipo = await this.programaEquipoRepository.find({
|
||||
where: { equipo: { ubicacion } },
|
||||
where: { equipo: { id_equipo } },
|
||||
});
|
||||
|
||||
if (equipo.length === 0) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
UseGuards,
|
||||
Res,
|
||||
Req,
|
||||
Param,
|
||||
Patch,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
@@ -19,7 +21,15 @@ import { Role } from 'src/role.enum';
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/switch/:id')
|
||||
async getactive(@Param('id') id: number) {
|
||||
return this.userService.getactive(id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
async getAll() {
|
||||
return this.userService.getAll();
|
||||
@@ -27,11 +37,18 @@ export class UserController {
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/perfil')
|
||||
@Get('/perfil')
|
||||
async getAllPerfil() {
|
||||
return this.userService.getAllPerfil();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch(':id/activo')
|
||||
toggleActivo(@Param('id') id: number) {
|
||||
return this.userService.toggleActivo(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data: Login, @Res() res: Response) {
|
||||
return this.userService.Login(data, res);
|
||||
@@ -44,7 +61,9 @@ export class UserController {
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
|
||||
@Post('/create')
|
||||
async createUser(@Body() data: CreateUserDto) {
|
||||
return this.userService.create(data);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user