Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4db486a8c6 | |||
| a1028b1cd8 | |||
| 07c1e1651a | |||
| 61fb91c7ec | |||
| 46ad8e88ce | |||
| 94641514ad | |||
| f334a0f9e2 | |||
| ac009d0688 | |||
| 8b6186ff6e | |||
| 0d9e82f527 | |||
| 65bdb47c00 | |||
| 73e0ede7ed | |||
| 645c4ed6c1 | |||
| 4bd78578a7 | |||
| 5f5295dcb4 | |||
| 70e1e2d7bf | |||
| 2071be5a65 | |||
| 0cf4fc5d3c | |||
| 9d07eab337 | |||
| af2052111c | |||
| 3bb95a3d50 | |||
| e28d534edf | |||
| 81ad881d6a | |||
| 54d878c145 | |||
| 04290f4097 | |||
| 22431dd73e | |||
| 9ddff920fb |
Generated
+347
-557
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,7 @@
|
|||||||
"@nestjs/typeorm": "^11.0.0",
|
"@nestjs/typeorm": "^11.0.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.2",
|
"class-validator": "^0.14.2",
|
||||||
|
"ldapts": "^8.1.7",
|
||||||
"mysql2": "^3.14.4",
|
"mysql2": "^3.14.4",
|
||||||
"passport": "^0.7.0",
|
"passport": "^0.7.0",
|
||||||
"passport-jwt": "^4.0.1",
|
"passport-jwt": "^4.0.1",
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ActiveDirectoryController } from './active-directory.controller';
|
||||||
|
import { ActiveDirectoryService } from './active-directory.service';
|
||||||
|
|
||||||
|
describe('ActiveDirectoryController', () => {
|
||||||
|
let controller: ActiveDirectoryController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [ActiveDirectoryController],
|
||||||
|
providers: [ActiveDirectoryService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<ActiveDirectoryController>(ActiveDirectoryController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { Controller, Post, Body, Param } from '@nestjs/common';
|
||||||
|
import { ActiveDirectoryService } from './active-directory.service';
|
||||||
|
|
||||||
|
@Controller('active-directory')
|
||||||
|
export class ActiveDirectoryController {
|
||||||
|
constructor(private readonly adService: ActiveDirectoryService) {}
|
||||||
|
|
||||||
|
@Post('crear/:cuenta')
|
||||||
|
async crearUsuario(@Param('cuenta') cuenta: string) {
|
||||||
|
await this.adService.createUser(cuenta);
|
||||||
|
return { message: `Usuario ${cuenta} creado en AD` };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('reset/:cuenta')
|
||||||
|
async resetPassword(@Param('cuenta') cuenta: string) {
|
||||||
|
await this.adService.resetPassword(cuenta);
|
||||||
|
return { message: `Contraseña de ${cuenta} reseteada` };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('cambiar-password/:cuenta')
|
||||||
|
async cambiarPassword(
|
||||||
|
@Param('cuenta') cuenta: string,
|
||||||
|
@Body('password') password?: string,
|
||||||
|
) {
|
||||||
|
await this.adService.changePassword(cuenta, password);
|
||||||
|
return { message: `Contraseña de ${cuenta} actualizada` };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { ActiveDirectoryService } from './active-directory.service';
|
||||||
|
import { ActiveDirectoryController } from './active-directory.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [ConfigModule],
|
||||||
|
providers: [ActiveDirectoryService],
|
||||||
|
controllers: [ActiveDirectoryController],
|
||||||
|
exports: [ActiveDirectoryService],
|
||||||
|
})
|
||||||
|
export class ActiveDirectoryModule {}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ActiveDirectoryService } from './active-directory.service';
|
||||||
|
|
||||||
|
describe('ActiveDirectoryService', () => {
|
||||||
|
let service: ActiveDirectoryService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [ActiveDirectoryService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<ActiveDirectoryService>(ActiveDirectoryService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { Client, Attribute, Change } from 'ldapts';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ActiveDirectoryService {
|
||||||
|
private readonly logger = new Logger(ActiveDirectoryService.name);
|
||||||
|
|
||||||
|
constructor(private configService: ConfigService) { }
|
||||||
|
|
||||||
|
private createClient(): Client {
|
||||||
|
return new Client({
|
||||||
|
url: this.configService.get<string>('AD_URL')!,
|
||||||
|
tlsOptions: { rejectUnauthorized: false },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async createUser(cuenta: string): Promise<void> {
|
||||||
|
const client = this.createClient();
|
||||||
|
const bindDN = this.configService.get<string>('AD_BIND_DN')!;
|
||||||
|
const bindPass = this.configService.get<string>('AD_BIND_PASS')!;
|
||||||
|
const baseDN = this.configService.get<string>('AD_BASE_DN')!;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.bind(bindDN, bindPass);
|
||||||
|
|
||||||
|
const userDN = `CN=${cuenta},${baseDN}`;
|
||||||
|
|
||||||
|
await client.add(userDN, {
|
||||||
|
objectClass: ['top', 'person', 'organizationalPerson', 'user'],
|
||||||
|
sAMAccountName: cuenta,
|
||||||
|
cn: cuenta,
|
||||||
|
description: 'Creado desde el Sitio',
|
||||||
|
userAccountControl: '32',
|
||||||
|
});
|
||||||
|
|
||||||
|
const encodedPassword = Buffer.from(`"${cuenta}"`, 'utf16le');
|
||||||
|
|
||||||
|
await client.modify(userDN, [
|
||||||
|
new Change({
|
||||||
|
operation: 'replace',
|
||||||
|
modification: new Attribute({ type: 'unicodePwd', values: [encodedPassword] }),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await client.modify(userDN, [
|
||||||
|
new Change({
|
||||||
|
operation: 'replace',
|
||||||
|
modification: new Attribute({ type: 'pwdLastSet', values: ['0'] }),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await client.modify(userDN, [
|
||||||
|
new Change({
|
||||||
|
operation: 'replace',
|
||||||
|
modification: new Attribute({ type: 'userAccountControl', values: ['512'] }),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
this.logger.log(`Usuario ${cuenta} creado exitosamente en AD`);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`Error al crear usuario ${cuenta} en AD`, error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await client.unbind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async resetPassword(cuenta: string): Promise<void> {
|
||||||
|
const client = this.createClient();
|
||||||
|
const bindDN = this.configService.get<string>('AD_BIND_DN')!;
|
||||||
|
const bindPass = this.configService.get<string>('AD_BIND_PASS')!;
|
||||||
|
const baseDN = this.configService.get<string>('AD_BASE_DN')!;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.bind(bindDN, bindPass);
|
||||||
|
const userDN = `CN=${cuenta},${baseDN}`;
|
||||||
|
await client.del(userDN);
|
||||||
|
this.logger.log(`Usuario ${cuenta} eliminado de AD`);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(`No se pudo eliminar ${cuenta} de AD (puede no existir)`, error);
|
||||||
|
} finally {
|
||||||
|
await client.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.createUser(cuenta);
|
||||||
|
}
|
||||||
|
|
||||||
|
async changePassword(cuenta: string, newPass?: string): Promise<void> {
|
||||||
|
const client = this.createClient();
|
||||||
|
const bindDN = this.configService.get<string>('AD_BIND_DN')!;
|
||||||
|
const bindPass = this.configService.get<string>('AD_BIND_PASS')!;
|
||||||
|
const baseDN = this.configService.get<string>('AD_BASE_DN')!;
|
||||||
|
const password = newPass ?? cuenta;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.bind(bindDN, bindPass);
|
||||||
|
|
||||||
|
const userDN = `CN=${cuenta},${baseDN}`;
|
||||||
|
const encodedPassword = Buffer.from(`"${password}"`, 'utf16le');
|
||||||
|
|
||||||
|
await client.modify(userDN, [
|
||||||
|
new Change({
|
||||||
|
operation: 'replace',
|
||||||
|
modification: new Attribute({ type: 'unicodePwd', values: [encodedPassword] }),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await client.modify(userDN, [
|
||||||
|
new Change({
|
||||||
|
operation: 'replace',
|
||||||
|
modification: new Attribute({ type: 'pwdLastSet', values: ['0'] }),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
this.logger.log(`Contraseña de ${cuenta} actualizada`);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`Error al cambiar contraseña de ${cuenta}`, error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await client.unbind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export class CreateActiveDirectoryDto {}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateActiveDirectoryDto } from './create-active-directory.dto';
|
||||||
|
|
||||||
|
export class UpdateActiveDirectoryDto extends PartialType(CreateActiveDirectoryDto) {}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export class ActiveDirectory {}
|
||||||
@@ -32,8 +32,7 @@ export class AlumnoController {
|
|||||||
return this.alumnoService.findOneWhitSancion(+id);
|
return this.alumnoService.findOneWhitSancion(+id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
//delete guard to use in cedetec
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA)
|
|
||||||
@Get('sancion/:id')
|
@Get('sancion/:id')
|
||||||
findOne(@Param('id') id: number) {
|
findOne(@Param('id') id: number) {
|
||||||
return this.alumnoService.findOne(+id);
|
return this.alumnoService.findOne(+id);
|
||||||
|
|||||||
@@ -54,9 +54,26 @@ export class AlumnoSancionService {
|
|||||||
|
|
||||||
const alusancion = await this.alumnosancionRepository.find({
|
const alusancion = await this.alumnosancionRepository.find({
|
||||||
where: { alumno: { id_cuenta } },
|
where: { alumno: { id_cuenta } },
|
||||||
|
relations: ['sancion'],
|
||||||
});
|
});
|
||||||
|
|
||||||
return { student, alusancion };
|
const now = new Date();
|
||||||
|
|
||||||
|
const sancionesActivas = alusancion.filter((item) => {
|
||||||
|
const fechaInicio = new Date(item.fecha_inicio);
|
||||||
|
|
||||||
|
const fechaFin = new Date(fechaInicio);
|
||||||
|
fechaFin.setDate(
|
||||||
|
fechaFin.getDate() + item.sancion.duracion * 7,
|
||||||
|
);
|
||||||
|
|
||||||
|
return fechaFin >= now;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
student,
|
||||||
|
alusancion: sancionesActivas,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeByStudent(id_cuenta: number): Promise<{ message: string }> {
|
async removeByStudent(id_cuenta: number): Promise<{ message: string }> {
|
||||||
|
|||||||
+10
-1
@@ -43,6 +43,7 @@ import { BitacoraModule } from './bitacora/bitacora.module';
|
|||||||
import { Bitacora } from './bitacora/entities/bitacora.entity';
|
import { Bitacora } from './bitacora/entities/bitacora.entity';
|
||||||
import { MensajeModule } from './mensaje/mensaje.module';
|
import { MensajeModule } from './mensaje/mensaje.module';
|
||||||
import { Mensaje } from './mensaje/entities/mensaje.entity';
|
import { Mensaje } from './mensaje/entities/mensaje.entity';
|
||||||
|
import { ActiveDirectoryModule } from './active-directory/active-directory.module';
|
||||||
import { CostoModule } from './costo/costo.module';
|
import { CostoModule } from './costo/costo.module';
|
||||||
import { Costo } from './costo/entities/costo.entity';
|
import { Costo } from './costo/entities/costo.entity';
|
||||||
|
|
||||||
@@ -85,6 +86,13 @@ import { Costo } from './costo/entities/costo.entity';
|
|||||||
Costo,
|
Costo,
|
||||||
],
|
],
|
||||||
synchronize: false, //Never change to true in production!
|
synchronize: false, //Never change to true in production!
|
||||||
|
|
||||||
|
extra: {
|
||||||
|
connectionLimit: 5,
|
||||||
|
waitForConnections: true,
|
||||||
|
idleTimeout: 60000,
|
||||||
|
connectTimeout: 10000,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
UserModule,
|
UserModule,
|
||||||
@@ -107,9 +115,10 @@ import { Costo } from './costo/entities/costo.entity';
|
|||||||
BitacoraModule,
|
BitacoraModule,
|
||||||
MensajeModule,
|
MensajeModule,
|
||||||
CostoModule,
|
CostoModule,
|
||||||
|
ActiveDirectoryModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule { }
|
||||||
//IO
|
//IO
|
||||||
|
|||||||
@@ -25,16 +25,17 @@ export class DetalleServicioController {
|
|||||||
return this.detalleServicioService.findByDateRange(data.desde, data.hasta);
|
return this.detalleServicioService.findByDateRange(data.desde, data.hasta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Get('totales-por-periodo')
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
async getTotalesPorPeriodo(
|
@Get('totales-por-periodo')
|
||||||
@Query('periodoInicio') periodoInicio?: string,
|
async getTotalesPorPeriodo(
|
||||||
@Query('periodoFin') periodoFin?: string,
|
@Query('periodoInicio') periodoInicio?: string,
|
||||||
@Query('servicioId') servicioId?: string,
|
@Query('periodoFin') periodoFin?: string,
|
||||||
) {
|
@Query('servicioId') servicioId?: string,
|
||||||
const inicio = periodoInicio ? parseInt(periodoInicio) : undefined;
|
) {
|
||||||
const fin = periodoFin ? parseInt(periodoFin) : undefined;
|
const inicio = periodoInicio ? parseInt(periodoInicio) : undefined;
|
||||||
const servicio = servicioId ? parseInt(servicioId) : undefined;
|
const fin = periodoFin ? parseInt(periodoFin) : undefined;
|
||||||
return this.detalleServicioService.getTotalesPorServicioYPeriodo(inicio, fin, servicio);
|
const servicio = servicioId ? parseInt(servicioId) : undefined;
|
||||||
}
|
return this.detalleServicioService.getTotalesPorServicioYPeriodo(inicio, fin, servicio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export class EquipoService {
|
|||||||
.innerJoin('equipo.plataforma', 'p')
|
.innerJoin('equipo.plataforma', 'p')
|
||||||
.innerJoin('equipo.areaUbicacion', 'a')
|
.innerJoin('equipo.areaUbicacion', 'a')
|
||||||
.where('equipo.activo = 1')
|
.where('equipo.activo = 1')
|
||||||
.orderBy('equipo.ubicacion', 'ASC')
|
.orderBy('equipo.ubicacion + 0', 'ASC')
|
||||||
.getRawMany();
|
.getRawMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ export class EquipoService {
|
|||||||
return `equipo.id_equipo NOT IN ${subQuery}`;
|
return `equipo.id_equipo NOT IN ${subQuery}`;
|
||||||
})
|
})
|
||||||
|
|
||||||
.orderBy('equipo.ubicacion', 'ASC')
|
.orderBy('equipo.ubicacion + 0', 'ASC')
|
||||||
|
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -10,10 +10,11 @@ async function bootstrap() {
|
|||||||
app.useGlobalPipes(new ValidationPipe());
|
app.useGlobalPipes(new ValidationPipe());
|
||||||
|
|
||||||
app.enableCors(
|
app.enableCors(
|
||||||
// {
|
// {
|
||||||
// origin: configService.get<string>('Front_URL'),
|
// origin: configService.get<string>('Front_URL'),
|
||||||
// }
|
// }
|
||||||
);
|
);
|
||||||
|
app.enableShutdownHooks();
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
await app.listen(process.env.PORT ?? 3000);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
@@ -11,26 +11,33 @@ export class MesaController {
|
|||||||
constructor(private readonly mesaService: MesaService) { }
|
constructor(private readonly mesaService: MesaService) { }
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||||
@Get()
|
@Get()
|
||||||
async findAll() {
|
async findAll() {
|
||||||
return this.mesaService.findAll();
|
return this.mesaService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||||
@Get('activo')
|
@Get('activo')
|
||||||
async findAllActivo() {
|
async findAllActivo() {
|
||||||
return this.mesaService.findAllActivo();
|
return this.mesaService.findAllActivo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||||
@Get('uso')
|
@Get('uso')
|
||||||
async findActiveMesas() {
|
async findActiveMesas() {
|
||||||
return this.mesaService.findActiveMesas();
|
return this.mesaService.findActiveMesas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||||
|
@Get('usoWhitout')
|
||||||
|
async findActiveMesasWhitoudOcupado() {
|
||||||
|
return this.mesaService.findActiveMesasWhitoudOcupado();
|
||||||
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
@@ -42,7 +49,7 @@ export class MesaController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||||
@Patch(':id/activo')
|
@Patch(':id/activo')
|
||||||
toggleActivo(@Param('id') id: number) {
|
toggleActivo(@Param('id') id: number) {
|
||||||
return this.mesaService.toggleActivo(+id);
|
return this.mesaService.toggleActivo(+id);
|
||||||
|
|||||||
@@ -142,4 +142,27 @@ export class MesaService {
|
|||||||
.orderBy('mesa.id_mesa', 'ASC')
|
.orderBy('mesa.id_mesa', 'ASC')
|
||||||
.getRawMany();
|
.getRawMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findActiveMesasWhitoudOcupado() {
|
||||||
|
return this.mesaRepository
|
||||||
|
.createQueryBuilder('mesa')
|
||||||
|
.select([
|
||||||
|
'mesa.id_mesa AS id_mesa',
|
||||||
|
])
|
||||||
|
.where('mesa.activo = 1')
|
||||||
|
.andWhere(`
|
||||||
|
NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM bitacora_mesa bm
|
||||||
|
WHERE bm.id_mesa = mesa.id_mesa
|
||||||
|
AND TIMESTAMPDIFF(
|
||||||
|
SECOND,
|
||||||
|
NOW(),
|
||||||
|
DATE_ADD(bm.tiempo_entrada, INTERVAL bm.tiempo_asignado MINUTE)
|
||||||
|
) > 0
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
.orderBy('mesa.id_mesa', 'ASC')
|
||||||
|
.getRawMany();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export class PeriodoController {
|
|||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Post()
|
@Post()
|
||||||
create(@Body() data: CreatePeriodoDto) {
|
create(@Body() data: CreatePeriodoDto) {
|
||||||
return this.periodoService.create(data);
|
return this.periodoService.create(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,21 +39,21 @@ export class PeriodoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Get('compare')
|
@Get('compare')
|
||||||
compare(
|
compare(
|
||||||
@Query('p1') p1: number,
|
@Query('p1') p1: number,
|
||||||
@Query('p2') p2: number,
|
@Query('p2') p2: number,
|
||||||
) {
|
) {
|
||||||
return this.periodoService.comparePeriodos(p1, p2);
|
return this.periodoService.comparePeriodos(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('range')
|
||||||
|
getRange(
|
||||||
|
@Query('p1') p1: number,
|
||||||
|
@Query('p2') p2: number,
|
||||||
|
) {
|
||||||
|
return this.periodoService.getPeriodosEnRango(p1, p2);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('range')
|
|
||||||
getRange(
|
|
||||||
@Query('p1') p1: number,
|
|
||||||
@Query('p2') p2: number,
|
|
||||||
) {
|
|
||||||
return this.periodoService.getPeriodosEnRango(p1, p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class PeriodoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findAll() {
|
async findAll() {
|
||||||
return this.periodoRepository.find({order:{'id_periodo':"DESC"}});
|
return this.periodoRepository.find({ order: { 'id_periodo': "DESC" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPeriodoActivo(): Promise<Periodo> {
|
async getPeriodoActivo(): Promise<Periodo> {
|
||||||
@@ -71,48 +71,48 @@ export class PeriodoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async comparePeriodos(id1: number, id2: number) {
|
async comparePeriodos(id1: number, id2: number) {
|
||||||
const periodo1 = await this.periodoRepository.findOne({
|
const periodo1 = await this.periodoRepository.findOne({
|
||||||
where: { id_periodo: id1 },
|
where: { id_periodo: id1 },
|
||||||
});
|
});
|
||||||
|
|
||||||
const periodo2 = await this.periodoRepository.findOne({
|
const periodo2 = await this.periodoRepository.findOne({
|
||||||
where: { id_periodo: id2 },
|
where: { id_periodo: id2 },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!periodo1 || !periodo2) {
|
if (!periodo1 || !periodo2) {
|
||||||
throw new NotFoundException('Uno de los periodos no existe');
|
throw new NotFoundException('Uno de los periodos no existe');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
periodo1: {
|
||||||
|
id: periodo1.id_periodo,
|
||||||
|
nombre: periodo1.semestre,
|
||||||
|
fecha_inicio: periodo1.fecha_inicio_servicio,
|
||||||
|
fecha_fin: periodo1.fecha_fin_servicio,
|
||||||
|
},
|
||||||
|
periodo2: {
|
||||||
|
id: periodo2.id_periodo,
|
||||||
|
nombre: periodo2.semestre,
|
||||||
|
fecha_inicio: periodo2.fecha_inicio_servicio,
|
||||||
|
fecha_fin: periodo2.fecha_fin_servicio,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
async getPeriodosEnRango(id1: number, id2: number) {
|
||||||
periodo1: {
|
const min = Math.min(id1, id2);
|
||||||
id: periodo1.id_periodo,
|
const max = Math.max(id1, id2);
|
||||||
nombre: periodo1.semestre,
|
|
||||||
fecha_inicio: periodo1.fecha_inicio_servicio,
|
|
||||||
fecha_fin: periodo1.fecha_fin_servicio,
|
|
||||||
},
|
|
||||||
periodo2: {
|
|
||||||
id: periodo2.id_periodo,
|
|
||||||
nombre: periodo2.semestre,
|
|
||||||
fecha_inicio: periodo2.fecha_inicio_servicio,
|
|
||||||
fecha_fin: periodo2.fecha_fin_servicio,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPeriodosEnRango(id1: number, id2: number) {
|
return this.periodoRepository.find({
|
||||||
const min = Math.min(id1, id2);
|
where: {
|
||||||
const max = Math.max(id1, id2);
|
id_periodo: Between(min, max),
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
id_periodo: 'ASC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return this.periodoRepository.find({
|
|
||||||
where: {
|
|
||||||
id_periodo: Between(min, max),
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
id_periodo: 'ASC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,12 @@ export class ProgramaEquipoController {
|
|||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Get('programas/:id')
|
@Get('programas/:id')
|
||||||
findAllProgramByNumber(@Param('id') id: number) {
|
async findAllProgramByNumber(@Param('id') id: number) {
|
||||||
return this.programaEquipoService.findAllProgramByNumber(+id);
|
return await this.programaEquipoService.findAllProgramByNumber(+id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
|
|
||||||
@Get('ubicacion/:id')
|
@Get('ubicacion/:id')
|
||||||
findAllProgramByUbicacion(@Param('id') id: string) {
|
findAllProgramByUbicacion(@Param('id') id: string) {
|
||||||
return this.programaEquipoService.findAllProgramByUbication(id);
|
return this.programaEquipoService.findAllProgramByUbication(id);
|
||||||
@@ -28,7 +27,7 @@ export class ProgramaEquipoController {
|
|||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
findOne(@Param('id') id: string) {
|
findOne(@Param('id') id: number) {
|
||||||
return this.programaEquipoService.findOne(id);
|
return this.programaEquipoService.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ export class ProgramaEquipoService {
|
|||||||
return this.programaEquipoRepository.find();
|
return this.programaEquipoRepository.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(ubicacion: string) {
|
async findOne(id_equipo: number) {
|
||||||
const equipo = await this.programaEquipoRepository.find({
|
const equipo = await this.programaEquipoRepository.find({
|
||||||
where: { equipo: { ubicacion } },
|
where: { equipo: { id_equipo } },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (equipo.length === 0) {
|
if (equipo.length === 0) {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
UseGuards,
|
UseGuards,
|
||||||
Res,
|
Res,
|
||||||
Req,
|
Req,
|
||||||
|
Param,
|
||||||
|
Patch,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import type { Response } from 'express';
|
import type { Response } from 'express';
|
||||||
import { UserService } from './user.service';
|
import { UserService } from './user.service';
|
||||||
@@ -19,6 +21,13 @@ import { Role } from 'src/role.enum';
|
|||||||
export class UserController {
|
export class UserController {
|
||||||
constructor(private readonly userService: UserService) { }
|
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)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Get()
|
@Get()
|
||||||
@@ -28,11 +37,18 @@ export class UserController {
|
|||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Get('/perfil')
|
@Get('/perfil')
|
||||||
async getAllPerfil() {
|
async getAllPerfil() {
|
||||||
return this.userService.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()
|
@Post()
|
||||||
async Login(@Body() data: Login, @Res() res: Response) {
|
async Login(@Body() data: Login, @Res() res: Response) {
|
||||||
return this.userService.Login(data, res);
|
return this.userService.Login(data, res);
|
||||||
|
|||||||
@@ -19,7 +19,36 @@ export class UserService {
|
|||||||
@InjectRepository(Perfil)
|
@InjectRepository(Perfil)
|
||||||
private perfilRepository: Repository<Perfil>,
|
private perfilRepository: Repository<Perfil>,
|
||||||
private jwtService: JwtService,
|
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> {
|
async findOneByNameandPassword(data: Login): Promise<User> {
|
||||||
const { usuario, password } = data;
|
const { usuario, password } = data;
|
||||||
@@ -28,6 +57,10 @@ export class UserService {
|
|||||||
where: { usuario, password },
|
where: { usuario, password },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (user?.activo === 0) {
|
||||||
|
throw new NotFoundException(`El usuario se encuentra desactivado`);
|
||||||
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new NotFoundException(`El usuario o la contraseña es incorrecta`);
|
throw new NotFoundException(`El usuario o la contraseña es incorrecta`);
|
||||||
}
|
}
|
||||||
@@ -111,7 +144,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAll() {
|
async getAll() {
|
||||||
return this.userRepository.find();
|
return this.userRepository.find({select:['id_usuario','nombre','usuario','perfil','activo','password']});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllPerfil() {
|
async getAllPerfil() {
|
||||||
|
|||||||
Reference in New Issue
Block a user