diff --git a/docker-compose.yml b/docker-compose.yml index f01d8df..2ce656a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,17 +1,15 @@ services: database: image: mariadb:latest - container_name: Iris_api + container_name: Iris_db restart: always environment: - - MARIADB_ROOT_PASSWORD=root - - MARIADB_DATABASE=Iris_testDB - - MARIADB_USER=miusuario - - MARIADB_PASSWORD=root - env_file: - - ../Iris_back/.env + MARIADB_ROOT_PASSWORD: root + MARIADB_DATABASE: Iris_testDB + MARIADB_USER: root + MARIADB_PASSWORD: root ports: - - '${DB_PORT}:3306' + - '3306:3306' volumes: - mariadb_data:/var/lib/mysql - ./initdb:/docker-entrypoint-initdb.d diff --git a/package-lock.json b/package-lock.json index 47f092e..1dfa050 100644 --- a/package-lock.json +++ b/package-lock.json @@ -243,7 +243,6 @@ "integrity": "sha512-2BCOP7TN8M+gVDj7/ht3hsaO/B/n5oDbiAyyvnRlNOs+u1o+JWNYTQrmpuNp1/Wq2gcFrI01JAW+paEKDMx/CA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.3", @@ -2503,7 +2502,6 @@ "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-11.1.6.tgz", "integrity": "sha512-krKwLLcFmeuKDqngG2N/RuZHCs2ycsKcxWIDgcm7i1lf3sQ0iG03ci+DsP/r3FcT/eJDFsIHnKtNta2LIi7PzQ==", "license": "MIT", - "peer": true, "dependencies": { "file-type": "21.0.0", "iterare": "1.2.1", @@ -2551,7 +2549,6 @@ "integrity": "sha512-siWX7UDgErisW18VTeJA+x+/tpNZrJewjTBsRPF3JVxuWRuAB1kRoiJcxHgln8Lb5UY9NdvklITR84DUEXD0Cg==", "hasInstallScript": true, "license": "MIT", - "peer": true, "dependencies": { "@nuxt/opencollective": "0.4.1", "fast-safe-stringify": "2.1.1", @@ -2635,7 +2632,6 @@ "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-11.1.6.tgz", "integrity": "sha512-HErwPmKnk+loTq8qzu1up+k7FC6Kqa8x6lJ4cDw77KnTxLzsCaPt+jBvOq6UfICmfqcqCCf3dKXg+aObQp+kIQ==", "license": "MIT", - "peer": true, "dependencies": { "cors": "2.8.5", "express": "5.1.0", @@ -2878,7 +2874,6 @@ "integrity": "sha512-27Ov4rm0s2C6LLX+NDXfDVB69LGs8K94sXtFhgeUyQ4DBywZuCgTBu2loCNHRr8JhT9DeQvJM5j9FAu/THbo4w==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@swc/counter": "^0.1.3", "@xhmikosr/bin-wrapper": "^13.0.5", @@ -2951,7 +2946,6 @@ "dev": true, "hasInstallScript": true, "license": "Apache-2.0", - "peer": true, "dependencies": { "@swc/counter": "^0.1.3", "@swc/types": "^0.1.24" @@ -3326,7 +3320,6 @@ "integrity": "sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/estree": "*", "@types/json-schema": "*" @@ -3486,7 +3479,6 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-24.5.2.tgz", "integrity": "sha512-FYxk1I7wPv3K2XBaoyH2cTnocQEu8AOZ60hPbsyukMPLv5/5qr7V1i8PLHdl6Zf87I+xZXFvPCXYjiTFq+YSDQ==", "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~7.12.0" } @@ -3628,7 +3620,6 @@ "integrity": "sha512-VGMpFQGUQWYT9LfnPcX8ouFojyrZ/2w3K5BucvxL/spdNehccKhB4jUyB1yBCXpr2XFm0jkECxgrpXBW2ipoAw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.44.0", "@typescript-eslint/types": "8.44.0", @@ -4955,7 +4946,6 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "devOptional": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -5014,7 +5004,6 @@ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -5282,7 +5271,6 @@ "resolved": "https://registry.npmjs.org/axios/-/axios-1.12.2.tgz", "integrity": "sha512-vMJzPewAlRyOgxV2dU0Cuz2O8zzzx9VYtbJOaBgXFeLc4IV/Eg50n4LowmehOOR61S8ZMpc2K5Sa7g6A4jfkUw==", "license": "MIT", - "peer": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.4", @@ -5571,7 +5559,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001716", "electron-to-chromium": "^1.5.149", @@ -5879,15 +5866,13 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/class-validator": { "version": "0.14.2", "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.2.tgz", "integrity": "sha512-3kMVRF2io8N8pY1IFIXlho9r8IPUUIfHe2hYVtiebvAzU2XeQFXTv+XI4WX+TnXmtwXMDcjngcpkiPM0O9PvLw==", "license": "MIT", - "peer": true, "dependencies": { "@types/validator": "^13.11.8", "libphonenumber-js": "^1.11.1", @@ -6682,7 +6667,6 @@ "integrity": "sha512-QePbBFMJFjgmlE+cXAlbHZbHpdFVS2E/6vzCy7aKlebddvl1vadiC4JFV5u/wqTkNUwEV8WrQi257jf5f06hrg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -6744,7 +6728,6 @@ "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==", "dev": true, "license": "MIT", - "peer": true, "bin": { "eslint-config-prettier": "bin/cli.js" }, @@ -8475,7 +8458,6 @@ "integrity": "sha512-Ry+p2+NLk6u8Agh5yVqELfUJvRfV51hhVBRIB5yZPY7mU0DGBmOuFG5GebZbMbm86cdQNK0fhJuDX8/1YorISQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@jest/core": "30.1.3", "@jest/types": "30.0.5", @@ -10484,7 +10466,6 @@ "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", "license": "MIT", - "peer": true, "dependencies": { "passport-strategy": "1.x.x", "pause": "0.0.1", @@ -10760,7 +10741,6 @@ "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", "dev": true, "license": "MIT", - "peer": true, "bin": { "prettier": "bin/prettier.cjs" }, @@ -10986,8 +10966,7 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==", - "license": "Apache-2.0", - "peer": true + "license": "Apache-2.0" }, "node_modules/repeat-string": { "version": "1.6.1", @@ -11151,7 +11130,6 @@ "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz", "integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==", "license": "Apache-2.0", - "peer": true, "dependencies": { "tslib": "^2.1.0" } @@ -11998,7 +11976,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -12372,7 +12349,6 @@ "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -12533,7 +12509,6 @@ "resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.3.27.tgz", "integrity": "sha512-pNV1bn+1n8qEe8tUNsNdD8ejuPcMAg47u2lUGnbsajiNUr3p2Js1XLKQjBMH0yMRMDfdX8T+fIRejFmIwy9x4A==", "license": "MIT", - "peer": true, "dependencies": { "@sqltools/formatter": "^1.2.5", "ansis": "^3.17.0", @@ -12755,7 +12730,6 @@ "integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", "devOptional": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -13061,7 +13035,6 @@ "integrity": "sha512-QaNKAvGCDRh3wW1dsDjeMdDXwZm2vqq3zn6Pvq4rHOEOGSaUMgOOjG2Y9ZbIGzpfkJk9ZYTHpDqgDfeBDcnLaw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/eslint-scope": "^3.7.7", "@types/estree": "^1.0.8", @@ -13131,7 +13104,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", diff --git a/src/caso-especial/caso-especial.controller.ts b/src/caso-especial/caso-especial.controller.ts index a4d7b49..e23446c 100644 --- a/src/caso-especial/caso-especial.controller.ts +++ b/src/caso-especial/caso-especial.controller.ts @@ -25,10 +25,10 @@ import { FilterCasoEspecialDto } from './dto/filter-caso-especial.dto'; @Controller('caso-especial') export class CasoEspecialController { - constructor(private readonly casoEspecialService: CasoEspecialService) {} + constructor(private readonly casoEspecialService: CasoEspecialService) { } @Post() - @UseGuards(AuthGuard('jwt')) // reemplaza verificaToken + @UseGuards(AuthGuard('jwt')) @UseInterceptors( FileInterceptor('archivos', { storage: diskStorage({ @@ -45,15 +45,9 @@ export class CasoEspecialController { @Body('alumno') alumno: CreateCasoEspecialDto, ) { try { - const data = await this.casoEspecialService.create(alumno, file.filename); - return { - statusCode: 201, - message: 'Archivo subido con éxito', - data, - }; + return await this.casoEspecialService.create(alumno, file.filename); } catch (err) { - // Si hay error, eliminar archivo subido - if (file && file.filename) { + if (file?.filename) { fs.unlinkSync(`./server/uploads/${file.filename}`); } throw new BadRequestException(err.message); diff --git a/src/caso-especial/caso-especial.service.ts b/src/caso-especial/caso-especial.service.ts index 9393ed5..daee115 100644 --- a/src/caso-especial/caso-especial.service.ts +++ b/src/caso-especial/caso-especial.service.ts @@ -32,7 +32,7 @@ export class CasoEspecialService { private validacion: ValidacionService, private gmail: gmail, private drive: DriveService, - ) {} + ) { } async create(body: CreateCasoEspecialDto, file: string) { const { @@ -52,62 +52,59 @@ export class CasoEspecialService { motivo = '', } = body; - const usuario = await this.usuarioRepository.findOneBy({ - idUsuario: idUsuario, + const usuario = await this.usuarioRepository.findOne({ + where: { idUsuario }, + relations: ['tipoUsuario'], }); + 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, - }); + const carrera = await this.carreraRepository.findOneBy({ idCarrera }); if (!carrera) throw new NotFoundException('Esta carrera no existe en la db.'); const casoExistente = await this.casoEspecialRepository.findOne({ - where: { usuario: usuario }, + where: { usuario: { idUsuario } }, }); 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.'); - } + if (!carpeta) throw new Error('No se pudo crear la carpeta en Drive.'); + const archivoZip = await this.drive.uploadFile( path, - `archivos.zip`, + '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) + if (!archivoZip) throw new Error('No se pudo subir el archivo a Drive.'); + const status = await this.statusRepository.findOneBy({ idStatus }); + if (!status) + throw new NotFoundException('Este status no existe en la db.'); + 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, + correo, + telefono, + institucion, + dependencia, + motivo, + direccion, + fechaInicio, + fechaFin, + fechaNacimiento, + carpeta, + archivoZip, + usuario, + carrera, + status, + creditos, }); await this.casoEspecialRepository.save(nuevoCaso); @@ -117,6 +114,7 @@ export class CasoEspecialService { }; } + async findAllFiltered(dto: FilterCasoEspecialDto) { const { pagina = 1, idStatus, nombre = '', numeroCuenta = '' } = dto; diff --git a/src/servicio/servicio.controller.ts b/src/servicio/servicio.controller.ts index 2696303..3173ad7 100644 --- a/src/servicio/servicio.controller.ts +++ b/src/servicio/servicio.controller.ts @@ -24,10 +24,11 @@ import { CrearServicioDto } from './dto/create-servicio.dto'; import { Response } from 'express'; import { ServiciosAdminDto } from './dto/servicios-admin.dto'; import { ServiciosResponsableDto } from './dto/servicios-responsable.dto'; +import { RegistroValidadoDto } from './dto/registro-validado.dto'; @Controller('servicio') export class ServicioController { - constructor(private readonly servicioService: ServicioService) {} + constructor(private readonly servicioService: ServicioService) { } // ------------------ POST ------------------ @@ -44,6 +45,13 @@ export class ServicioController { return { ok: true }; } + @Post('registro-validado') + async registroValidado( + @Body() dto: RegistroValidadoDto, + ): Promise<{ message: string }> { + return this.servicioService.registroValidado(dto); + } + @Post('nuevo') @UseGuards(AuthGuard('jwt')) @UseInterceptors(FileInterceptor('cartaAceptacion')) @@ -104,7 +112,7 @@ export class ServicioController { @Get('reporte') @UseGuards(AuthGuard('jwt')) async generarReporte( - @Query('inicio') inicio: string, + @Query('inicio') inicio: string, @Query('fin') fin: string, @Res() res: Response) { const path = await this.servicioService.generarReporte(inicio, fin); @@ -199,4 +207,3 @@ export class ServicioController { return this.servicioService.update(data, files); } } - \ No newline at end of file diff --git a/src/servicio/servicio.module.ts b/src/servicio/servicio.module.ts index 9992fdb..93a3873 100644 --- a/src/servicio/servicio.module.ts +++ b/src/servicio/servicio.module.ts @@ -15,10 +15,11 @@ 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'; +import { Status } from 'src/status/entities/status.entity'; @Module({ imports: [ - TypeOrmModule.forFeature([Servicio, Usuario, Programa, Carrera]), + TypeOrmModule.forFeature([Servicio, Usuario, Programa, Carrera, Status]), AuthModule, ], controllers: [ServicioController], @@ -31,4 +32,4 @@ import { AuthModule } from 'src/auth/auth.module'; ], exports: [TypeOrmModule], }) -export class ServicioModule {} +export class ServicioModule { } diff --git a/src/servicio/servicio.service.ts b/src/servicio/servicio.service.ts index 727cb0a..e8a2caa 100644 --- a/src/servicio/servicio.service.ts +++ b/src/servicio/servicio.service.ts @@ -22,7 +22,8 @@ import { RegistroValidadoDto } from './dto/registro-validado.dto'; import * as fs from 'fs'; import { ServiciosAdminDto } from './dto/servicios-admin.dto'; import { ServiciosResponsableDto } from './dto/servicios-responsable.dto'; -import { SendMailDto } from 'src/helpers.services/dto/send-email.dto'; +import { SendMailDto } from 'src/helpers.services/dto/send-email.dto'; +import { Status } from 'src/status/entities/status.entity'; const { canceladoAlumno, canceladoResponsable, @@ -43,6 +44,9 @@ export class ServicioService { @InjectRepository(Carrera) private carreraRepo: Repository, + @InjectRepository(Status) + private statusRepo: Repository, + private validacionService: ValidacionService, private driveService: DriveService, @@ -52,7 +56,7 @@ export class ServicioService { private archivoService: ArchivoService, private authService: AuthService, - ) {} + ) { } async obtenerServicioAlumno(idUsuario: number) { const usuario = await this.usuarioRepo.findOne({ @@ -653,7 +657,7 @@ export class ServicioService { */ // Hacemos una validacion en el nombre const nombreArchivo = `./server/uploads/${this.validacionService.validacionBasicaStr(file.filename, 'archivo', true, 1000)}`; - + const archivoPath = `./server/uploads/${nombreArchivo}`; // Validacion de tipo de archivo @@ -668,11 +672,11 @@ export class ServicioService { const progInterno = dto.programaInterno ? this.validacionService.validarAlfanumerico( - dto.programaInterno, - 'programa interno', - true, - 250, - ) + dto.programaInterno, + 'programa interno', + true, + 250, + ) : ''; const prof = dto.profesor ? this.validacionService.validarTexto(dto.profesor, 'profesor', true, 50) @@ -757,28 +761,22 @@ export class ServicioService { idServicio: number, mensaje: string, ): Promise<{ message: string }> { - let correoResponsable: any = {}; - let correoAlumno: any = {}; + let correoResponsable: any; + let correoAlumno: any; let emailResponsable = ''; - const sendCorreoResponsableDto: SendMailDto = { - to: correoResponsable, - subject: correoResponsable.subject, - fecha_recibido: new Date(), - text: correoResponsable.msj, - html: '', - adjuntos: undefined, - }; const servicio = await this.servicioRepo.findOne({ where: { idServicio }, - relations: ['usuario', 'programa', 'programa.usuario'], + relations: ['usuario', 'programa', 'programa.usuario', 'status'], }); if (!servicio) { throw new NotFoundException('No existe este Servicio Social.'); } - switch (servicio.status?.idStatus) { + const statusId = servicio.status.idStatus; + + switch (statusId) { case 1: correoAlumno = preRegistroRechazadoAlumno( mensaje, @@ -790,18 +788,9 @@ export class ServicioService { servicio.usuario.nombre, ); - emailResponsable = servicio.programa.usuario.usuario; // correo del responsable + emailResponsable = servicio.programa.usuario.usuario; - const sendCorreoAlumnoDto: SendMailDto = { - to: servicio.correo, - subject: correoAlumno.subject, - fecha_recibido: new Date(), - text: correoAlumno.msj, - html: '', - adjuntos: undefined, - }; - - // Enviar correo al alumno + // correo alumno await this.gmailService.enviarCorreo({ subject: correoAlumno.subject, to: servicio.correo, @@ -835,7 +824,7 @@ export class ServicioService { throw new BadRequestException('Id status no válido.'); } - // Enviar correo al responsable + // correo responsable await this.gmailService.enviarCorreo({ subject: correoResponsable.subject, to: emailResponsable, @@ -843,57 +832,51 @@ export class ServicioService { fecha_recibido: new Date(), }); - // Actualizar estado del servicio + const statusRechazado = await this.statusRepo.findOneBy({ idStatus: 7 }); + + if (!statusRechazado) { + throw new NotFoundException('El estatus de rechazado no existe.'); + } + await this.servicioRepo.update(idServicio, { - status: { idStatus: 7 }, // si tienes relación con Status + status: statusRechazado, cartaAceptacion: '', }); - return { message: 'Se rechazó correctamente la Carta de Aceptación.' }; + return { + message: 'Se rechazó correctamente la Carta de Aceptación.', + }; } + async rechazarInforme( idServicio: number, mensaje: string, ): Promise<{ message: string }> { - let correoResponsable: any = {}; - let correoAlumno: any = {}; + let correoResponsable: any; + let correoAlumno: any; let emailResponsable = ''; - const sendCorreoResponsableDto: SendMailDto = { - to: correoResponsable, - subject: correoResponsable.subject, - fecha_recibido: new Date(), - text: correoResponsable.msj, - html: '', - adjuntos: undefined, - }; - const servicio = await this.servicioRepo.findOne({ where: { idServicio }, - relations: ['usuario', 'programa', 'programa.usuario'], + relations: ['usuario', 'programa', 'programa.usuario', 'status'], }); - if (!servicio) + if (!servicio) { throw new NotFoundException('No existe este Servicio Social.'); + } - const sendCorreoAlumnoDto: SendMailDto = { - to: servicio.correo, - subject: correoAlumno.subject, - fecha_recibido: new Date(), - text: correoAlumno.msj, - html: '', - adjuntos: undefined, - }; - - switch (servicio.status?.idStatus) { - case 5: { - correoAlumno = terminoRechazadoAlumno(mensaje, servicio.usuario.nombre); + switch (servicio.status.idStatus) { + case 5: + correoAlumno = terminoRechazadoAlumno( + mensaje, + servicio.usuario.nombre, + ); correoResponsable = terminoRechazadoResponsable( mensaje, servicio.usuario.nombre, ); - emailResponsable = servicio.programa.usuario.usuario; // correo responsable + emailResponsable = servicio.programa.usuario.usuario; await this.gmailService.enviarCorreo({ subject: correoAlumno.subject, @@ -902,7 +885,6 @@ export class ServicioService { fecha_recibido: new Date(), }); break; - } case 1: case 2: @@ -933,7 +915,6 @@ export class ServicioService { throw new BadRequestException('Id status no válido.'); } - // Enviar correo al responsable await this.gmailService.enviarCorreo({ subject: correoResponsable.subject, to: emailResponsable, @@ -941,54 +922,40 @@ export class ServicioService { fecha_recibido: new Date(), }); - // Actualizar estado del servicio await this.servicioRepo.update(idServicio, { - status: { idStatus: 9 }, // nuevo estado (rechazado) + status: { idStatus: 9 }, informeGlobal: '', }); - return { message: 'Se rechazó correctamente el Informe Global.' }; + return { + message: 'Se rechazó correctamente el Informe Global.', + }; } + async rechazarTermino( idServicio: number, mensaje: string, ): Promise<{ message: string }> { - let correoResponsable: any = {}; - let correoAlumno: any = {}; + let correoResponsable: any; + let correoAlumno: any; let emailResponsable = ''; - const sendCorreoResponsableDto: SendMailDto = { - to: correoResponsable, - subject: correoResponsable.subject, - fecha_recibido: new Date(), - text: correoResponsable.msj, - html: '', - adjuntos: undefined, - }; - const servicio = await this.servicioRepo.findOne({ where: { idServicio }, - relations: ['usuario', 'programa', 'programa.usuario'], + relations: ['usuario', 'programa', 'programa.usuario', 'status'], }); - if (!servicio) + if (!servicio) { throw new NotFoundException('No existe este Servicio Social.'); + } - const sendCorreoAlumnoDto: SendMailDto = { - to: servicio.correo, - subject: correoAlumno.subject, - fecha_recibido: new Date(), - text: correoAlumno.msj, - html: '', - adjuntos: undefined, - }; - - const idStatus = servicio.status?.idStatus; - - switch (idStatus) { - case 5: { - correoAlumno = terminoRechazadoAlumno(mensaje, servicio.usuario.nombre); + switch (servicio.status.idStatus) { + case 5: + correoAlumno = terminoRechazadoAlumno( + mensaje, + servicio.usuario.nombre, + ); correoResponsable = terminoRechazadoResponsable( mensaje, servicio.usuario.nombre, @@ -1002,7 +969,6 @@ export class ServicioService { fecha_recibido: new Date(), }); break; - } case 1: case 2: @@ -1033,7 +999,6 @@ export class ServicioService { throw new BadRequestException('Id status no válido.'); } - // Enviar correo al responsable await this.gmailService.enviarCorreo({ subject: correoResponsable.subject, to: emailResponsable, @@ -1041,15 +1006,17 @@ export class ServicioService { fecha_recibido: new Date(), }); - // Actualizar el servicio await this.servicioRepo.update(idServicio, { - status: { idStatus: 8 }, // Rechazado (Carta de Término) + status: { idStatus: 8 }, cartaTermino: '', }); - return { message: 'Se rechazó correctamente la Carta de Término.' }; + return { + message: 'Se rechazó correctamente la Carta de Término.', + }; } + async registro(idServicio: number): Promise<{ message: string }> { let password = await this.authService.generarPassword(); if (process.env.MODE === 'pruebas') password = 'qwertyui'; @@ -1419,7 +1386,7 @@ export class ServicioService { dataUpdate.cartaAceptacion = result === null ? undefined : result; } } - } catch (err) {} + } catch (err) { } try { if (files?.['cartaTermino']?.[0]?.filename) { @@ -1433,7 +1400,7 @@ export class ServicioService { dataUpdate.cartaTermino = result === null ? undefined : result; } } - } catch (err) {} + } catch (err) { } try { if (files?.['informeGlobal']?.[0]?.filename) { @@ -1445,7 +1412,7 @@ export class ServicioService { ); dataUpdate.informeGlobal = result === null ? undefined : result; } - } catch (err) {} + } catch (err) { } // ---- 📆 Validaciones de campos del body ---- if (body.correo) dataUpdate.correo = body.correo; diff --git a/src/usuario/usuario.controller.ts b/src/usuario/usuario.controller.ts index 9869c6a..5d7275b 100644 --- a/src/usuario/usuario.controller.ts +++ b/src/usuario/usuario.controller.ts @@ -20,13 +20,13 @@ import { UpdateUsuarioDto } from './dto/update-usuario.dto'; @Controller('usuario') export class UsuarioController { - constructor(private readonly usuarioService: UsuarioService) {} + constructor(private readonly usuarioService: UsuarioService) { } - /*Get('todos') - //@UseGuards(AuthGuard('jwt')) - async obtenerTodosLosServicios() { - return this.usuarioService.obtenerTodosLosUsuarios(); - }*/ //No subir en produccion + /*Get('todos') + //@UseGuards(AuthGuard('jwt')) + async obtenerTodosLosServicios() { + return this.usuarioService.obtenerTodosLosUsuarios(); + }*/ //No subir en produccion @Post('crearUsuario') @UsePipes(new ValidationPipe({ transform: true })) diff --git a/src/usuario/usuario.service.ts b/src/usuario/usuario.service.ts index 9b01f03..6e2c377 100644 --- a/src/usuario/usuario.service.ts +++ b/src/usuario/usuario.service.ts @@ -60,7 +60,7 @@ export class UsuarioService { private readonly tipoUsurioRepo: Repository, private readonly gmail: gmail, private readonly authService: AuthService, - ) {} + ) { } async escolares(numeroDeCuenta: string) { let response; @@ -79,17 +79,23 @@ export class UsuarioService { }); */ response = { - data: { - nombre: 'nombre', - carrconst: 'Carrera', - avance: '80', - }, + data: { + nombre: 'nombre', + carrconst: 'Carrera', + avance: '80', + }, }; } else { response = await axios.post( `${process.env.ESCOLARES}${numeroDeCuenta}`, - { password: process.env.ESCOLARES_PASS }, + process.env.ESCOLARES_PASS, + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }, ); + } } catch (error) { throw new UnauthorizedException( @@ -174,7 +180,7 @@ export class UsuarioService { } // Preparar correo - const { preRegistro } = require('../helpers.services/msjCorreos'); + const { preRegistro } = require('../helpers.services/msjCorreos'); let correo = preRegistro(password, usuario.nombre); // Enviar correo @@ -198,7 +204,7 @@ export class UsuarioService { const password = await this.authService.generarPassword(); // Buscar usuario - const usuario = await this.userRepo.findOne({ where: { idUsuario },relations: ['tipoUsuario'] }); + const usuario = await this.userRepo.findOne({ where: { idUsuario }, relations: ['tipoUsuario'] }); if (!usuario) { throw new NotFoundException('No existe este Usuario.'); @@ -258,7 +264,7 @@ export class UsuarioService { const dataUpdate: Partial = {}; // Buscar responsable - const responsable = await this.userRepo.findOne({ + const responsable = await this.userRepo.findOne({ where: { idUsuario }, relations: ['tipoUsuario'], }); @@ -354,13 +360,13 @@ export class UsuarioService { }; } -/*c obtenerTodosLosUsuarios() { - return await this.userRepo.find({ - relations: ['tipoUsuario'], - take: 10, - order: { - idUsuario: 'DESC', // Ordenar por el más reciente primero - }, - }); - }*/ // no subir a produccion + /*c obtenerTodosLosUsuarios() { + return await this.userRepo.find({ + relations: ['tipoUsuario'], + take: 10, + order: { + idUsuario: 'DESC', // Ordenar por el más reciente primero + }, + }); + }*/ // no subir a produccion }