From f06decdc43ac6ed03aba726d272b733eda16d631 Mon Sep 17 00:00:00 2001 From: Emilio Date: Wed, 22 Oct 2025 10:30:23 -0600 Subject: [PATCH 1/5] se corrigieron los modules --- ProgramaModule | 0 UsuarioModule] | 0 src/auth/auth.module.ts | 2 +- src/carrera/carrera.module.ts | 7 +- src/caso-especial/caso-especial.service.ts | 156 +++++++++++--------- src/programa/programa.module.ts | 20 ++- src/servicio/servicio.module.ts | 13 +- src/status/status.module.ts | 3 + src/tipo-usuario/tipo-usuario.controller.ts | 34 ----- src/usuario/usuario.module.ts | 16 +- 10 files changed, 144 insertions(+), 107 deletions(-) create mode 100644 ProgramaModule create mode 100644 UsuarioModule] delete mode 100644 src/tipo-usuario/tipo-usuario.controller.ts diff --git a/ProgramaModule b/ProgramaModule new file mode 100644 index 0000000..e69de29 diff --git a/UsuarioModule] b/UsuarioModule] new file mode 100644 index 0000000..e69de29 diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index 9189418..53374ae 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -1,4 +1,4 @@ -import { JwtModule } from '@nestjs/jwt'; +import { JwtModule, JwtService } from '@nestjs/jwt'; import { Module } from '@nestjs/common'; import { AuthService } from './auth.service'; import { Usuario } from 'src/usuario/entities/usuario.entity'; diff --git a/src/carrera/carrera.module.ts b/src/carrera/carrera.module.ts index 97fcf41..e1663fa 100644 --- a/src/carrera/carrera.module.ts +++ b/src/carrera/carrera.module.ts @@ -1,8 +1,9 @@ import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Carrera } from './entities/carrera.entity'; @Module({ - controllers: [], - providers: [], - exports: [], + imports: [TypeOrmModule.forFeature([Carrera])], + exports: [TypeOrmModule], }) export class CarreraModule {} diff --git a/src/caso-especial/caso-especial.service.ts b/src/caso-especial/caso-especial.service.ts index f0ddcd1..92a436c 100644 --- a/src/caso-especial/caso-especial.service.ts +++ b/src/caso-especial/caso-especial.service.ts @@ -1,4 +1,8 @@ -import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'; +import { + BadRequestException, + Injectable, + NotFoundException, +} from '@nestjs/common'; import { CreateCasoEspecialDto } from './dto/create-caso-especial.dto'; import { UpdateCasoEspecialDto } from './dto/update-caso-especial.dto'; import { ValidacionService } from 'src/helpers.services/validacion.service'; @@ -12,6 +16,7 @@ import { DriveService } from 'src/drive/drive.service'; import { Status } from 'src/status/entities/status.entity'; import { FilterCasoEspecialDto } from './dto/filter-caso-especial.dto'; import { arch } from 'os'; +import { SendMailDto } from 'src/helpers.services/dto/send-email.dto'; @Injectable() export class CasoEspecialService { @@ -27,9 +32,7 @@ export class CasoEspecialService { private validacion: ValidacionService, private gmail: gmail, private drive: DriveService, - ) { } - - + ) {} async create(body: CreateCasoEspecialDto, file: string) { const { @@ -49,49 +52,63 @@ export class CasoEspecialService { motivo = '', } = body; - const usuario = await this.usuarioRepository.findOneBy({ idUsuario: idUsuario }); - if (!usuario) throw new NotFoundException('Este alumno no existe en la db.'); - if (usuario.tipoUsuario.idTipoUsuario !== 3) throw new BadRequestException('Este usuario no es de tipo Alumno.'); + const usuario = await this.usuarioRepository.findOneBy({ + idUsuario: idUsuario, + }); + if (!usuario) + throw new NotFoundException('Este alumno no existe en la db.'); + if (usuario.tipoUsuario.idTipoUsuario !== 3) + throw new BadRequestException('Este usuario no es de tipo Alumno.'); - const carrera = await this.carreraRepository.findOneBy({ idCarrera: idCarrera }); - if (!carrera) throw new NotFoundException('Esta carrera no existe en la db.'); + const carrera = await this.carreraRepository.findOneBy({ + idCarrera: idCarrera, + }); + if (!carrera) + throw new NotFoundException('Esta carrera no existe en la db.'); - const casoExistente = await this.casoEspecialRepository.findOne({ where: { usuario: usuario } }); - if (casoExistente) throw new BadRequestException('Este alumno ya tiene un Caso Especial.'); + const casoExistente = await this.casoEspecialRepository.findOne({ + where: { usuario: usuario }, + }); + if (casoExistente) + throw new BadRequestException('Este alumno ya tiene un Caso Especial.'); const path = `./server/uploads/${file}`; const carpeta = await this.drive.folder(numeroCuenta); if (!carpeta) { throw new Error('No se pudo crear la carpeta en Drive.'); } - const archivoZip = await this.drive.uploadFile(path, `archivos.zip`, 'application/zip', carpeta); - - const status = await this.statusRepository.findOne({ where: { idStatus: idStatus } }) + const archivoZip = await this.drive.uploadFile( + path, + `archivos.zip`, + 'application/zip', + carpeta, + ); + const status = await this.statusRepository.findOne({ + where: { idStatus: idStatus }, + }); if (!status) throw new NotFoundException('Este status no existe en la db.'); - if(archivoZip === null) throw new Error('No se pudo subir el archivo a Drive.') - + if (archivoZip === null) + throw new Error('No se pudo subir el archivo a Drive.'); - const nuevoCaso = this.casoEspecialRepository.create( - { - correo: correo, - telefono: telefono, - institucion: institucion, - dependencia: dependencia, - motivo: motivo, - direccion: direccion, - fechaInicio: fechaInicio, - fechaFin: fechaFin, - fechaNacimiento: fechaNacimiento, - carpeta: carpeta, - archivoZip: archivoZip, - usuario: usuario, - carrera: carrera, - status: status, - creditos: creditos, - } - ); + const nuevoCaso = this.casoEspecialRepository.create({ + correo: correo, + telefono: telefono, + institucion: institucion, + dependencia: dependencia, + motivo: motivo, + direccion: direccion, + fechaInicio: fechaInicio, + fechaFin: fechaFin, + fechaNacimiento: fechaNacimiento, + carpeta: carpeta, + archivoZip: archivoZip, + usuario: usuario, + carrera: carrera, + status: status, + creditos: creditos, + }); await this.casoEspecialRepository.save(nuevoCaso); @@ -102,10 +119,10 @@ export class CasoEspecialService { async findAllFiltered(dto: FilterCasoEspecialDto) { const { pagina = 1, idStatus, nombre = '', numeroCuenta = '' } = dto; - + const take = 25; const skip = (pagina - 1) * take; - + const query = this.casoEspecialRepository .createQueryBuilder('caso') .leftJoinAndSelect('caso.usuario', 'usuario') @@ -114,32 +131,36 @@ export class CasoEspecialService { .take(take) .skip(skip) .orderBy('caso.updatedAt', 'DESC'); - + if (idStatus) { query.andWhere('status.idStatus = :idStatus', { idStatus }); } else { query.andWhere('status.idStatus > :defaultStatus', { defaultStatus: 10 }); } - + if (nombre) { query.andWhere('usuario.nombre ILIKE :nombre', { nombre: `%${nombre}%` }); } - + if (numeroCuenta) { - query.andWhere('usuario.usuario ILIKE :numeroCuenta', { numeroCuenta: `%${numeroCuenta}%` }); + query.andWhere('usuario.usuario ILIKE :numeroCuenta', { + numeroCuenta: `%${numeroCuenta}%`, + }); } - + const [result, total] = await query.getManyAndCount(); - + return { count: total, serviciosEspeciales: result, }; } - async liberarCasoEspecial(idCEspecial: number): Promise<{ message: string }> { - const idCasoEspecial = this.validacion.validarNumeroEntero(idCEspecial, 'id caso especial'); + const idCasoEspecial = this.validacion.validarNumeroEntero( + idCEspecial, + 'id caso especial', + ); let update = {}; const caso = await this.casoEspecialRepository.findOne({ @@ -161,20 +182,17 @@ export class CasoEspecialService { idStatus: caso.status.idStatus === 11 ? 13 : 14, }; - let sendMessage = { + let sendMessage: SendMailDto = { to: caso.correo, subject: correo.subject, text: correo.msj, - - html: '', - - - } + fecha_recibido: new Date(), + }; // Envía correo - await this.gmail.sendMail(sendMessage); + await this.gmail.enviarCorreo(sendMessage); break; case 6: @@ -188,18 +206,21 @@ export class CasoEspecialService { await this.casoEspecialRepository.update({ idCasoEspecial }, update); return { - message: 'Se cambió de estatus correctamente y se envió un correo al alumno informándole de su liberación.', + message: + 'Se cambió de estatus correctamente y se envió un correo al alumno informándole de su liberación.', }; } - async admin(idCasoEspecial: number) { const id = this.validacion.validarNumeroEntero( idCasoEspecial, - 'id caso especial' + 'id caso especial', ); - const casoEspecial = await this.casoEspecialRepository.findOne({ where: { idCasoEspecial }, relations: ['usuario', 'carrera', 'status'] }); + const casoEspecial = await this.casoEspecialRepository.findOne({ + where: { idCasoEspecial }, + relations: ['usuario', 'carrera', 'status'], + }); if (!casoEspecial) { throw new Error('No existe este Caso Especial.'); } @@ -207,12 +228,14 @@ export class CasoEspecialService { } async updateCasoEspecial(id: number, dto: UpdateCasoEspecialDto) { - const caso = await this.casoEspecialRepository.findOne({ where: { idCasoEspecial: id } }); - + const caso = await this.casoEspecialRepository.findOne({ + where: { idCasoEspecial: id }, + }); + if (!caso) { throw new NotFoundException('Este Caso Especial no existe en la db.'); } - + const camposActualizables = [ 'correo', 'fechaInicio', @@ -224,25 +247,26 @@ export class CasoEspecialService { 'dependencia', 'motivo', ]; - + let huboCambios = false; - + for (const campo of camposActualizables) { if (dto[campo] !== undefined) { (caso as any)[campo] = dto[campo]; huboCambios = true; } } - + if (!huboCambios) { - throw new BadRequestException('No se envió ningún campo para actualizar este caso especial.'); + throw new BadRequestException( + 'No se envió ningún campo para actualizar este caso especial.', + ); } - + await this.casoEspecialRepository.save(caso); - + return { message: 'Se guardaron correctamente los cambios de este caso especial.', }; } - } diff --git a/src/programa/programa.module.ts b/src/programa/programa.module.ts index aac5c70..8f6c74f 100644 --- a/src/programa/programa.module.ts +++ b/src/programa/programa.module.ts @@ -1,9 +1,27 @@ import { Module } from '@nestjs/common'; import { ProgramaService } from './programa.service'; import { ProgramaController } from './programa.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Programa } from './entities/programa.entity'; +import { Usuario } from 'src/usuario/entities/usuario.entity'; +import { UsuarioModule } from 'src/usuario/usuario.module'; +import { ValidacionService } from 'src/helpers.services/validacion.service'; +import { AuthService } from 'src/auth/auth.service'; +import { gmail } from 'src/helpers.services/gmail.service'; +import { AuthModule } from 'src/auth/auth.module'; +import { JwtService } from '@nestjs/jwt'; +import { Servicio } from 'src/servicio/entities/servicio.entity'; @Module({ + imports: [TypeOrmModule.forFeature([Programa, Servicio]), UsuarioModule], controllers: [ProgramaController], - providers: [ProgramaService], + providers: [ + ProgramaService, + AuthService, + ValidacionService, + gmail, + JwtService, + ], + exports: [TypeOrmModule], }) export class ProgramaModule {} diff --git a/src/servicio/servicio.module.ts b/src/servicio/servicio.module.ts index a0e70fe..9992fdb 100644 --- a/src/servicio/servicio.module.ts +++ b/src/servicio/servicio.module.ts @@ -8,9 +8,19 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { Servicio } from './entities/servicio.entity'; import { Usuario } from 'src/usuario/entities/usuario.entity'; import { ArchivoService } from 'src/helpers.services/archivo.service'; +import { UsuarioModule } from 'src/usuario/usuario.module'; +import { ProgramaModule } from 'src/programa/programa.module'; +import { Programa } from 'src/programa/entities/programa.entity'; +import { Carrera } from 'src/carrera/entities/carrera.entity'; +import { Auth } from 'googleapis'; +import { AuthService } from 'src/auth/auth.service'; +import { AuthModule } from 'src/auth/auth.module'; @Module({ - imports: [TypeOrmModule.forFeature([Servicio, Usuario])], + imports: [ + TypeOrmModule.forFeature([Servicio, Usuario, Programa, Carrera]), + AuthModule, + ], controllers: [ServicioController], providers: [ ServicioService, @@ -19,5 +29,6 @@ import { ArchivoService } from 'src/helpers.services/archivo.service'; gmail, ArchivoService, ], + exports: [TypeOrmModule], }) export class ServicioModule {} diff --git a/src/status/status.module.ts b/src/status/status.module.ts index c0e6a62..5bf4314 100644 --- a/src/status/status.module.ts +++ b/src/status/status.module.ts @@ -1,8 +1,11 @@ import { Module } from '@nestjs/common'; import { StatusService } from './status.service'; import { StatusController } from './status.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Status } from './entities/status.entity'; @Module({ + imports: [TypeOrmModule.forFeature([Status])], controllers: [StatusController], providers: [StatusService], }) diff --git a/src/tipo-usuario/tipo-usuario.controller.ts b/src/tipo-usuario/tipo-usuario.controller.ts deleted file mode 100644 index e0d1cb8..0000000 --- a/src/tipo-usuario/tipo-usuario.controller.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; -import { TipoUsuarioService } from './tipo-usuario.service'; -import { CreateTipoUsuarioDto } from './dto/create-tipo-usuario.dto'; -import { UpdateTipoUsuarioDto } from './dto/update-tipo-usuario.dto'; - -@Controller('tipo-usuario') -export class TipoUsuarioController { - constructor(private readonly tipoUsuarioService: TipoUsuarioService) {} - - @Post() - create(@Body() createTipoUsuarioDto: CreateTipoUsuarioDto) { - return this.tipoUsuarioService.create(createTipoUsuarioDto); - } - - @Get() - findAll() { - return this.tipoUsuarioService.findAll(); - } - - @Get(':id') - findOne(@Param('id') id: string) { - return this.tipoUsuarioService.findOne(+id); - } - - @Patch(':id') - update(@Param('id') id: string, @Body() updateTipoUsuarioDto: UpdateTipoUsuarioDto) { - return this.tipoUsuarioService.update(+id, updateTipoUsuarioDto); - } - - @Delete(':id') - remove(@Param('id') id: string) { - return this.tipoUsuarioService.remove(+id); - } -} diff --git a/src/usuario/usuario.module.ts b/src/usuario/usuario.module.ts index 100d41c..36f05b5 100644 --- a/src/usuario/usuario.module.ts +++ b/src/usuario/usuario.module.ts @@ -1,9 +1,23 @@ import { Module } from '@nestjs/common'; import { UsuarioService } from './usuario.service'; import { UsuarioController } from './usuario.controller'; +import { Usuario } from './entities/usuario.entity'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { CarreraModule } from 'src/carrera/carrera.module'; +import { ServicioModule } from 'src/servicio/servicio.module'; +import { gmail } from 'src/helpers.services/gmail.service'; +import { Auth } from 'googleapis'; +import { AuthModule } from 'src/auth/auth.module'; @Module({ + imports: [ + TypeOrmModule.forFeature([Usuario]), + CarreraModule, + ServicioModule, + AuthModule, + ], controllers: [UsuarioController], - providers: [UsuarioService], + providers: [UsuarioService, gmail], + exports: [TypeOrmModule], }) export class UsuarioModule {} From 442780486598289cede1d20126b3dd6fa908d9ab Mon Sep 17 00:00:00 2001 From: Emilio Date: Wed, 22 Oct 2025 13:44:11 -0600 Subject: [PATCH 2/5] modificaciones sobre .env --- src/auth/jwt.strategy.ts | 2 +- src/programa/programa.service.ts | 4 ---- src/servicio/servicio.service.ts | 4 ---- src/usuario/usuario.service.ts | 27 ++++++++++++++++----------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/auth/jwt.strategy.ts b/src/auth/jwt.strategy.ts index da8d485..3c725bb 100644 --- a/src/auth/jwt.strategy.ts +++ b/src/auth/jwt.strategy.ts @@ -7,7 +7,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) { constructor() { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), - secretOrKey: process.env.JWT_SECRET, + secretOrKey: process.env.JWT, }); } diff --git a/src/programa/programa.service.ts b/src/programa/programa.service.ts index 5dfaa3e..87b2127 100644 --- a/src/programa/programa.service.ts +++ b/src/programa/programa.service.ts @@ -90,10 +90,6 @@ export class ProgramaService { fecha_recibido: new Date(), }; - if (!process.env.TOKEN_GMAIL) { - throw new Error('No existe el token'); - } - try { responsable = await this.usuarioRepo.save(responsable); diff --git a/src/servicio/servicio.service.ts b/src/servicio/servicio.service.ts index 31a139b..d35e6c7 100644 --- a/src/servicio/servicio.service.ts +++ b/src/servicio/servicio.service.ts @@ -230,10 +230,6 @@ export class ServicioService { adjuntos: undefined, }; - if (!process.env.TOKEN_GMAIL) { - throw new Error('No existe el token'); - } - if (servicio.correo) { await this.gmailService.enviarCorreo(sendCorreoAlumnoDto); } diff --git a/src/usuario/usuario.service.ts b/src/usuario/usuario.service.ts index e23520c..ea77b8a 100644 --- a/src/usuario/usuario.service.ts +++ b/src/usuario/usuario.service.ts @@ -59,17 +59,22 @@ export class UsuarioService { async escolares(numeroDeCuenta: string) { let response; try { - response = await axios.post( - `${process.env.ESCOLARES}${numeroDeCuenta}`, - { password: process.env.ESCOLARES_PASS }, - - { - headers: { - 'Content-Type': 'application/json', // Tipo de contenido - Authorization: `Bearer ${process.env.API_TOKEN}`, // Header de auth - }, - }, - ); + if (process.env.MODE == 'pruebas') { + response = new Promise((res) => { + res({ + data: { + nombre: 'nombre', + carrconst: 'Carrera', + avance: '80', + }, + }); + }); + } else { + response = await axios.post( + `${process.env.ESCOLARES}${numeroDeCuenta}`, + { password: process.env.ESCOLARES_PASS }, + ); + } } catch (error) { throw new UnauthorizedException( 'No se pudo conectar con el servicio de escolares', From b771ca2e576c0009c1c0e7318e3b37c6c6851931 Mon Sep 17 00:00:00 2001 From: Emilio Date: Thu, 30 Oct 2025 11:32:38 -0600 Subject: [PATCH 3/5] Se hicieron cambios en el app module --- src/app.module.ts | 54 ++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index bbd262c..5b0b6e9 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -17,12 +17,10 @@ import { UsuarioModule } from './usuario/usuario.module'; @Module({ imports: [ - ConfigModule.forRoot( - {isGlobal: true} - ), - + ConfigModule.forRoot({ isGlobal: true }), + TypeOrmModule.forRoot({ - type: 'mysql', + type: 'mysql', host: process.env.db_host, username: process.env.db_username, database: process.env.db_database, @@ -31,32 +29,30 @@ import { UsuarioModule } from './usuario/usuario.module'; synchronize: true, dropSchema: false, // elimina la base de datos // logging: true, // Habilita los logs para depuración - autoLoadEntities: true, // Carga automáticamente las entidades - + autoLoadEntities: false, // Carga automáticamente las entidades }), - - CarreraModule, - - CasoEspecialModule, - - CuestionarioAlumnoModule, - - CuestionarioAlumno2Module, - - CuestionarioProgramaModule, - - CuestionarioPrograma2Module, - - ProgramaModule, - - ServicioModule, - - StatusModule, - - TipoUsuarioModule, - - UsuarioModule, + CarreraModule, + + CasoEspecialModule, + + CuestionarioAlumnoModule, + + CuestionarioAlumno2Module, + + CuestionarioProgramaModule, + + CuestionarioPrograma2Module, + + ProgramaModule, + + ServicioModule, + + StatusModule, + + TipoUsuarioModule, + + UsuarioModule, ], controllers: [AppController], providers: [AppService], From 09e12161bd96b88f395411428eb613b3873d453f Mon Sep 17 00:00:00 2001 From: Emilio Date: Thu, 30 Oct 2025 11:34:55 -0600 Subject: [PATCH 4/5] Se hicieron cambios en el app module --- env_Example | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 env_Example diff --git a/env_Example b/env_Example new file mode 100644 index 0000000..96113ee --- /dev/null +++ b/env_Example @@ -0,0 +1,12 @@ +DB_USERNAME= +DB_DATABASE= +DB_PASSWORD= +DB_PORT= +DB_HOST= +PORT= +JWT= +CARPETA= +MAIL_URL= +MAIL_TOKEN= +ESCOLARES= +ESCOLARES_PASS= \ No newline at end of file From 6a871d8fa1ba172b9b4ecfacbbe24bcaba36fa19 Mon Sep 17 00:00:00 2001 From: dscadmin Date: Thu, 30 Oct 2025 13:24:06 -0600 Subject: [PATCH 5/5] =?UTF-8?q?Modificaci=C3=B3n=20a=20script=20start=20de?= =?UTF-8?q?l=20package.json=20para=20uso=20de=20Node=2022?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 170f8b0..0035a31 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "nest start", + "start": "source ~/.nvm/nvm.sh && nvm use 22.10.0 && npm install && nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main",