diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index d91be9e..e127f1d 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -23,7 +23,7 @@ export class AuthService { @InjectRepository(Usuario) private readonly userRepo: Repository, - ) {} + ) { } async jwtVerificar(token: string) { try { @@ -57,7 +57,7 @@ export class AuthService { async encriptar(password) { const saltRounds = 10; - return await bcrypt.hash(password,saltRounds); + return await bcrypt.hash(password, saltRounds); } async generarPassword() { @@ -84,7 +84,7 @@ export class AuthService { const match = await this.comparar(password, user.password); if (!match) throw new UnauthorizedException('Credenciales inválidas'); - if (!user.activo) throw new Error('Este usuario no esta activo.'); + if (!user.activo) throw new BadRequestException('Este usuario no esta activo.'); const token = await this.jwtCreate( user.idUsuario, diff --git a/src/caso-especial/caso-especial.service.ts b/src/caso-especial/caso-especial.service.ts index 49f53b1..a64f656 100644 --- a/src/caso-especial/caso-especial.service.ts +++ b/src/caso-especial/caso-especial.service.ts @@ -74,7 +74,7 @@ export class CasoEspecialService { 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 BadRequestException('No se pudo crear la carpeta en Drive.'); const archivoZip = await this.drive.uploadFile( path, @@ -83,7 +83,7 @@ export class CasoEspecialService { carpeta, ); if (!archivoZip) - throw new Error('No se pudo subir el archivo a Drive.'); + throw new BadRequestException('No se pudo subir el archivo a Drive.'); const status = await this.statusRepository.findOneBy({ idStatus }); if (!status) @@ -167,7 +167,7 @@ export class CasoEspecialService { }); if (!caso) { - throw new Error('No existe este Caso Especial.'); + throw new BadRequestException('No existe este Caso Especial.'); } switch (caso.status.idStatus) { @@ -196,10 +196,10 @@ export class CasoEspecialService { break; case 6: - throw new Error('Este Caso Especial ya se encuentra en Liberación.'); + throw new BadRequestException('Este Caso Especial ya se encuentra en Liberación.'); default: - throw new Error('Id status no válido.'); + throw new BadRequestException('Id status no válido.'); } // Actualiza en base de datos @@ -222,7 +222,7 @@ export class CasoEspecialService { relations: ['usuario', 'carrera', 'status'], }); if (!casoEspecial) { - throw new Error('No existe este Caso Especial.'); + throw new BadRequestException('No existe este Caso Especial.'); } return casoEspecial; } diff --git a/src/cuestionario-alumno2/cuestionario-alumno2.service.ts b/src/cuestionario-alumno2/cuestionario-alumno2.service.ts index 6d789f3..fdaad69 100644 --- a/src/cuestionario-alumno2/cuestionario-alumno2.service.ts +++ b/src/cuestionario-alumno2/cuestionario-alumno2.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { BadRequestException, Injectable } from '@nestjs/common'; import { CreateCuestionarioAlumno2Dto } from './dto/create-cuestionario-alumno2.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { Servicio } from 'src/servicio/entities/servicio.entity'; @@ -35,11 +35,11 @@ export class CuestionarioAlumno2Service { relations: ['cuestionarioAlumno2', 'status'], }); if (!servicio) { - throw new Error('No existe este Servicio Social.'); + throw new BadRequestException('No existe este Servicio Social.'); } if (servicio.cuestionarioAlumno2) { - throw new Error( + throw new BadRequestException( 'Este Servicio Social ya cuenta con cuestionario de alumno', ); } @@ -49,7 +49,7 @@ export class CuestionarioAlumno2Service { console.log('antes de create ques2'); if (messageByStatus.hasOwnProperty(servicio.status.idStatus)) { - throw new Error(messageByStatus[servicio.status.idStatus]); + throw new BadRequestException(messageByStatus[servicio.status.idStatus]); } console.log('datos a registrar en la tabla cuestionarioAlumno2', { @@ -99,7 +99,7 @@ export class CuestionarioAlumno2Service { } if (!temp) { - throw new Error(); + throw new BadRequestException(); } data = temp.map((item) => ({ ...item })); @@ -133,7 +133,7 @@ export class CuestionarioAlumno2Service { } if (!temp || temp.length === 0) { - throw new Error('No hay datos para exportar'); + throw new BadRequestException('No hay datos para exportar'); } const data = temp.map((item) => ({ ...item })); diff --git a/src/cuestionario-programa2/cuestionario-programa2.service.ts b/src/cuestionario-programa2/cuestionario-programa2.service.ts index 8d63fcd..d6be802 100644 --- a/src/cuestionario-programa2/cuestionario-programa2.service.ts +++ b/src/cuestionario-programa2/cuestionario-programa2.service.ts @@ -22,8 +22,8 @@ export class CuestionarioPrograma2Service { private servicioRepository: Repository, private archivoService: ArchivoService, private validacionService: ValidacionService, - - ) {} + + ) { } async create(cuestionarioPrograma2: CreateCuestionarioPrograma2Dto) { let idServicio = cuestionarioPrograma2.idServicio; @@ -36,18 +36,18 @@ export class CuestionarioPrograma2Service { relations: ['cuestionarioPrograma2', 'status'], }); if (!servicio) { - throw new Error('No existe este Servicio Social.'); + throw new BadRequestException('No existe este Servicio Social.'); } if (servicio.cuestionarioPrograma2) { - throw new Error( + throw new BadRequestException( 'Este Servicio Social ya cuenta con cuestionario de programa', ); } // Esta validacion esta incorrecta la cambie por la linea de arriva // if (servicio.cuestionarioPrograma2.idCuestionarioPrograma2) { - // throw new Error( + // throw new BadRequestException( // 'Este Servicio Social ya cuenta con cuestionario de alumno', // ); // } @@ -56,7 +56,7 @@ export class CuestionarioPrograma2Service { console.log('antes de create ques2'); if (messageByStatus.hasOwnProperty(servicio.status.idStatus)) - throw new Error(messageByStatus[servicio.status.idStatus]); + throw new BadRequestException(messageByStatus[servicio.status.idStatus]); console.log('despues de registrar cuestionario', cuestionario); diff --git a/src/drive/drive.service.ts b/src/drive/drive.service.ts index 4d2dc4f..5231c0c 100644 --- a/src/drive/drive.service.ts +++ b/src/drive/drive.service.ts @@ -133,7 +133,7 @@ export class DriveService { }); if (!res.data.id) { - throw new Error('No se pudo crear la carpeta'); + throw new BadRequestException('No se pudo crear la carpeta'); } return res.data.id; diff --git a/src/helpers.services/validacion.service.ts b/src/helpers.services/validacion.service.ts index 3b99b8c..32c37e4 100644 --- a/src/helpers.services/validacion.service.ts +++ b/src/helpers.services/validacion.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from "@nestjs/common"; +import { BadRequestException, Injectable } from "@nestjs/common"; import { InjectRepository } from "@nestjs/typeorm"; import moment from "moment"; import { Servicio } from "src/servicio/entities/servicio.entity"; @@ -19,15 +19,15 @@ export class ValidacionService { } yaExiste(campo, m) { - throw new Error(`Ya se encuentra en uso ${m ? 'el' : 'la'} ${campo}.`); + throw new BadRequestException(`Ya se encuentra en uso ${m ? 'el' : 'la'} ${campo}.`); } noValido(campo, m, razon) { - throw new Error(`${m ? 'El' : 'La'} ${campo} no es valid${m ? 'o' : 'a'}, ${razon}.`); + throw new BadRequestException(`${m ? 'El' : 'La'} ${campo} no es valid${m ? 'o' : 'a'}, ${razon}.`); } noHay(variable, campo, m) { - if (!variable) throw new Error(`No se mando ${m ? 'el' : 'la'} ${campo}.`); + if (!variable) throw new BadRequestException(`No se mando ${m ? 'el' : 'la'} ${campo}.`); } validacionBasicaStr(texto, campo, m, length) { @@ -139,7 +139,7 @@ export class ValidacionService { for (const [key, value] of Object.entries(body)) { if (!optionalKeys.includes(key) && (value === null || value === undefined || value === '')) { - throw new Error(`El campo ${key} no puede estar vacío.`); + throw new BadRequestException(`El campo ${key} no puede estar vacío.`); } } @@ -157,7 +157,7 @@ export class ValidacionService { for (const key of expectedKeys) { if (!(key in body)) { - throw new Error(`Falta la respuesta para la pregunta ${key}.`); + throw new BadRequestException(`Falta la respuesta para la pregunta ${key}.`); } } @@ -170,7 +170,7 @@ export class ValidacionService { for (const [key, value] of Object.entries(body)) { if (!camposOpcionales.includes(key) && (value === null || value === undefined || value === '')) { - throw new Error(`El campo ${key} no puede estar vacío.`); + throw new BadRequestException(`El campo ${key} no puede estar vacío.`); } } @@ -184,7 +184,7 @@ export class ValidacionService { for (const key of expectedKeys) { if (!(key in body)) { - throw new Error(`Falta la respuesta para la pregunta ${key}.`); + throw new BadRequestException(`Falta la respuesta para la pregunta ${key}.`); } } diff --git a/src/programa/programa.service.ts b/src/programa/programa.service.ts index b7df099..d580cfa 100644 --- a/src/programa/programa.service.ts +++ b/src/programa/programa.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { BadRequestException, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Like, Repository } from 'typeorm'; import * as csv from 'csvtojson'; @@ -209,11 +209,11 @@ export class ProgramaService { }); if (!usuario) { - throw new Error('No existe este usuario.'); + throw new BadRequestException('No existe este usuario.'); } if (usuario.tipoUsuario.idTipoUsuario !== 2) { - throw new Error('No es un usuario de tipo responsable'); + throw new BadRequestException('No es un usuario de tipo responsable'); } const year = new Date().getFullYear().toString(); @@ -236,11 +236,11 @@ export class ProgramaService { }); if (!usuario) { - throw new Error('No existe este usuario.'); + throw new BadRequestException('No existe este usuario.'); } if (usuario.tipoUsuario.idTipoUsuario !== 2) { - throw new Error('No es un usuario de tipo responsable'); + throw new BadRequestException('No es un usuario de tipo responsable'); } const year = new Date().getFullYear().toString(); @@ -267,17 +267,17 @@ export class ProgramaService { relations: ["tipoUsuario"], }); - if (!usuarioNuevo) throw new Error('No existe este usuario.'); + if (!usuarioNuevo) throw new BadRequestException('No existe este usuario.'); if (usuarioNuevo.tipoUsuario.idTipoUsuario != 2) - throw new Error('No es un usuario de tipo responsable'); + throw new BadRequestException('No es un usuario de tipo responsable'); if (usuarioNuevo.usuario === correoOtroResponsable) - throw new Error('Son el mismo usuario.'); + throw new BadRequestException('Son el mismo usuario.'); let viejoResponsable = await this.usuarioRepo.findOne({ where: { usuario: otroResponsable }, }); - if (!viejoResponsable) throw new Error('No existe este usuario.'); + if (!viejoResponsable) throw new BadRequestException('No existe este usuario.'); await this.programaRepo.update( { usuario: viejoResponsable }, diff --git a/src/servicio/servicio.service.ts b/src/servicio/servicio.service.ts index cb14cac..b6f452d 100644 --- a/src/servicio/servicio.service.ts +++ b/src/servicio/servicio.service.ts @@ -969,7 +969,7 @@ export class ServicioService { }); if (!servicio.informeGlobal) { - throw new Error("no hay Informe Global") + throw new BadRequestException("no hay Informe Global") } await this.driveService.deleteFile(servicio.informeGlobal) @@ -1059,7 +1059,7 @@ export class ServicioService { }); if (!servicio.cartaTermino) { - throw new Error("No hay Carta Termino") + throw new BadRequestException("No hay Carta Termino") } await this.driveService.deleteFile(servicio.cartaTermino) diff --git a/src/usuario/usuario.service.ts b/src/usuario/usuario.service.ts index 572845c..6754676 100644 --- a/src/usuario/usuario.service.ts +++ b/src/usuario/usuario.service.ts @@ -109,7 +109,7 @@ export class UsuarioService { !response.data.carrconst || !response.data.avance ) { - throw new Error( + throw new BadRequestException( 'El alumno no cumple con los requisitos para realizar el Servicio Social. Si cree que esto es erróneo comunícate al Departamento de Servicio Social y Bolsa de Trabajo.', ); } @@ -127,7 +127,7 @@ export class UsuarioService { }; if (alumno.creditos < this.carreras[alumno.carrera]) { - throw new Error('Este alumno no cuenta con los créditos necesarios.'); + throw new BadRequestException('Este alumno no cuenta con los créditos necesarios.'); } while (alumno.nombre.search('‘') != -1 && alumno.nombre.search('Ã') != -1) { alumno.nombre = alumno.nombre.replace('Ã', 'Ñ');