Creacion de Spec y actualizacion de funcion Gmail

This commit is contained in:
2025-10-20 14:52:27 -06:00
parent 8eb7a2614d
commit 1adcff5298
+93 -52
View File
@@ -11,7 +11,7 @@ import { Servicio } from './entities/servicio.entity';
import { Usuario } from 'src/usuario/entities/usuario.entity';
import { ValidacionService } from 'src/helpers.services/validacion.service';
import { gmail } from 'src/helpers.services/gmail.service';
import { SendCorreoDto } from 'src/helpers.services/dto/send-email.dto';
import { SendMailDto } from 'src/helpers.services/dto/send-email.dto';
import { DriveService } from 'src/drive/drive.service';
import moment from 'moment';
import { ArchivoService } from 'src/helpers.services/archivo.service';
@@ -22,6 +22,7 @@ import { AuthService } from 'src/auth/auth.service';
import { RegistroValidadoDto } from './dto/registro-validado.dto';
import * as fs from 'fs';
import { ServiciosAdminDto } from './dto/servicios-admin.dto';
import { send } from 'process';
@Injectable()
export class ServicioService {
@@ -211,19 +212,19 @@ export class ServicioService {
const correoAlumno = canceladoAlumno(mensaje, alumno.nombre);
const correoResponsable = canceladoResponsable(mensaje, alumno.nombre);
const sendCorreoAlumnoDto: SendCorreoDto = {
const sendCorreoAlumnoDto: SendMailDto = {
to: servicio.correo,
subject: correoAlumno.subject,
fecha_recibido: new Date(),
fecha_recibido: new Date().toLocaleDateString(),
text: correoAlumno.msj,
html: '',
adjuntos: undefined,
};
const sendCorreoResponsableDto: SendCorreoDto = {
const sendCorreoResponsableDto: SendMailDto = {
to: responsable.usuario,
subject: correoResponsable.subject,
fecha_recibido: new Date(),
fecha_recibido: new Date().toLocaleDateString(),
text: correoResponsable.msj,
html: '',
adjuntos: undefined,
@@ -234,16 +235,16 @@ export class ServicioService {
}
if (servicio.correo) {
await this.gmailService.send(
await this.gmailService.enviarCorreo(
sendCorreoAlumnoDto,
process.env.TOKEN_GMAIL,
//process.env.TOKEN_GMAIL,
);
}
if (responsable.usuario) {
await this.gmailService.send(
await this.gmailService.enviarCorreo(
sendCorreoResponsableDto,
process.env.TOKEN_GMAIL,
//process.env.TOKEN_GMAIL,
);
}
@@ -588,15 +589,15 @@ export class ServicioService {
const correoAlumno = terminoValidado(servicio.usuario.nombre);
if (servicio.correo) {
await this.gmailService.sendMail(
await this.gmailService.enviarCorreo(
{
to: servicio.correo,
subject: correoAlumno.subject,
text: correoAlumno.msj,
html: '',
fecha_recibido: new Date(),
fecha_recibido: new Date().toLocaleDateString(),
},
process.env.TOKEN_GMAIL,
//process.env.TOKEN_GMAIL,
);
}
break;
@@ -739,6 +740,14 @@ export class ServicioService {
let correoAlumno: any = {};
let emailResponsable = '';
const sendCorreoResponsableDto: SendMailDto = {
to: correoResponsable,
subject: correoResponsable.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoResponsable.msj,
html: '',
adjuntos: undefined,
};
const servicio = await this.servicioRepo.findOne({
where: { idServicio },
relations: ['usuario', 'programa', 'programa.usuario'],
@@ -762,12 +771,18 @@ export class ServicioService {
emailResponsable = servicio.programa.usuario.usuario; // correo del responsable
const sendCorreoAlumnoDto: SendMailDto = {
to: servicio.correo,
subject: correoAlumno.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoAlumno.msj,
html: '',
adjuntos: undefined,
};
// Enviar correo al alumno
await this.gmailService.enviarCorreo(
correoAlumno.subject,
servicio.correo,
correoAlumno.msj,
);
await this.gmailService.enviarCorreo(sendCorreoAlumnoDto);
break;
case 2:
@@ -796,11 +811,7 @@ export class ServicioService {
}
// Enviar correo al responsable
await this.gmailService.enviarCorreo(
correoResponsable.subject,
emailResponsable,
correoResponsable.msj,
);
await this.gmailService.enviarCorreo(sendCorreoResponsableDto);
// Actualizar estado del servicio
await this.servicioRepo.update(idServicio, {
@@ -819,6 +830,15 @@ export class ServicioService {
let correoAlumno: any = {};
let emailResponsable = '';
const sendCorreoResponsableDto: SendMailDto = {
to: correoResponsable,
subject: correoResponsable.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoResponsable.msj,
html: '',
adjuntos: undefined,
};
const servicio = await this.servicioRepo.findOne({
where: { idServicio },
relations: ['usuario', 'programa', 'programa.usuario'],
@@ -827,6 +847,15 @@ export class ServicioService {
if (!servicio)
throw new NotFoundException('No existe este Servicio Social.');
const sendCorreoAlumnoDto: SendMailDto = {
to: servicio.correo,
subject: correoAlumno.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoAlumno.msj,
html: '',
adjuntos: undefined,
};
switch (servicio.status?.idStatus) {
case 5: {
correoAlumno = terminoRechazadoAlumno(mensaje, servicio.usuario.nombre);
@@ -836,11 +865,7 @@ export class ServicioService {
);
emailResponsable = servicio.programa.usuario.usuario; // correo responsable
await this.gmailService.enviarCorreo(
correoAlumno.subject,
servicio.correo,
correoAlumno.msj,
);
await this.gmailService.enviarCorreo(sendCorreoAlumnoDto);
break;
}
@@ -874,11 +899,7 @@ export class ServicioService {
}
// Enviar correo al responsable
await this.gmailService.enviarCorreo(
correoResponsable.subject,
emailResponsable,
correoResponsable.msj,
);
await this.gmailService.enviarCorreo(sendCorreoResponsableDto);
// Actualizar estado del servicio
await this.servicioRepo.update(idServicio, {
@@ -897,6 +918,15 @@ export class ServicioService {
let correoAlumno: any = {};
let emailResponsable = '';
const sendCorreoResponsableDto: SendMailDto = {
to: correoResponsable,
subject: correoResponsable.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoResponsable.msj,
html: '',
adjuntos: undefined,
};
const servicio = await this.servicioRepo.findOne({
where: { idServicio },
relations: ['usuario', 'programa', 'programa.usuario'],
@@ -905,6 +935,15 @@ export class ServicioService {
if (!servicio)
throw new NotFoundException('No existe este Servicio Social.');
const sendCorreoAlumnoDto: SendMailDto = {
to: servicio.correo,
subject: correoAlumno.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoAlumno.msj,
html: '',
adjuntos: undefined,
};
const idStatus = servicio.status?.idStatus;
switch (idStatus) {
@@ -916,11 +955,7 @@ export class ServicioService {
);
emailResponsable = servicio.programa.usuario.usuario;
await this.gmailService.enviarCorreo(
correoAlumno.subject,
servicio.correo,
correoAlumno.msj,
);
await this.gmailService.enviarCorreo(sendCorreoAlumnoDto);
break;
}
@@ -954,11 +989,7 @@ export class ServicioService {
}
// Enviar correo al responsable
await this.gmailService.enviarCorreo(
correoResponsable.subject,
emailResponsable,
correoResponsable.msj,
);
await this.gmailService.enviarCorreo(sendCorreoResponsableDto);
// Actualizar el servicio
await this.servicioRepo.update(idServicio, {
@@ -1054,6 +1085,24 @@ export class ServicioService {
let correoResponsable: any;
let emailResponsable: string;
const sendCorreoResponsableDto: SendMailDto = {
to: correoResponsable,
subject: correoResponsable.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoResponsable.msj,
html: '',
adjuntos: undefined,
};
const sendCorreoAlumnoDto: SendMailDto = {
to: servicio.correo,
subject: correoAlumno.subject,
fecha_recibido: new Date().toLocaleDateString(),
text: correoAlumno.msj,
html: '',
adjuntos: undefined,
};
switch (servicio.status.idStatus) {
case 2:
correoAlumno = registroValidadoAlumno(servicio.usuario.nombre);
@@ -1061,11 +1110,7 @@ export class ServicioService {
servicio.usuario.nombre,
);
emailResponsable = servicio.programa.usuario.usuario;
await this.gmailService.enviarCorreo(
correoAlumno.subject,
servicio.correo,
correoAlumno.msj,
);
await this.gmailService.enviarCorreo(sendCorreoAlumnoDto);
break;
case 1:
@@ -1097,11 +1142,7 @@ export class ServicioService {
throw new BadRequestException('Id status no válido.');
}
await this.gmailService.enviarCorreo(
correoResponsable.subject,
emailResponsable,
correoResponsable.msj,
);
await this.gmailService.enviarCorreo(sendCorreoResponsableDto);
// Determinar estatus según modo
const tempStatus = process.env.MODE === 'pruebas' ? 4 : 3;