Compare commits
20 Commits
55c7ff8c02
...
a0e4e78c4d
| Author | SHA1 | Date | |
|---|---|---|---|
| a0e4e78c4d | |||
| deff4def56 | |||
| f653b0e24a | |||
| eb52f9829f | |||
| c63f59593c | |||
| f9a12d5c0d | |||
| 1aef1e8b0f | |||
| 59d3ec1490 | |||
| 8c69da9999 | |||
| 075a637b8d | |||
| 12498ac6eb | |||
| fe0b7762e7 | |||
| 384830aea7 | |||
| 99f76c9412 | |||
| 8a82b49a5c | |||
| 23acb847c3 | |||
| cba8ec6d0e | |||
| 6055c6ae76 | |||
| 296b1d9121 | |||
| ece4c9a2f2 |
Generated
+1502
-1629
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -35,7 +35,7 @@
|
||||
"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",
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -9,10 +9,10 @@ import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('student')
|
||||
export class AlumnoController {
|
||||
constructor(private readonly alumnoService: AlumnoService) {}
|
||||
constructor(private readonly alumnoService: AlumnoService) { }
|
||||
|
||||
@Get()
|
||||
async find(){
|
||||
async find() {
|
||||
return this.alumnoService.findAll()
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@ export class AlumnoController {
|
||||
|
||||
//@UseGuards(JwtAuthGuard)
|
||||
@Get(':id')
|
||||
findOneWhitSancion(@Param('id') id: number) {
|
||||
return this.alumnoService.findOneWhitSancion(+id);
|
||||
}
|
||||
|
||||
//@UseGuards(JwtAuthGuard)
|
||||
@Get('sancion/:id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.alumnoService.findOne(+id);
|
||||
}
|
||||
|
||||
@@ -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,14 +1,13 @@
|
||||
import { Controller, Get, Post, Body, Param, Patch } 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';
|
||||
|
||||
@Controller('alumno-inscrito')
|
||||
export class AlumnoInscritoController {
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) {}
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) { }
|
||||
|
||||
@Post()
|
||||
async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
@@ -20,6 +19,11 @@ export class AlumnoInscritoController {
|
||||
return this.alumnoInscritoService.findAll();
|
||||
}
|
||||
|
||||
@Get("/inscritos/:idPeriodo")
|
||||
async findAllInscritos(@Param('idPeriodo') idPeriodo: number) {
|
||||
return this.alumnoInscritoService.findAllInscritos(idPeriodo);
|
||||
}
|
||||
|
||||
// @Post('/tiempo')
|
||||
// async addTime(@Body() body: AddTimeDto) {
|
||||
// const { idCuenta, idPlataforma, tiempoExtra } = body;
|
||||
@@ -36,11 +40,19 @@ export class AlumnoInscritoController {
|
||||
}
|
||||
|
||||
@Get(':id_cuenta')
|
||||
async findByIdWhitoud(
|
||||
@Param('id_cuenta') id_cuenta: number,
|
||||
): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findByIdWhitoud(id_cuenta);
|
||||
}
|
||||
|
||||
@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(
|
||||
|
||||
@@ -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,
|
||||
@@ -55,6 +62,31 @@ export class AlumnoInscritoService {
|
||||
});
|
||||
}
|
||||
|
||||
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',
|
||||
'alumno.genero AS genero',
|
||||
'plataforma.nombre AS profesor',
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total'
|
||||
])
|
||||
|
||||
.groupBy('carrera.carrera')
|
||||
.addGroupBy('alumno.genero')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
async findAllPlataforma() {
|
||||
return this.plataformaRepo.find();
|
||||
}
|
||||
@@ -64,6 +96,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 +112,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;
|
||||
|
||||
@@ -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,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,6 +37,18 @@ export class AlumnoSancionService {
|
||||
return await this.alumnosancionRepository.save(alumnosancion);
|
||||
}
|
||||
|
||||
async findSancion(id_cuenta: number): Promise<boolean> {
|
||||
const alusancion = await this.alumnosancionRepository.find({
|
||||
where: { alumno: { id_cuenta } },
|
||||
});
|
||||
|
||||
if (alusancion.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async findbyStudent(id_cuenta: number) {
|
||||
const student = await this.alumnoService.findOne(id_cuenta);
|
||||
|
||||
|
||||
+5
-1
@@ -43,6 +43,8 @@ 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 { CostoModule } from './costo/costo.module';
|
||||
import { Costo } from './costo/entities/costo.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -79,7 +81,8 @@ import { Mensaje } from './mensaje/entities/mensaje.entity';
|
||||
ProgramaEquipo,
|
||||
BitacoraMesa,
|
||||
Bitacora,
|
||||
Mensaje
|
||||
Mensaje,
|
||||
Costo,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -103,6 +106,7 @@ import { Mensaje } from './mensaje/entities/mensaje.entity';
|
||||
BitacoraMesaModule,
|
||||
BitacoraModule,
|
||||
MensajeModule,
|
||||
CostoModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common';
|
||||
import { BitacoraService } from './bitacora.service';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
import { BitacoraAlumnoDto, CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto';
|
||||
|
||||
@Controller('bitacora')
|
||||
export class BitacoraController {
|
||||
constructor(private readonly bitacoraService: BitacoraService) {}
|
||||
constructor(private readonly bitacoraService: BitacoraService) { }
|
||||
|
||||
@Post()
|
||||
assignment(@Body() createBitacoraDto: CreateBitacoraDto) {
|
||||
@@ -33,4 +33,23 @@ export class BitacoraController {
|
||||
findAll() {
|
||||
return this.bitacoraService.findAll();
|
||||
}
|
||||
|
||||
|
||||
@Post('equipos-por-dia')
|
||||
async obtenerEquipos(
|
||||
@Body() dto: BitacoraAlumnoDto
|
||||
) {
|
||||
return this.bitacoraService.obtenerEquiposPorAlumnoYFecha(
|
||||
dto.numero_cuenta,
|
||||
dto.fecha,
|
||||
);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import {
|
||||
Delete,
|
||||
} 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';
|
||||
|
||||
@Controller('bitacora-mesa')
|
||||
export class BitacoraMesaController {
|
||||
constructor(private readonly bitacoraMesaService: BitacoraMesaService) {}
|
||||
constructor(private readonly bitacoraMesaService: BitacoraMesaService) { }
|
||||
|
||||
@Post()
|
||||
assignment(@Body() createBitacoraMesaDto: CreateBitacoraMesaDto) {
|
||||
@@ -39,6 +39,11 @@ export class BitacoraMesaController {
|
||||
return this.bitacoraMesaService.findByTable(id_mesa);
|
||||
}
|
||||
|
||||
@Post('/date')
|
||||
findByDate(@Body() data: FindByDate) {
|
||||
return this.bitacoraMesaService.findByDate(data.date);
|
||||
}
|
||||
|
||||
@Patch('cancelar/:id')
|
||||
cancelationByMachine(
|
||||
@Param('id') id: number,
|
||||
@@ -46,4 +51,10 @@ export class BitacoraMesaController {
|
||||
) {
|
||||
return this.bitacoraMesaService.cancelation(id, tiempo_asignado);
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
@@ -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,13 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { CostoService } from './costo.service';
|
||||
|
||||
@Controller('costo')
|
||||
export class CostoController {
|
||||
constructor(private readonly costoService: CostoService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.costoService.findAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,14 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,7 +1,7 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } 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';
|
||||
|
||||
@Controller('equipo')
|
||||
export class EquipoController {
|
||||
@@ -51,5 +51,18 @@ export class EquipoController {
|
||||
toggleActivo(@Param('id') id: number) {
|
||||
return this.equipoService.toggleActivo(+id);
|
||||
}
|
||||
|
||||
@Patch('actualizar-area')
|
||||
actualizarPorArea(
|
||||
@Body() updateAreaEquiposDto: UpdateAreaEquiposDto,
|
||||
) {
|
||||
const { id_area_ubicacion, activo } = updateAreaEquiposDto;
|
||||
|
||||
return this.equipoService.actualizarEquiposPorArea(
|
||||
id_area_ubicacion,
|
||||
activo,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
//IO
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,7 +15,12 @@ export class MesaController {
|
||||
async findAllActivo() {
|
||||
return this.mesaService.findAllActivo();
|
||||
}
|
||||
|
||||
|
||||
@Get('uso')
|
||||
async findActiveMesas() {
|
||||
return this.mesaService.findActiveMesas();
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async updateActivo(
|
||||
@Param('id') id: number,
|
||||
|
||||
@@ -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,27 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,28 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Put } from '@nestjs/common';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||
|
||||
@Controller('periodo')
|
||||
export class PeriodoController {
|
||||
constructor(private readonly periodoService:PeriodoService){}
|
||||
constructor(private readonly periodoService: PeriodoService) { }
|
||||
|
||||
@Get()
|
||||
findAll(){
|
||||
findAll() {
|
||||
return this.periodoService.findAll();
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() data: CreatePeriodoDto) {
|
||||
return this.periodoService.create(data);
|
||||
}
|
||||
|
||||
@Delete("/:id_periodo")
|
||||
delete(@Param("id_periodo") id_periodo: number) {
|
||||
return this.periodoService.delete(id_periodo)
|
||||
}
|
||||
|
||||
@Patch("/date/:id_periodo")
|
||||
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
|
||||
return this.periodoService.modifiedDate(data, id_periodo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
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 { 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() {
|
||||
@@ -30,4 +31,42 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { ProgramaService } from './programa.service';
|
||||
import { UpdateProgramaDto } from './dto/update-programa.dto';
|
||||
|
||||
@Controller('programa')
|
||||
export class ProgramaController {
|
||||
constructor(private readonly programaService: ProgramaService) {}
|
||||
constructor(private readonly programaService: ProgramaService) { }
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
@@ -15,7 +15,8 @@ export class ProgramaController {
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.programaService.findOne(+id);
|
||||
}
|
||||
@Post()
|
||||
|
||||
@Post()
|
||||
create(@Body() body) {
|
||||
return this.programaService.create(body);
|
||||
}
|
||||
@@ -25,4 +26,9 @@ export class ProgramaController {
|
||||
return this.programaService.update(+id, updateProgramaDto);
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export class UserController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/validate-token')
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
return req.user.role;
|
||||
}
|
||||
|
||||
@Post('/create')
|
||||
|
||||
@@ -18,7 +18,7 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
return {
|
||||
global: true,
|
||||
secret: configService.get('JWT_SECRET'),
|
||||
signOptions: { expiresIn: '1h' },
|
||||
signOptions: { expiresIn: '7h' },
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -27,9 +27,6 @@ export class UserService {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { usuario, password },
|
||||
});
|
||||
console.log(usuario);
|
||||
console.log(password);
|
||||
console.log(user);
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(`El usuario o la contraseña es incorrecta`);
|
||||
@@ -44,7 +41,7 @@ export class UserService {
|
||||
const payload = {
|
||||
id: user.id_usuario,
|
||||
usuario: user.usuario,
|
||||
role: user.perfil.perfil,
|
||||
role: user.perfil.id_perfil,
|
||||
};
|
||||
const token = await this.jwtService.signAsync(payload);
|
||||
|
||||
@@ -108,7 +105,6 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user