Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d0217b445b |
Generated
+558
-348
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,6 @@
|
|||||||
"@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",
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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` };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
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 {}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export class CreateActiveDirectoryDto {}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from '@nestjs/mapped-types';
|
|
||||||
import { CreateActiveDirectoryDto } from './create-active-directory.dto';
|
|
||||||
|
|
||||||
export class UpdateActiveDirectoryDto extends PartialType(CreateActiveDirectoryDto) {}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export class ActiveDirectory {}
|
|
||||||
@@ -32,7 +32,8 @@ export class AlumnoController {
|
|||||||
return this.alumnoService.findOneWhitSancion(+id);
|
return this.alumnoService.findOneWhitSancion(+id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//delete guard to use in cedetec
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@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,26 +54,9 @@ 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'],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const now = new Date();
|
return { student, alusancion };
|
||||||
|
|
||||||
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 }> {
|
||||||
|
|||||||
+1
-10
@@ -43,7 +43,6 @@ 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';
|
||||||
|
|
||||||
@@ -86,13 +85,6 @@ 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,
|
||||||
@@ -115,10 +107,9 @@ 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,17 +25,16 @@ export class DetalleServicioController {
|
|||||||
return this.detalleServicioService.findByDateRange(data.desde, data.hasta);
|
return this.detalleServicioService.findByDateRange(data.desde, data.hasta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Get('totales-por-periodo')
|
||||||
@Get('totales-por-periodo')
|
async getTotalesPorPeriodo(
|
||||||
async getTotalesPorPeriodo(
|
|
||||||
@Query('periodoInicio') periodoInicio?: string,
|
@Query('periodoInicio') periodoInicio?: string,
|
||||||
@Query('periodoFin') periodoFin?: string,
|
@Query('periodoFin') periodoFin?: string,
|
||||||
@Query('servicioId') servicioId?: string,
|
@Query('servicioId') servicioId?: string,
|
||||||
) {
|
) {
|
||||||
const inicio = periodoInicio ? parseInt(periodoInicio) : undefined;
|
const inicio = periodoInicio ? parseInt(periodoInicio) : undefined;
|
||||||
const fin = periodoFin ? parseInt(periodoFin) : undefined;
|
const fin = periodoFin ? parseInt(periodoFin) : undefined;
|
||||||
const servicio = servicioId ? parseInt(servicioId) : undefined;
|
const servicio = servicioId ? parseInt(servicioId) : undefined;
|
||||||
return this.detalleServicioService.getTotalesPorServicioYPeriodo(inicio, fin, servicio);
|
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 + 0', 'ASC')
|
.orderBy('equipo.ubicacion', '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 + 0', 'ASC')
|
.orderBy('equipo.ubicacion', 'ASC')
|
||||||
|
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -13,8 +13,7 @@ async function bootstrap() {
|
|||||||
// {
|
// {
|
||||||
// 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,33 +11,26 @@ 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')
|
||||||
@@ -49,7 +42,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,27 +142,4 @@ 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query, UseGuards } from '@nestjs/common';
|
||||||
import { PeriodoService } from './periodo.service';
|
import { PeriodoService } from './periodo.service';
|
||||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||||
@@ -37,4 +37,23 @@ export class PeriodoController {
|
|||||||
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
|
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
|
||||||
return this.periodoService.modifiedDate(data, id_periodo)
|
return this.periodoService.modifiedDate(data, id_periodo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
|
@Get('compare')
|
||||||
|
compare(
|
||||||
|
@Query('p1') p1: number,
|
||||||
|
@Query('p2') p2: number,
|
||||||
|
) {
|
||||||
|
return this.periodoService.comparePeriodos(p1, p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('range')
|
||||||
|
getRange(
|
||||||
|
@Query('p1') p1: number,
|
||||||
|
@Query('p2') p2: number,
|
||||||
|
) {
|
||||||
|
return this.periodoService.getPeriodosEnRango(p1, p2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Periodo } from './entities/periodo.entity';
|
import { Periodo } from './entities/periodo.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { Between, Repository } from 'typeorm';
|
||||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -69,4 +69,50 @@ export class PeriodoService {
|
|||||||
async modifiedDate(data: ModifiedDateDto, id_periodo) {
|
async modifiedDate(data: ModifiedDateDto, id_periodo) {
|
||||||
return this.periodoRepository.update(id_periodo, data)
|
return this.periodoRepository.update(id_periodo, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async comparePeriodos(id1: number, id2: number) {
|
||||||
|
const periodo1 = await this.periodoRepository.findOne({
|
||||||
|
where: { id_periodo: id1 },
|
||||||
|
});
|
||||||
|
|
||||||
|
const periodo2 = await this.periodoRepository.findOne({
|
||||||
|
where: { id_periodo: id2 },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!periodo1 || !periodo2) {
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getPeriodosEnRango(id1: number, id2: number) {
|
||||||
|
const min = Math.min(id1, id2);
|
||||||
|
const max = Math.max(id1, id2);
|
||||||
|
|
||||||
|
return this.periodoRepository.find({
|
||||||
|
where: {
|
||||||
|
id_periodo: Between(min, max),
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
id_periodo: 'ASC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ 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')
|
||||||
async findAllProgramByNumber(@Param('id') id: number) {
|
findAllProgramByNumber(@Param('id') id: number) {
|
||||||
return await this.programaEquipoService.findAllProgramByNumber(+id);
|
return 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);
|
||||||
@@ -27,7 +28,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: number) {
|
findOne(@Param('id') id: string) {
|
||||||
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(id_equipo: number) {
|
async findOne(ubicacion: string) {
|
||||||
const equipo = await this.programaEquipoRepository.find({
|
const equipo = await this.programaEquipoRepository.find({
|
||||||
where: { equipo: { id_equipo } },
|
where: { equipo: { ubicacion } },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (equipo.length === 0) {
|
if (equipo.length === 0) {
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ 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';
|
||||||
@@ -21,13 +19,6 @@ 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()
|
||||||
@@ -42,13 +33,6 @@ export class UserController {
|
|||||||
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,36 +19,7 @@ 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;
|
||||||
@@ -57,10 +28,6 @@ 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`);
|
||||||
}
|
}
|
||||||
@@ -144,7 +111,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAll() {
|
async getAll() {
|
||||||
return this.userRepository.find({select:['id_usuario','nombre','usuario','perfil','activo','password']});
|
return this.userRepository.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllPerfil() {
|
async getAllPerfil() {
|
||||||
|
|||||||
Reference in New Issue
Block a user