Compare commits
67 Commits
55c7ff8c02
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 4db486a8c6 | |||
| a1028b1cd8 | |||
| 07c1e1651a | |||
| 61fb91c7ec | |||
| 46ad8e88ce | |||
| 94641514ad | |||
| f334a0f9e2 | |||
| ac009d0688 | |||
| d0217b445b | |||
| 8b6186ff6e | |||
| 0d9e82f527 | |||
| 0b984f1a9e | |||
| 65bdb47c00 | |||
| 73e0ede7ed | |||
| 645c4ed6c1 | |||
| 5b5d552b0c | |||
| 4bd78578a7 | |||
| 5f5295dcb4 | |||
| 70e1e2d7bf | |||
| 2071be5a65 | |||
| b154d1fb93 | |||
| 0cf4fc5d3c | |||
| 9d07eab337 | |||
| af2052111c | |||
| 3bb95a3d50 | |||
| e28d534edf | |||
| 81ad881d6a | |||
| 54d878c145 | |||
| 04290f4097 | |||
| 22431dd73e | |||
| 9ddff920fb | |||
| a42cfb6247 | |||
| c4c14f8520 | |||
| 9c07860840 | |||
| 53ab8c5c27 | |||
| 0323c93ca3 | |||
| 8aa0eab353 | |||
| a96187a10f | |||
| 07e7160242 | |||
| 1584e16a46 | |||
| a0e4e78c4d | |||
| 9e836fb947 | |||
| 8f65896390 | |||
| deff4def56 | |||
| 45e91e5c3f | |||
| f653b0e24a | |||
| 46d98e2a6b | |||
| eb52f9829f | |||
| c63f59593c | |||
| b6594bd879 | |||
| f9a12d5c0d | |||
| 18b869d681 | |||
| 472bfebb7a | |||
| 1aef1e8b0f | |||
| 59d3ec1490 | |||
| 8c69da9999 | |||
| 075a637b8d | |||
| 12498ac6eb | |||
| fe0b7762e7 | |||
| 384830aea7 | |||
| 99f76c9412 | |||
| 8a82b49a5c | |||
| 23acb847c3 | |||
| cba8ec6d0e | |||
| 6055c6ae76 | |||
| 296b1d9121 | |||
| ece4c9a2f2 |
Generated
+1583
-1920
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -30,12 +30,13 @@
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.2",
|
||||
"ldapts": "^8.1.7",
|
||||
"mysql2": "^3.14.4",
|
||||
"passport": "^0.7.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.26"
|
||||
"typeorm": "^0.3.28"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
|
||||
@@ -2,33 +2,40 @@ import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { OperationsService } from './operations.services';
|
||||
import { chargePrintDto } from './dto/operations.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('operations')
|
||||
export class OperationsController {
|
||||
constructor(private readonly operationsService: OperationsService) {}
|
||||
constructor(private readonly operationsService: OperationsService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.PCPUMA, Role.SERVICIO_SOCIAL)
|
||||
@Post('impressions')
|
||||
async chargePrint(@Body() data: chargePrintDto, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.chargePrint(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.PCPUMA, Role.SERVICIO_SOCIAL)
|
||||
@Post('receipt')
|
||||
async addCredit(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.addCredit(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.SERVICIO_SOCIAL, Role.ATENCION_USUARIOS)
|
||||
@Post('registration')
|
||||
async addReceiptInscription(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.addReceiptInscription(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.SERVICIO_SOCIAL, Role.ATENCION_USUARIOS)
|
||||
@Post('time')
|
||||
async addTime(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
|
||||
@@ -23,7 +23,7 @@ export class OperationsService {
|
||||
private readonly userService: UserService,
|
||||
private readonly reciboService: ReciboService,
|
||||
private readonly periodoService: PeriodoService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async chargePrint(data: chargePrintDto, id_usuario: number) {
|
||||
const { monto, id_cuenta, id_servicio, numero_hojas } = data;
|
||||
@@ -41,6 +41,7 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
const detalleData = {
|
||||
servicio: id_servicio,
|
||||
@@ -49,6 +50,7 @@ export class OperationsService {
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
numero_hojas,
|
||||
periodo,
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(
|
||||
@@ -92,6 +94,7 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
try {
|
||||
const detalleData = {
|
||||
@@ -100,6 +103,7 @@ export class OperationsService {
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
periodo
|
||||
};
|
||||
|
||||
await this.reciboService.create(detalleData, queryRunner.manager);
|
||||
@@ -119,6 +123,12 @@ export class OperationsService {
|
||||
async addTime(data, id_usuario: number) {
|
||||
const { monto, id_cuenta, idPlataforma, folio_recibo, fecha_recibo } = data;
|
||||
|
||||
const ticket = await this.reciboService.findOne(folio_recibo);
|
||||
|
||||
if (ticket) {
|
||||
throw new BadRequestException('Ticket ya existente');
|
||||
}
|
||||
|
||||
const studentRegister = await this.alumnoInscritoService.findRegister(
|
||||
id_cuenta,
|
||||
idPlataforma,
|
||||
@@ -130,6 +140,7 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
try {
|
||||
const detalleRecibo = {
|
||||
@@ -148,6 +159,7 @@ export class OperationsService {
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
periodo,
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(
|
||||
@@ -182,6 +194,12 @@ export class OperationsService {
|
||||
realizo_pago,
|
||||
} = data;
|
||||
|
||||
const ticket = await this.reciboService.findOne(folio_recibo);
|
||||
|
||||
if (ticket) {
|
||||
throw new BadRequestException('Ticket ya existente');
|
||||
}
|
||||
|
||||
await this.alumnoInscritoService.findNotRegister(id_cuenta, id_plataforma);
|
||||
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
@@ -190,27 +208,30 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
const detalleRecibo = {
|
||||
folio_recibo,
|
||||
user,
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
};
|
||||
|
||||
const detalleData = {
|
||||
servicio: 4,
|
||||
user,
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
periodo,
|
||||
};
|
||||
|
||||
try {
|
||||
const detalleRecibo = {
|
||||
folio_recibo,
|
||||
user,
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
};
|
||||
|
||||
await this.reciboService.create(detalleRecibo, queryRunner.manager);
|
||||
|
||||
const detalleData = {
|
||||
servicio: 4,
|
||||
user,
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(
|
||||
const ola = await this.detalleServicioService.Create(
|
||||
detalleData,
|
||||
queryRunner.manager,
|
||||
);
|
||||
|
||||
@@ -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 {}
|
||||
@@ -9,24 +9,37 @@ import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('student')
|
||||
export class AlumnoController {
|
||||
constructor(private readonly alumnoService: AlumnoService) {}
|
||||
constructor(private readonly alumnoService: AlumnoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
async find(){
|
||||
async find() {
|
||||
return this.alumnoService.findAll()
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
}
|
||||
|
||||
//@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA)
|
||||
@Get(':id')
|
||||
findOneWhitSancion(@Param('id') id: number) {
|
||||
return this.alumnoService.findOneWhitSancion(+id);
|
||||
}
|
||||
|
||||
//delete guard to use in cedetec
|
||||
@Get('sancion/:id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.alumnoService.findOne(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/create')
|
||||
async newStudent(@Body() createStudentDto: CreateStudentDto) {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { AlumnoService } from './student.service';
|
||||
import { AlumnoController } from './student.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { AlumnoSancionModule } from 'src/alumno_sancion/alumno_sancion.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Alumno, Carrera])],
|
||||
imports: [TypeOrmModule.forFeature([Alumno, Carrera]),
|
||||
forwardRef(() => AlumnoSancionModule),
|
||||
],
|
||||
controllers: [AlumnoController],
|
||||
providers: [AlumnoService],
|
||||
exports: [AlumnoService],
|
||||
})
|
||||
export class AlumnoModule {}
|
||||
export class AlumnoModule { }
|
||||
//IO
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { ConflictException, ForbiddenException, forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { AlumnoSancionService } from 'src/alumno_sancion/alumno_sancion.service';
|
||||
import { ExceptionsHandler } from '@nestjs/core/exceptions/exceptions-handler';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoService {
|
||||
@@ -12,7 +14,10 @@ export class AlumnoService {
|
||||
private readonly studentRepository: Repository<Alumno>,
|
||||
@InjectRepository(Carrera)
|
||||
private readonly carreraRepository: Repository<Carrera>,
|
||||
) {}
|
||||
|
||||
@Inject(forwardRef(() => AlumnoSancionService))
|
||||
private readonly alumnoSancionService: AlumnoSancionService,
|
||||
) { }
|
||||
|
||||
async findAll(): Promise<Alumno[]> {
|
||||
return this.studentRepository.find({
|
||||
@@ -22,12 +27,21 @@ export class AlumnoService {
|
||||
|
||||
async create(data: CreateStudentDto): Promise<Alumno> {
|
||||
const { id_carrera, ...rest } = data;
|
||||
|
||||
const carrera = await this.carreraRepository.findOne({
|
||||
where: { id_carrera: data.id_carrera },
|
||||
});
|
||||
|
||||
if (!carrera) {
|
||||
throw new NotFoundException(`Carrera not found`);
|
||||
}
|
||||
|
||||
const currenStudent = await this.studentRepository.findOne({ where: { id_cuenta: data.id_cuenta } })
|
||||
|
||||
if (currenStudent) {
|
||||
throw new ConflictException('El usuario ya existe')
|
||||
}
|
||||
|
||||
const createStudent = { ...rest, carrera, fecha_registro: new Date() };
|
||||
|
||||
const student = this.studentRepository.create(createStudent);
|
||||
@@ -47,6 +61,25 @@ export class AlumnoService {
|
||||
return student;
|
||||
}
|
||||
|
||||
async findOneWhitSancion(id_cuenta: number): Promise<Alumno> {
|
||||
const student = await this.studentRepository.findOne({
|
||||
where: { id_cuenta },
|
||||
select: { id_cuenta: true, nombre: true, credito: true },
|
||||
});
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Numero de cuenta ${id_cuenta} no existente`);
|
||||
}
|
||||
|
||||
const sancion = await this.alumnoSancionService.findSancion(id_cuenta)
|
||||
|
||||
if (sancion) {
|
||||
throw new ForbiddenException('El usuario se encuentra sancionado')
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
async findOneByName(nombre: string): Promise<Alumno> {
|
||||
const student = await this.studentRepository.findOne({
|
||||
where: { nombre },
|
||||
|
||||
@@ -1,57 +1,84 @@
|
||||
import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param, Patch, UseGuards, ParseIntPipe } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import {
|
||||
AddTimeDto,
|
||||
CreateAlumnoInscritoDto,
|
||||
} from './dto/create-alumno_inscrito.dto';
|
||||
import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('alumno-inscrito')
|
||||
export class AlumnoInscritoController {
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) {}
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Post()
|
||||
async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
return this.alumnoInscritoService.createWhitoutPay(dto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findAll();
|
||||
}
|
||||
|
||||
// @Post('/tiempo')
|
||||
// async addTime(@Body() body: AddTimeDto) {
|
||||
// const { idCuenta, idPlataforma, tiempoExtra } = body;
|
||||
// return this.alumnoInscritoService.(
|
||||
// idCuenta,
|
||||
// idPlataforma,
|
||||
// tiempoExtra,
|
||||
// );
|
||||
// }
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get("/inscritos/:idPeriodo")
|
||||
async findAllInscritos(@Param('idPeriodo') idPeriodo: number) {
|
||||
return this.alumnoInscritoService.findAllInscritos(idPeriodo);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/plataforma')
|
||||
async findAllPlataforma() {
|
||||
return this.alumnoInscritoService.findAllPlataforma();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get(':id_cuenta')
|
||||
async findByIdWhitoud(
|
||||
@Param('id_cuenta') id_cuenta: number,
|
||||
): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findByIdWhitoud(id_cuenta);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get(':id_cuenta/sancion')
|
||||
async findById(
|
||||
@Param('id_cuenta') id_cuenta: number,
|
||||
): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findById(id_cuenta);
|
||||
}
|
||||
//pruebas borrar
|
||||
@Patch('platica/:idCuenta/:idPeriodo/:idPlataforma')
|
||||
marcarPlatica(
|
||||
@Param('idCuenta') idCuenta: number,
|
||||
@Param('idPeriodo') idPeriodo: number,
|
||||
@Param('idPlataforma') idPlataforma: number,
|
||||
|
||||
@Get('inscritos/periodo/:inicio/:fin')
|
||||
findByPeriodo(
|
||||
@Param('inicio', ParseIntPipe) inicio: number,
|
||||
@Param('fin', ParseIntPipe) fin: number,
|
||||
) {
|
||||
return this.alumnoInscritoService.marcarPlatica(
|
||||
idCuenta,
|
||||
idPeriodo,
|
||||
idPlataforma,
|
||||
);
|
||||
return this.alumnoInscritoService.findAllInscritosByRango(inicio, fin, 'periodo');
|
||||
}
|
||||
|
||||
@Get('inscritos/anio/:inicio/:fin')
|
||||
findByAnio(
|
||||
@Param('inicio', ParseIntPipe) inicio: number,
|
||||
@Param('fin', ParseIntPipe) fin: number,
|
||||
) {
|
||||
return this.alumnoInscritoService.findAllInscritosByRango(inicio, fin, 'anio');
|
||||
}
|
||||
|
||||
@Get('inscritos/mes/:anio')
|
||||
findByMes(
|
||||
@Param('anio', ParseIntPipe) anio: number,
|
||||
) {
|
||||
return this.alumnoInscritoService.findAllInscritosByRango(anio, 0, 'mes');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import { AlumnoInscritoController } from './alumno_inscrito.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnoInscrito, Plataforma } from './entities/alumno_inscrito.entity';
|
||||
import { BitacoraMesa } from 'src/bitacora_mesa/entities/bitacora_mesa.entity';
|
||||
import { PeriodoModule } from 'src/periodo/periodo.module';
|
||||
import { AlumnoSancionModule } from 'src/alumno_sancion/alumno_sancion.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito,Plataforma,BitacoraMesa]),PeriodoModule],
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito, Plataforma, BitacoraMesa]), PeriodoModule,
|
||||
forwardRef(() => AlumnoSancionModule),],
|
||||
controllers: [AlumnoInscritoController],
|
||||
providers: [AlumnoInscritoService],
|
||||
exports:[AlumnoInscritoService]
|
||||
exports: [AlumnoInscritoService]
|
||||
})
|
||||
export class AlumnoInscritoModule {}
|
||||
export class AlumnoInscritoModule { }
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
@@ -8,6 +11,7 @@ import { AlumnoInscrito, Plataforma } from './entities/alumno_inscrito.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { PeriodoService } from 'src/periodo/periodo.service';
|
||||
import { AlumnoSancionService } from 'src/alumno_sancion/alumno_sancion.service';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoInscritoService {
|
||||
@@ -17,7 +21,10 @@ export class AlumnoInscritoService {
|
||||
@InjectRepository(Plataforma)
|
||||
private readonly plataformaRepo: Repository<Plataforma>,
|
||||
private readonly periodoService: PeriodoService,
|
||||
) {}
|
||||
|
||||
@Inject(forwardRef(() => AlumnoSancionService))
|
||||
private readonly alumnoSancionService: AlumnoSancionService,
|
||||
) { }
|
||||
|
||||
async createWhitoutPay(
|
||||
dto: CreateAlumnoInscritoDto,
|
||||
@@ -54,6 +61,26 @@ export class AlumnoInscritoService {
|
||||
take: 100,
|
||||
});
|
||||
}
|
||||
async findAllInscritos(idPeriodo: number) {
|
||||
return this.alumnoInscritoRepo
|
||||
.createQueryBuilder('inscritos')
|
||||
.innerJoin('inscritos.alumno', 'alumno')
|
||||
.innerJoin('alumno.carrera', 'carrera')
|
||||
.innerJoin('inscritos.plataforma', 'plataforma')
|
||||
.innerJoin('inscritos.periodo', 'periodo')
|
||||
.where('periodo.id_periodo = :idPeriodo', { idPeriodo })
|
||||
.select([
|
||||
'carrera.carrera AS carrera',
|
||||
'periodo.semestre AS semestre',
|
||||
'plataforma.nombre AS profesor',
|
||||
'COUNT(DISTINCT CASE WHEN alumno.genero IN (\'F\', \'Femenino\') THEN alumno.id_cuenta END) AS femenino',
|
||||
'COUNT(DISTINCT CASE WHEN alumno.genero IN (\'M\', \'Masculino\') THEN alumno.id_cuenta END) AS masculino',
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total'
|
||||
])
|
||||
.groupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
async findAllPlataforma() {
|
||||
return this.plataformaRepo.find();
|
||||
@@ -64,6 +91,12 @@ export class AlumnoInscritoService {
|
||||
}
|
||||
|
||||
async findById(id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
const sancion = await this.alumnoSancionService.findSancion(id_cuenta)
|
||||
|
||||
if (sancion) {
|
||||
throw new ForbiddenException('El usuario se encuentra sancionado')
|
||||
}
|
||||
|
||||
const students = await this.alumnoInscritoRepo
|
||||
.createQueryBuilder('ai')
|
||||
.leftJoinAndSelect('ai.alumno', 'alumno')
|
||||
@@ -74,7 +107,25 @@ export class AlumnoInscritoService {
|
||||
.getMany();
|
||||
|
||||
if (students.length === 0) {
|
||||
throw new NotFoundException('Estudiante no Registrado');
|
||||
throw new NotFoundException('Estudiante no inscrito en el periodo actual');
|
||||
}
|
||||
|
||||
return students;
|
||||
}
|
||||
|
||||
async findByIdWhitoud(id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
|
||||
const students = await this.alumnoInscritoRepo
|
||||
.createQueryBuilder('ai')
|
||||
.leftJoinAndSelect('ai.alumno', 'alumno')
|
||||
.leftJoinAndSelect('ai.periodo', 'periodo')
|
||||
.leftJoinAndSelect('ai.plataforma', 'plataforma')
|
||||
.where('alumno.id_cuenta = :id_cuenta', { id_cuenta })
|
||||
.andWhere("periodo.activo = b'1'")
|
||||
.getMany();
|
||||
|
||||
if (students.length === 0) {
|
||||
throw new NotFoundException('Estudiante no inscrito en el periodo actual');
|
||||
}
|
||||
|
||||
return students;
|
||||
@@ -143,7 +194,7 @@ export class AlumnoInscritoService {
|
||||
}
|
||||
}
|
||||
|
||||
//Borrar
|
||||
|
||||
async addTimeBorrar(
|
||||
idCuenta: number,
|
||||
idPlataforma: number,
|
||||
@@ -180,4 +231,119 @@ export class AlumnoInscritoService {
|
||||
const create = repo.create(data);
|
||||
return await repo.save(create);
|
||||
}
|
||||
async findAllInscritosByRango(
|
||||
inicio: number,
|
||||
fin: number,
|
||||
tipo: 'periodo' | 'mes' | 'anio',
|
||||
) {
|
||||
const qb = this.alumnoInscritoRepo
|
||||
.createQueryBuilder('inscritos')
|
||||
.innerJoin('inscritos.alumno', 'alumno')
|
||||
.innerJoin('alumno.carrera', 'carrera')
|
||||
.innerJoin('inscritos.plataforma', 'plataforma')
|
||||
.innerJoin('inscritos.periodo', 'periodo');
|
||||
|
||||
// ============================
|
||||
// 🟢 PERIODO
|
||||
// ============================
|
||||
if (tipo === 'periodo') {
|
||||
qb.where('periodo.id_periodo BETWEEN :inicio AND :fin', {
|
||||
inicio,
|
||||
fin,
|
||||
});
|
||||
|
||||
qb.select([
|
||||
'periodo.id_periodo AS id_periodo',
|
||||
'periodo.semestre AS semestre',
|
||||
'carrera.carrera AS carrera',
|
||||
'plataforma.nombre AS profesor',
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('F', 'Femenino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS femenino`,
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('M', 'Masculino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS masculino`,
|
||||
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total',
|
||||
]);
|
||||
|
||||
qb.groupBy('periodo.id_periodo')
|
||||
.addGroupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.orderBy('periodo.id_periodo', 'ASC');
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 🔵 AÑO
|
||||
// ============================
|
||||
else if (tipo === 'anio') {
|
||||
qb.where(
|
||||
'periodo.fecha_inicio_servicio BETWEEN :inicio AND :fin',
|
||||
{
|
||||
inicio: `${inicio}-01-01`,
|
||||
fin: `${fin}-12-31`,
|
||||
},
|
||||
);
|
||||
|
||||
qb.select([
|
||||
'YEAR(periodo.fecha_inicio_servicio) AS semestre',
|
||||
'carrera.carrera AS carrera',
|
||||
'plataforma.nombre AS profesor',
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('F', 'Femenino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS femenino`,
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('M', 'Masculino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS masculino`,
|
||||
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total',
|
||||
]);
|
||||
|
||||
qb.groupBy('YEAR(periodo.fecha_inicio_servicio)')
|
||||
.addGroupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.orderBy('YEAR(periodo.fecha_inicio_servicio)', 'ASC')
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 🟡 MES (UN SOLO AÑO)
|
||||
// ============================
|
||||
else if (tipo === 'mes') {
|
||||
qb.where('YEAR(periodo.fecha_inicio_servicio) = :anio', {
|
||||
anio: inicio, // aquí "inicio" es el año
|
||||
});
|
||||
|
||||
qb.select([
|
||||
'MONTH(periodo.fecha_inicio_servicio) AS semestre',
|
||||
'carrera.carrera AS carrera',
|
||||
'plataforma.nombre AS profesor',
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('F', 'Femenino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS femenino`,
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('M', 'Masculino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS masculino`,
|
||||
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total',
|
||||
]);
|
||||
qb.groupBy('MONTH(periodo.fecha_inicio_servicio)')
|
||||
.addGroupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.orderBy('YEAR(periodo.fecha_inicio_servicio)', 'ASC')
|
||||
}
|
||||
|
||||
return qb.getRawMany();
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,6 @@ export class AlumnoInscrito {
|
||||
@OneToMany(() => BitacoraMesa, (bitacoraMesa) => bitacoraMesa.alumno_inscrito)
|
||||
bitacoras_mesa: BitacoraMesa[];
|
||||
|
||||
@OneToMany(() => Bitacora, (bitacora) => bitacora.equipo)
|
||||
@OneToMany(() => Bitacora, (bitacora) => bitacora.alumno_inscrito)
|
||||
bitacoras: Bitacora[];
|
||||
}
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/common';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('alumno-sancion')
|
||||
export class AlumnoSancionController {
|
||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) {}
|
||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
async create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||
return this.alumnoSancionService.create(createAlumnoSancionDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findbyStudent(@Param('id') id: number) {
|
||||
return this.alumnoSancionService.findbyStudent(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Delete(':id_cuenta')
|
||||
async deleteSancionesAlumno(@Param('id_cuenta') id_cuenta: number) {
|
||||
return this.alumnoSancionService.removeByStudent(+id_cuenta);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
import { AlumnoSancionController } from './alumno_sancion.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
@@ -7,16 +7,16 @@ import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||
import { AlumnoModule } from 'src/alumno/student.module';
|
||||
import { SancionModule } from 'src/sancion/sancion.module';
|
||||
import { AlumnoService } from 'src/alumno/student.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([AlumnoSancion, Alumno, Sancion]),
|
||||
AlumnoModule,
|
||||
forwardRef(() => AlumnoModule),
|
||||
SancionModule,
|
||||
],
|
||||
controllers: [AlumnoSancionController],
|
||||
providers: [AlumnoSancionService],
|
||||
exports: [AlumnoSancionService]
|
||||
})
|
||||
export class AlumnoSancionModule {}
|
||||
//IO
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -11,9 +11,12 @@ export class AlumnoSancionService {
|
||||
constructor(
|
||||
@InjectRepository(AlumnoSancion)
|
||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||
|
||||
@Inject(forwardRef(() => AlumnoService))
|
||||
private readonly alumnoService: AlumnoService,
|
||||
|
||||
private readonly sancionService: SancionService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async create(createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||
const { id_sancion, id_cuenta } = createAlumnoSancionDto;
|
||||
@@ -34,17 +37,43 @@ export class AlumnoSancionService {
|
||||
return await this.alumnosancionRepository.save(alumnosancion);
|
||||
}
|
||||
|
||||
async findbyStudent(id_cuenta: number) {
|
||||
const student = await this.alumnoService.findOne(id_cuenta);
|
||||
|
||||
async findSancion(id_cuenta: number): Promise<boolean> {
|
||||
const alusancion = await this.alumnosancionRepository.find({
|
||||
where: { alumno: { id_cuenta } },
|
||||
});
|
||||
|
||||
if (alusancion.length === 0) {
|
||||
throw new NotFoundException(`El estudiante no cuenta con una sanción activa`);
|
||||
return false;
|
||||
}
|
||||
return { student, alusancion };
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async findbyStudent(id_cuenta: number) {
|
||||
const student = await this.alumnoService.findOne(id_cuenta);
|
||||
|
||||
const alusancion = await this.alumnosancionRepository.find({
|
||||
where: { alumno: { id_cuenta } },
|
||||
relations: ['sancion'],
|
||||
});
|
||||
|
||||
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 }> {
|
||||
|
||||
+15
-2
@@ -43,6 +43,9 @@ import { BitacoraModule } from './bitacora/bitacora.module';
|
||||
import { Bitacora } from './bitacora/entities/bitacora.entity';
|
||||
import { MensajeModule } from './mensaje/mensaje.module';
|
||||
import { Mensaje } from './mensaje/entities/mensaje.entity';
|
||||
import { ActiveDirectoryModule } from './active-directory/active-directory.module';
|
||||
import { CostoModule } from './costo/costo.module';
|
||||
import { Costo } from './costo/entities/costo.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -79,9 +82,17 @@ import { Mensaje } from './mensaje/entities/mensaje.entity';
|
||||
ProgramaEquipo,
|
||||
BitacoraMesa,
|
||||
Bitacora,
|
||||
Mensaje
|
||||
Mensaje,
|
||||
Costo,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
|
||||
extra: {
|
||||
connectionLimit: 5,
|
||||
waitForConnections: true,
|
||||
idleTimeout: 60000,
|
||||
connectTimeout: 10000,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
UserModule,
|
||||
@@ -103,9 +114,11 @@ import { Mensaje } from './mensaje/entities/mensaje.entity';
|
||||
BitacoraMesaModule,
|
||||
BitacoraModule,
|
||||
MensajeModule,
|
||||
CostoModule,
|
||||
ActiveDirectoryModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
export class AppModule { }
|
||||
//IO
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { AreaUbicacionService } from './area_ubicacion.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('area-ubicacion')
|
||||
export class AreaUbicacionController {
|
||||
constructor(private readonly areaUbicacionService: AreaUbicacionService) {}
|
||||
constructor(private readonly areaUbicacionService: AreaUbicacionService) { }
|
||||
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.areaUbicacionService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.areaUbicacionService.findOne(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/programs/:id')
|
||||
findProgramsByArea(@Param('id')id:number){
|
||||
findProgramsByArea(@Param('id') id: number) {
|
||||
return this.areaUbicacionService.findProgramsByArea(+id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,38 @@
|
||||
import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param, Patch, UseGuards } from '@nestjs/common';
|
||||
import { BitacoraService } from './bitacora.service';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
import { BitacoraAlumnoDto, CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('bitacora')
|
||||
export class BitacoraController {
|
||||
constructor(private readonly bitacoraService: BitacoraService) {}
|
||||
constructor(private readonly bitacoraService: BitacoraService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Post()
|
||||
assignment(@Body() createBitacoraDto: CreateBitacoraDto) {
|
||||
return this.bitacoraService.assignment(createBitacoraDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/cuenta/:id')
|
||||
findOneByAcount(@Param('id') id: string) {
|
||||
return this.bitacoraService.findOneByAcount(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/equipo/:id')
|
||||
findOneByMachine(@Param('id') id: string) {
|
||||
return this.bitacoraService.findOneByMachine(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Patch('cancelar/:id')
|
||||
cancelationByMachine(
|
||||
@Param('id') id: number,
|
||||
@@ -29,8 +41,32 @@ export class BitacoraController {
|
||||
return this.bitacoraService.cancelation(id, tiempo_asignado);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bitacoraService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('equipos-por-dia')
|
||||
async obtenerEquipos(
|
||||
@Body() dto: BitacoraAlumnoDto
|
||||
) {
|
||||
return this.bitacoraService.obtenerEquiposPorAlumnoYFecha(
|
||||
dto.numero_cuenta,
|
||||
dto.fecha,
|
||||
);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('equipos-por-equipo')
|
||||
async equiposPorEquipo(
|
||||
@Body() dto: EquiposPorEquipoDto,
|
||||
) {
|
||||
return this.bitacoraService.equiposPorEquipo(dto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
import { CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Bitacora } from './entities/bitacora.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -9,7 +9,7 @@ export class BitacoraService {
|
||||
constructor(
|
||||
@InjectRepository(Bitacora)
|
||||
private readonly bitacoraRepository: Repository<Bitacora>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
assignment(dto: CreateBitacoraDto) {
|
||||
const bitacora = this.bitacoraRepository.create({
|
||||
@@ -91,4 +91,64 @@ export class BitacoraService {
|
||||
|
||||
return { message: 'Tiempo cancelado' };
|
||||
}
|
||||
|
||||
async obtenerEquiposPorAlumnoYFecha(numeroCuenta: string, fecha: string) {
|
||||
|
||||
const fechaInicio = new Date(`${fecha}T00:00:00`);
|
||||
const fechaFin = new Date(`${fecha}T23:59:59`);
|
||||
|
||||
return await this.bitacoraRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.innerJoinAndSelect('bitacora.equipo', 'equipo')
|
||||
.innerJoin('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.innerJoin('alumnoInscrito.alumno', 'alumno')
|
||||
.where('alumno.id_cuenta = :numeroCuenta', { numeroCuenta })
|
||||
.andWhere('bitacora.tiempo_entrada BETWEEN :inicio AND :fin', {
|
||||
inicio: fechaInicio,
|
||||
fin: fechaFin,
|
||||
})
|
||||
.select([
|
||||
'bitacora.tiempo_entrada',
|
||||
'bitacora.tiempo_asignado',
|
||||
'equipo.ubicacion',
|
||||
'equipo.nombre_equipo'
|
||||
])
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async equiposPorEquipo(dto: EquiposPorEquipoDto) {
|
||||
const { id_equipo, fecha } = dto;
|
||||
|
||||
const inicio = new Date(`${fecha}T00:00:00`);
|
||||
const fin = new Date(`${fecha}T23:59:59`);
|
||||
|
||||
const registros = await this.bitacoraRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.innerJoin('bitacora.equipo', 'equipo')
|
||||
.innerJoin('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.innerJoin('alumnoInscrito.alumno', 'alumno')
|
||||
.where('equipo.id_equipo = :id_equipo', { id_equipo })
|
||||
.andWhere('bitacora.tiempo_entrada BETWEEN :inicio AND :fin', {
|
||||
inicio,
|
||||
fin,
|
||||
})
|
||||
.select([
|
||||
'bitacora.tiempo_entrada AS tiempo_entrada',
|
||||
'bitacora.tiempo_asignado AS tiempo_asignado',
|
||||
'alumno.id_cuenta AS id_cuenta'
|
||||
])
|
||||
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
||||
.getRawMany();
|
||||
|
||||
return registros.map(reg => ({
|
||||
hora_entrada: reg.tiempo_entrada,
|
||||
min_utilizados: reg.tiempo_asignado,
|
||||
hora_salida: new Date(
|
||||
new Date(reg.tiempo_entrada).getTime() +
|
||||
reg.tiempo_asignado * 60000
|
||||
),
|
||||
cuenta_asociada: reg.id_cuenta
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,32 @@
|
||||
import { IsInt, IsOptional, IsString } from "class-validator";
|
||||
import { IsDateString, IsInt, IsNumber, IsNumberString, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateBitacoraDto {
|
||||
@IsInt()
|
||||
tiempo_asignado: number;
|
||||
@IsInt()
|
||||
tiempo_asignado: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ubicacion?: string;
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ubicacion?: string;
|
||||
|
||||
@IsInt()
|
||||
id_equipo: number;
|
||||
@IsInt()
|
||||
id_equipo: number;
|
||||
|
||||
@IsInt()
|
||||
id_alumno_inscrito: number;
|
||||
}
|
||||
@IsInt()
|
||||
id_alumno_inscrito: number;
|
||||
}
|
||||
|
||||
export class BitacoraAlumnoDto {
|
||||
@IsNumberString()
|
||||
numero_cuenta: string;
|
||||
|
||||
@IsDateString()
|
||||
fecha: string;
|
||||
}
|
||||
|
||||
export class EquiposPorEquipoDto {
|
||||
@IsNumber()
|
||||
id_equipo: number;
|
||||
|
||||
@IsString()
|
||||
fecha: string;
|
||||
}
|
||||
|
||||
@@ -5,40 +5,63 @@ import {
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { BitacoraMesaService } from './bitacora_mesa.service';
|
||||
import { CreateBitacoraMesaDto } from './dto/create-bitacora_mesa.dto';
|
||||
import { CreateBitacoraMesaDto, FindByDate } from './dto/create-bitacora_mesa.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('bitacora-mesa')
|
||||
export class BitacoraMesaController {
|
||||
constructor(private readonly bitacoraMesaService: BitacoraMesaService) {}
|
||||
constructor(private readonly bitacoraMesaService: BitacoraMesaService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Post()
|
||||
assignment(@Body() createBitacoraMesaDto: CreateBitacoraMesaDto) {
|
||||
return this.bitacoraMesaService.assignment(createBitacoraMesaDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bitacoraMesaService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.bitacoraMesaService.findOne(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/cuenta/:id_cuenta')
|
||||
findByCuenta(@Param('id_cuenta') id_cuenta: string) {
|
||||
return this.bitacoraMesaService.findByCuenta(+id_cuenta);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/table/:id_mesa')
|
||||
findByTable(@Param('id_mesa') id_mesa: number) {
|
||||
return this.bitacoraMesaService.findByTable(id_mesa);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/date')
|
||||
findByDate(@Body() data: FindByDate) {
|
||||
return this.bitacoraMesaService.findByDate(data.date);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Patch('cancelar/:id')
|
||||
cancelationByMachine(
|
||||
@Param('id') id: number,
|
||||
@@ -46,4 +69,12 @@ export class BitacoraMesaController {
|
||||
) {
|
||||
return this.bitacoraMesaService.cancelation(id, tiempo_asignado);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('mesas-por-dia')
|
||||
mesasPorDia(@Body() body: { fecha: string }) {
|
||||
return this.bitacoraMesaService.mesasPorFecha(body.fecha);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateBitacoraMesaDto } from './dto/create-bitacora_mesa.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { BitacoraMesa } from './entities/bitacora_mesa.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Repository, Between } from 'typeorm';
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
|
||||
@@ -11,46 +11,46 @@ export class BitacoraMesaService {
|
||||
constructor(
|
||||
@InjectRepository(BitacoraMesa)
|
||||
private readonly bitacoraMesaRepository: Repository<BitacoraMesa>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async assignment(dto: CreateBitacoraMesaDto) {
|
||||
|
||||
// VALIDAR: el alumno ya tiene una mesa activa
|
||||
const alumnoConMesa = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', {
|
||||
id_alumno_inscrito: dto.id_alumno_inscrito,
|
||||
})
|
||||
.andWhere(
|
||||
`TIMESTAMPDIFF(
|
||||
async assignment(dto: CreateBitacoraMesaDto) {
|
||||
|
||||
const alumnoConMesa = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', {
|
||||
id_alumno_inscrito: dto.id_alumno_inscrito,
|
||||
})
|
||||
.andWhere(
|
||||
`TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)
|
||||
) > 0`,
|
||||
)
|
||||
.getOne();
|
||||
)
|
||||
.getOne();
|
||||
|
||||
if (alumnoConMesa) {
|
||||
throw new BadRequestException(
|
||||
'El alumno ya tiene una mesa asignada',
|
||||
);
|
||||
if (alumnoConMesa) {
|
||||
throw new BadRequestException(
|
||||
'El alumno ya tiene una mesa asignada',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const bitacora = this.bitacoraMesaRepository.create({
|
||||
tiempo_entrada: new Date(),
|
||||
tiempo_asignado: dto.tiempo_asignado,
|
||||
mesa: { id_mesa: dto.id_mesa },
|
||||
alumno_inscrito: { id_alumno_inscrito: dto.id_alumno_inscrito },
|
||||
});
|
||||
|
||||
return this.bitacoraMesaRepository.save(bitacora);
|
||||
}
|
||||
|
||||
|
||||
const bitacora = this.bitacoraMesaRepository.create({
|
||||
tiempo_entrada: new Date(),
|
||||
tiempo_asignado: dto.tiempo_asignado,
|
||||
mesa: { id_mesa: dto.id_mesa },
|
||||
alumno_inscrito: { id_alumno_inscrito: dto.id_alumno_inscrito },
|
||||
});
|
||||
|
||||
return this.bitacoraMesaRepository.save(bitacora);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.bitacoraMesaRepository.find({
|
||||
relations: ['mesa', 'alumno_inscrito'],
|
||||
take: 100,
|
||||
order: { id_bitacora_mesa: "DESC" }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,13 +75,13 @@ export class BitacoraMesaService {
|
||||
.getOne();
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException('alumno sin mesa');
|
||||
throw new NotFoundException('Alumno sin mesa');
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
async findByTable(id_mesa: number) {
|
||||
async findByTable(id_mesa: number) {
|
||||
const student = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
@@ -104,6 +104,18 @@ export class BitacoraMesaService {
|
||||
return student;
|
||||
}
|
||||
|
||||
async findByDate(date) {
|
||||
const start = new Date(`${date}T00:00:00`);
|
||||
const end = new Date(`${date}T23:59:59`);
|
||||
|
||||
return this.bitacoraMesaRepository.find({
|
||||
where: {
|
||||
tiempo_entrada: Between(start, end),
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async cancelation(id_bitacora_mesa: number, nuevoTiempo: number) {
|
||||
const bitacora = await this.bitacoraMesaRepository.findOne({
|
||||
where: { id_bitacora_mesa },
|
||||
@@ -119,4 +131,33 @@ export class BitacoraMesaService {
|
||||
|
||||
return { message: 'Tiempo cancelado' };
|
||||
}
|
||||
|
||||
async mesasPorFecha(fecha: string) {
|
||||
const inicio = new Date(`${fecha}T00:00:00`);
|
||||
const fin = new Date(`${fecha}T23:59:59`);
|
||||
|
||||
const registros = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.innerJoinAndSelect('bitacora.mesa', 'mesa')
|
||||
.innerJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.innerJoinAndSelect('alumnoInscrito.alumno', 'alumno')
|
||||
.where('bitacora.tiempo_entrada BETWEEN :inicio AND :fin', {
|
||||
inicio,
|
||||
fin,
|
||||
})
|
||||
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
||||
.getMany();
|
||||
|
||||
return registros.map(reg => ({
|
||||
no_mesa: reg.mesa?.id_mesa,
|
||||
no_cuenta: reg.alumno_inscrito?.alumno?.id_cuenta,
|
||||
hora_entrada: reg.tiempo_entrada,
|
||||
tiempo_asignado: reg.tiempo_asignado,
|
||||
hora_salida: new Date(
|
||||
new Date(reg.tiempo_entrada).getTime() +
|
||||
reg.tiempo_asignado * 60000
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsInt, IsPositive } from 'class-validator';
|
||||
import { IsDateString, IsInt, IsPositive } from 'class-validator';
|
||||
|
||||
export class CreateBitacoraMesaDto {
|
||||
@IsInt()
|
||||
@@ -12,4 +12,9 @@ export class CreateBitacoraMesaDto {
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
id_alumno_inscrito: number;
|
||||
}
|
||||
|
||||
export class FindByDate {
|
||||
@IsDateString()
|
||||
date: string;
|
||||
}
|
||||
@@ -19,7 +19,6 @@ export class BitacoraMesa {
|
||||
@Column({ name: 'tiempo_entrada', type: 'datetime' })
|
||||
tiempo_entrada: Date;
|
||||
|
||||
|
||||
@ManyToOne(() => Mesa)
|
||||
@JoinColumn({ name: 'id_mesa' })
|
||||
mesa: Mesa;
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { CarreraService } from './carrera.service';
|
||||
import { Carrera } from './entities/carrera.entity';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('carrera')
|
||||
export class CarreraController {
|
||||
constructor(private readonly carreraService: CarreraService) {}
|
||||
constructor(private readonly carreraService: CarreraService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get()
|
||||
findAll(): Promise<Carrera[]> {
|
||||
return this.carreraService.findAll();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CostoController } from './costo.controller';
|
||||
import { CostoService } from './costo.service';
|
||||
|
||||
describe('CostoController', () => {
|
||||
let controller: CostoController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [CostoController],
|
||||
providers: [CostoService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<CostoController>(CostoController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { CostoService } from './costo.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Role } from 'src/role.enum';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
|
||||
@Controller('costo')
|
||||
export class CostoController {
|
||||
constructor(private readonly costoService: CostoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.costoService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/:id_servicio')
|
||||
find(@Param('id_servicio') id_servicio: number) {
|
||||
return this.costoService.find(id_servicio);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CostoService } from './costo.service';
|
||||
import { CostoController } from './costo.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Costo } from './entities/costo.entity';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Costo])],
|
||||
controllers: [CostoController],
|
||||
providers: [CostoService],
|
||||
})
|
||||
export class CostoModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CostoService } from './costo.service';
|
||||
|
||||
describe('CostoService', () => {
|
||||
let service: CostoService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CostoService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CostoService>(CostoService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Costo } from './entities/costo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class CostoService {
|
||||
constructor(@InjectRepository(Costo)
|
||||
private readonly CostoRepository: Repository<Costo>) {}
|
||||
|
||||
findAll() {
|
||||
return this.CostoRepository.find();
|
||||
}
|
||||
|
||||
find(id_servicio: number) {
|
||||
return this.CostoRepository.find({ where: { id_servicio } });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateCostoDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateCostoDto } from './create-costo.dto';
|
||||
|
||||
export class UpdateCostoDto extends PartialType(CreateCostoDto) {}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
|
||||
|
||||
@Entity('costo')
|
||||
export class Costo {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id_costo: number;
|
||||
|
||||
@Column('decimal', { precision: 10, scale: 2 })
|
||||
costo: number;
|
||||
|
||||
@Column({ type: 'int' })
|
||||
id_servicio: number;
|
||||
|
||||
@Column({
|
||||
type: 'timestamp',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
fecha_registro: Date;
|
||||
|
||||
}
|
||||
@@ -1,20 +1,41 @@
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
|
||||
import { DetalleServicioService } from './detalle_servicio.service';
|
||||
import { FindReciboByRangeDto } from 'src/recibo/dto/create-recibo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
|
||||
@Controller('detalle-servicio')
|
||||
export class DetalleServicioController {
|
||||
constructor(private readonly detalleServicioService: DetalleServicioService) {}
|
||||
constructor(private readonly detalleServicioService: DetalleServicioService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll(){
|
||||
findAll() {
|
||||
return this.detalleServicioService.findAll()
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('rango')
|
||||
async findByDateRange(@Body() data: FindReciboByRangeDto) {
|
||||
return this.detalleServicioService.findByDateRange(data.desde, data.hasta);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('totales-por-periodo')
|
||||
async getTotalesPorPeriodo(
|
||||
@Query('periodoInicio') periodoInicio?: string,
|
||||
@Query('periodoFin') periodoFin?: string,
|
||||
@Query('servicioId') servicioId?: string,
|
||||
) {
|
||||
const inicio = periodoInicio ? parseInt(periodoInicio) : undefined;
|
||||
const fin = periodoFin ? parseInt(periodoFin) : undefined;
|
||||
const servicio = servicioId ? parseInt(servicioId) : undefined;
|
||||
return this.detalleServicioService.getTotalesPorServicioYPeriodo(inicio, fin, servicio);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export class DetalleServicioService {
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.detalleServicioRepository.find({ take: 100 });
|
||||
return this.detalleServicioRepository.find({ take: 100 ,order:{fecha_operacion:'DESC'}});
|
||||
}
|
||||
|
||||
async findByDateRange(desde: string, hasta: string) {
|
||||
@@ -35,4 +35,42 @@ export class DetalleServicioService {
|
||||
.addGroupBy('servicio.servicio')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
async getTotalesPorServicioYPeriodo(periodoInicio?: number, periodoFin?: number, servicioId?: number) {
|
||||
const query = this.detalleServicioRepository
|
||||
.createQueryBuilder('ds')
|
||||
.select('s.servicio', 'nombre_servicio')
|
||||
.addSelect('p.semestre', 'periodo')
|
||||
.addSelect('p.id_periodo', 'id_periodo')
|
||||
.addSelect('SUM(ds.monto)', 'monto_total')
|
||||
.innerJoin('ds.servicio', 's')
|
||||
.innerJoin('ds.periodo', 'p');
|
||||
|
||||
if (periodoInicio && periodoFin) {
|
||||
query.andWhere('p.id_periodo BETWEEN :inicio AND :fin', { inicio: periodoInicio, fin: periodoFin });
|
||||
} else if (periodoInicio) {
|
||||
query.andWhere('p.id_periodo >= :inicio', { inicio: periodoInicio });
|
||||
} else if (periodoFin) {
|
||||
query.andWhere('p.id_periodo <= :fin', { fin: periodoFin });
|
||||
}
|
||||
|
||||
if (servicioId) {
|
||||
query.andWhere('s.id_servicio = :servicioId', { servicioId });
|
||||
}
|
||||
|
||||
const resultados = await query
|
||||
.groupBy('s.id_servicio')
|
||||
.addGroupBy('p.id_periodo')
|
||||
.orderBy('p.id_periodo')
|
||||
.addOrderBy('s.servicio')
|
||||
.getRawMany();
|
||||
|
||||
return resultados.map(item => ({
|
||||
nombre_servicio: item.nombre_servicio,
|
||||
periodo: item.periodo,
|
||||
monto_total: parseFloat(item.monto_total) || 0,
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
//IO
|
||||
@@ -1,27 +1,35 @@
|
||||
import { IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
import { IsBoolean, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateEquipoDto {
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_area_ubicacion: number;
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_area_ubicacion: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
id_equipo: number;
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
id_equipo: number;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_plataforma: number;
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_plataforma: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
ip: string;
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
ip: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nombre_equipo: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nombre_equipo: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
ubicacion: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
ubicacion: string;
|
||||
}
|
||||
|
||||
export class UpdateAreaEquiposDto {
|
||||
@IsInt()
|
||||
id_area_ubicacion: number;
|
||||
|
||||
@IsBoolean()
|
||||
activo: boolean;
|
||||
}
|
||||
|
||||
@@ -1,55 +1,92 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||
import { CreateEquipoDto, UpdateAreaEquiposDto } from './dto/create-equipo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('equipo')
|
||||
export class EquipoController {
|
||||
constructor(private readonly equipoService: EquipoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Get()
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
findAll(): Promise<Equipo[]> {
|
||||
return this.equipoService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/active')
|
||||
findActive() {
|
||||
return this.equipoService.findActive();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/disable')
|
||||
findDisable() {
|
||||
return this.equipoService.findDisable();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/student/:id')
|
||||
findOnlyUsable(@Param('id') id: number): Promise<Equipo[]> {
|
||||
return this.equipoService.findOnlyUsable(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/busy')
|
||||
findOnlyBusy(): Promise<Equipo[]> {
|
||||
return this.equipoService.findOnlyBusy();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string): Promise<Equipo> {
|
||||
return this.equipoService.findOne(id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
create(@Body() equipo: CreateEquipoDto) {
|
||||
return this.equipoService.create(equipo);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch()
|
||||
update(@Body() equipo: CreateEquipoDto) {
|
||||
return this.equipoService.update(equipo);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Patch(':id/activo')
|
||||
toggleActivo(@Param('id') id: number) {
|
||||
return this.equipoService.toggleActivo(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Patch('actualizar-area')
|
||||
actualizarPorArea(
|
||||
@Body() updateAreaEquiposDto: UpdateAreaEquiposDto,
|
||||
) {
|
||||
const { id_area_ubicacion, activo } = updateAreaEquiposDto;
|
||||
|
||||
return this.equipoService.actualizarEquiposPorArea(
|
||||
id_area_ubicacion,
|
||||
activo,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
//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();
|
||||
|
||||
@@ -204,5 +204,21 @@ export class EquipoService {
|
||||
activo: nuevoActivo,
|
||||
};
|
||||
}
|
||||
|
||||
async actualizarEquiposPorArea(
|
||||
id_area_ubicacion: number,
|
||||
activo: boolean,
|
||||
) {
|
||||
const result = await this.equipoRepository.update(
|
||||
{ id_area_ubicacion },
|
||||
{ activo },
|
||||
);
|
||||
|
||||
return {
|
||||
message: 'Equipos actualizados correctamente',
|
||||
affected: result.affected,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
//IO
|
||||
|
||||
+5
-4
@@ -10,10 +10,11 @@ async function bootstrap() {
|
||||
app.useGlobalPipes(new ValidationPipe());
|
||||
|
||||
app.enableCors(
|
||||
// {
|
||||
// origin: configService.get<string>('Front_URL'),
|
||||
// }
|
||||
);
|
||||
// {
|
||||
// origin: configService.get<string>('Front_URL'),
|
||||
// }
|
||||
);
|
||||
app.enableShutdownHooks();
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { MensajeService } from './mensaje.service';
|
||||
import { CreateMensajeDto } from './dto/create-mensaje.dto';
|
||||
import { UpdateMensajeDto } from './dto/update-mensaje.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('mensaje')
|
||||
export class MensajeController {
|
||||
constructor(private readonly mensajeService: MensajeService) {}
|
||||
constructor(private readonly mensajeService: MensajeService) { }
|
||||
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Get() @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
findAll() {
|
||||
return this.mensajeService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.mensajeService.findOne(+id);
|
||||
|
||||
@@ -1,21 +1,45 @@
|
||||
import { Controller, Body, Patch, Param, Get } from '@nestjs/common';
|
||||
import { Controller, Body, Patch, Param, Get, UseGuards } from '@nestjs/common';
|
||||
import { MesaService } from './mesa.service';
|
||||
import { UpdateMesaDto } from './dto/update-mesa.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Role } from 'src/role.enum';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
|
||||
@Controller('mesa')
|
||||
export class MesaController {
|
||||
constructor(private readonly mesaService: MesaService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get()
|
||||
async findAll() {
|
||||
return this.mesaService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('activo')
|
||||
async findAllActivo() {
|
||||
return this.mesaService.findAllActivo();
|
||||
}
|
||||
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('uso')
|
||||
async 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)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch(':id')
|
||||
async updateActivo(
|
||||
@Param('id') id: number,
|
||||
@@ -24,6 +48,8 @@ export class MesaController {
|
||||
return this.mesaService.updateActivo(id, updateMesaDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Patch(':id/activo')
|
||||
toggleActivo(@Param('id') id: number) {
|
||||
return this.mesaService.toggleActivo(+id);
|
||||
|
||||
@@ -38,15 +38,42 @@ export class MesaService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
async findAll(): Promise<Mesa[]> {
|
||||
return await this.mesaRepository.find();
|
||||
}
|
||||
|
||||
|
||||
async findAllActivo(): Promise<Mesa[]> {
|
||||
return await this.mesaRepository.find({ where: { activo: true } });
|
||||
const mesas = await this.mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
|
||||
.andWhere('mesa.activo = true')
|
||||
|
||||
.andWhere((qb) => {
|
||||
const subQuery = qb
|
||||
.subQuery()
|
||||
.select('bitacora_mesa.id_mesa')
|
||||
.from('bitacora_mesa', 'bitacora_mesa')
|
||||
.where(
|
||||
`TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bitacora_mesa.tiempo_entrada, INTERVAL bitacora_mesa.tiempo_asignado MINUTE)
|
||||
) > 0`,
|
||||
)
|
||||
.getQuery();
|
||||
|
||||
return `mesa.id_mesa NOT IN ${subQuery}`;
|
||||
})
|
||||
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
|
||||
.getMany();
|
||||
|
||||
if (!mesas.length) {
|
||||
throw new NotFoundException('No usable table found');
|
||||
}
|
||||
|
||||
return mesas;
|
||||
}
|
||||
|
||||
async updateActivo(id: number, updateMesaDto: UpdateMesaDto) {
|
||||
@@ -92,4 +119,50 @@ export class MesaService {
|
||||
activo: nuevoActivo,
|
||||
};
|
||||
}
|
||||
|
||||
findActiveMesas() {
|
||||
return this.mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
.select([
|
||||
'mesa.id_mesa AS id_mesa',
|
||||
`
|
||||
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
|
||||
) AS ocupado
|
||||
`,
|
||||
])
|
||||
.where('mesa.activo = 1')
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,3 +21,13 @@ export class CreatePeriodoDto {
|
||||
@IsBoolean()
|
||||
activo?: boolean;
|
||||
}
|
||||
|
||||
export class ModifiedDateDto {
|
||||
|
||||
@IsDateString()
|
||||
fecha_inicio_servicio: string;
|
||||
|
||||
@IsDateString()
|
||||
fecha_fin_servicio: string;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,59 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query, UseGuards } from '@nestjs/common';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('periodo')
|
||||
export class PeriodoController {
|
||||
constructor(private readonly periodoService:PeriodoService){}
|
||||
constructor(private readonly periodoService: PeriodoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll(){
|
||||
findAll() {
|
||||
return this.periodoService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
create(@Body() data: CreatePeriodoDto) {
|
||||
return this.periodoService.create(data);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Delete("/:id_periodo")
|
||||
delete(@Param("id_periodo") id_periodo: number) {
|
||||
return this.periodoService.delete(id_periodo)
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch("/date/:id_periodo")
|
||||
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
|
||||
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,21 +1,22 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Periodo } from './entities/periodo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Between, Repository } from 'typeorm';
|
||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PeriodoService {
|
||||
constructor(
|
||||
@InjectRepository(Periodo)
|
||||
private readonly periodoRepository: Repository<Periodo>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async findOne() {
|
||||
return this.periodoRepository.findOne({ where: {} });
|
||||
async findOne(semestre: string) {
|
||||
return this.periodoRepository.findOne({ where: { semestre } });
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return this.periodoRepository.find();
|
||||
return this.periodoRepository.find({ order: { 'id_periodo': "DESC" } });
|
||||
}
|
||||
|
||||
async getPeriodoActivo(): Promise<Periodo> {
|
||||
@@ -30,4 +31,88 @@ export class PeriodoService {
|
||||
|
||||
return periodo;
|
||||
}
|
||||
|
||||
async getPeriodoActivoWhitoutError(): Promise<Periodo | null> {
|
||||
const periodo = await this.periodoRepository.findOne({
|
||||
where: { activo: true },
|
||||
order: { id_periodo: 'DESC' },
|
||||
});
|
||||
|
||||
return periodo;
|
||||
}
|
||||
|
||||
async delete(id_periodo: number) {
|
||||
await this.periodoRepository.delete(id_periodo)
|
||||
}
|
||||
|
||||
async periodoDisable(id_periodo: number) {
|
||||
await this.periodoRepository.update(id_periodo, { activo: false })
|
||||
}
|
||||
|
||||
async create(data: CreatePeriodoDto) {
|
||||
const periodo = await this.findOne(data.semestre)
|
||||
|
||||
if (periodo) {
|
||||
throw new BadRequestException("El periodo ya existe")
|
||||
}
|
||||
|
||||
const periodoActive = await this.getPeriodoActivoWhitoutError();
|
||||
|
||||
if (periodoActive) {
|
||||
await this.periodoDisable(periodoActive.id_periodo)
|
||||
}
|
||||
|
||||
const create = this.periodoRepository.create(data)
|
||||
return this.periodoRepository.save(create)
|
||||
}
|
||||
|
||||
async modifiedDate(data: ModifiedDateDto, id_periodo) {
|
||||
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',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,28 +1,48 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||
import { ProgramaService } from './programa.service';
|
||||
import { UpdateProgramaDto } from './dto/update-programa.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('programa')
|
||||
export class ProgramaController {
|
||||
constructor(private readonly programaService: ProgramaService) {}
|
||||
constructor(private readonly programaService: ProgramaService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.programaService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.programaService.findOne(+id);
|
||||
}
|
||||
@Post()
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
create(@Body() body) {
|
||||
return this.programaService.create(body);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) {
|
||||
return this.programaService.update(+id, updateProgramaDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Delete(':id')
|
||||
delete(@Param('id') id:string){
|
||||
return this.programaService.delete(+id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ export class ProgramaService {
|
||||
await this.programaRepository.update(id, updateProgramaDto);
|
||||
return await this.findOne(id);
|
||||
}
|
||||
|
||||
async delete(id:number){
|
||||
return this.programaRepository.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,26 +1,38 @@
|
||||
import { Controller, Get, Body, Patch, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Body, Patch, Param, UseGuards } from '@nestjs/common';
|
||||
import { ProgramaEquipoService } from './programa_equipo.service';
|
||||
import { UpdateProgramaEquipoDto, UpdateProgramasSalaDto } from './dto/update-programa_equipo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('programa-equipo')
|
||||
export class ProgramaEquipoController {
|
||||
constructor(private readonly programaEquipoService: ProgramaEquipoService) {}
|
||||
constructor(private readonly programaEquipoService: ProgramaEquipoService) { }
|
||||
|
||||
@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)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('ubicacion/:id')
|
||||
findAllProgramByUbicacion(@Param('id') id: string) {
|
||||
return this.programaEquipoService.findAllProgramByUbication(id);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch('equipo/:id')
|
||||
updateMachine(
|
||||
@Param('id') id: string,
|
||||
@@ -32,6 +44,8 @@ export class ProgramaEquipoController {
|
||||
);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch('sala')
|
||||
updateBySala(@Body() dto: UpdateProgramasSalaDto) {
|
||||
return this.programaEquipoService.updateBySala(dto.sala, dto.programas);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -3,15 +3,20 @@ import {
|
||||
Post,
|
||||
Body,
|
||||
UseGuards,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { ReciboService } from './recibo.service';
|
||||
import { FindReciboByRangeDto } from './dto/create-recibo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('recibo')
|
||||
export class ReciboController {
|
||||
constructor(private readonly reciboService: ReciboService) {}
|
||||
constructor(private readonly reciboService: ReciboService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('rango')
|
||||
async findByDateRange(@Body() data: FindReciboByRangeDto) {
|
||||
return this.reciboService.findByDateRange(data.desde, data.hasta);
|
||||
|
||||
+6
-4
@@ -1,5 +1,7 @@
|
||||
|
||||
export enum Role {
|
||||
ADMINISTRADOR = 'ADMINISTRADOR',
|
||||
OPERADOR = 'OPERADOR',
|
||||
}
|
||||
ADMINISTRADOR = 1,
|
||||
ATENCION_USUARIOS = 2,
|
||||
SERVICIO_SOCIAL = 3,
|
||||
SUPER_ADMINISTRADOR = 4,
|
||||
PCPUMA = 5,
|
||||
}
|
||||
+2
-2
@@ -6,7 +6,7 @@ import { ROLES_KEY } from './roles.decorator';
|
||||
|
||||
@Injectable()
|
||||
export class RolesGuard implements CanActivate {
|
||||
constructor(private reflector: Reflector) {}
|
||||
constructor(private reflector: Reflector) { }
|
||||
|
||||
canActivate(context: ExecutionContext): boolean {
|
||||
const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
|
||||
@@ -17,6 +17,6 @@ export class RolesGuard implements CanActivate {
|
||||
return true;
|
||||
}
|
||||
const { user } = context.switchToHttp().getRequest();
|
||||
return requiredRoles.some((role) => user.role?.includes(role));
|
||||
return requiredRoles.some((role) => user.role === role);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { SancionService } from './sancion.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
@Controller('sancion')
|
||||
export class SancionController {
|
||||
constructor(private readonly sancionService: SancionService) {}
|
||||
constructor(private readonly sancionService: SancionService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
find() {
|
||||
return this.sancionService.find();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.sancionService.findOne(+id);
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ServicioService } from './servicio.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('servicio')
|
||||
export class ServicioController {
|
||||
constructor(private readonly servicioService: ServicioService) {}
|
||||
constructor(private readonly servicioService: ServicioService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.servicioService.findAll();
|
||||
|
||||
@@ -23,7 +23,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
if (!payload || !payload.id || !payload.usuario) {
|
||||
throw new ForbiddenException('Token inválido o corrupto');
|
||||
}
|
||||
console.log(payload)
|
||||
return { id: payload.id, usuario: payload.usuario,role:payload.role};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,29 +4,51 @@ import {
|
||||
Post,
|
||||
Body,
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
Req,
|
||||
Param,
|
||||
Patch,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { JwtAuthGuard } from './jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('user')
|
||||
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)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
async getAll() {
|
||||
return this.userService.getAll();
|
||||
}
|
||||
|
||||
@Get('/perfil')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@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);
|
||||
@@ -35,15 +57,18 @@ export class UserController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/validate-token')
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
return req.user.role;
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/create')
|
||||
async createUser(@Body() data: CreateUserDto) {
|
||||
return this.userService.create(data);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/changePassword')
|
||||
async changePassword(@Body() data: changePasswordDto, @Req() req) {
|
||||
const id_usuario = req.user.id;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
return {
|
||||
global: true,
|
||||
secret: configService.get('JWT_SECRET'),
|
||||
signOptions: { expiresIn: '1h' },
|
||||
signOptions: { expiresIn: '7h' },
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -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;
|
||||
@@ -27,9 +56,10 @@ export class UserService {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { usuario, password },
|
||||
});
|
||||
console.log(usuario);
|
||||
console.log(password);
|
||||
console.log(user);
|
||||
|
||||
if (user?.activo === 0) {
|
||||
throw new NotFoundException(`El usuario se encuentra desactivado`);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(`El usuario o la contraseña es incorrecta`);
|
||||
@@ -43,14 +73,14 @@ export class UserService {
|
||||
|
||||
const payload = {
|
||||
id: user.id_usuario,
|
||||
usuario: user.usuario,
|
||||
role: user.perfil.perfil,
|
||||
usuario: user.nombre,
|
||||
role: user.perfil.id_perfil,
|
||||
};
|
||||
const token = await this.jwtService.signAsync(payload);
|
||||
|
||||
res.cookie('token', token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production', // en dev desactívalo
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'strict',
|
||||
path: '/',
|
||||
});
|
||||
@@ -108,14 +138,13 @@ export class UserService {
|
||||
usuario: (await this.findOne(id_usuario)).usuario,
|
||||
password: data.password,
|
||||
});
|
||||
console.log(user);
|
||||
|
||||
user.password = data.newPassword;
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
|
||||
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