Se realizaron correcciones

This commit is contained in:
evenegas
2026-01-06 07:20:11 -06:00
parent 5567a26ed6
commit bc4146a07d
9 changed files with 155 additions and 212 deletions
+10 -3
View File
@@ -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);
}
}
+3 -2
View File
@@ -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 { }
+68 -101
View File
@@ -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<Carrera>,
@InjectRepository(Status)
private statusRepo: Repository<Status>,
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;