83 lines
2.3 KiB
JavaScript
83 lines
2.3 KiB
JavaScript
const helperPath = '../../helper';
|
|
const correos = require(`${helperPath}/correos`);
|
|
const gmail = require(`${helperPath}/gmail`);
|
|
const validar = require(`${helperPath}/validar`);
|
|
const dbPath = '../../db/tablas';
|
|
const Programa = require(`${dbPath}/Programa`);
|
|
const Servicio = require(`${dbPath}/Servicio`);
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
|
|
|
const cancelar = async (body) => {
|
|
const idServicio = validar.validarNumeroEntero(
|
|
body.idServicio,
|
|
'id servicio'
|
|
);
|
|
const mensaje = validar.validarAlfanumerico(
|
|
body.mensaje,
|
|
'mensaje',
|
|
true,
|
|
800
|
|
);
|
|
let correoResponsable = {};
|
|
let correoAlumno = {};
|
|
let emailResponsable = '';
|
|
|
|
return Servicio.findOne({
|
|
where: { idServicio },
|
|
include: [
|
|
{ model: Usuario },
|
|
{ model: Programa, include: [{ model: Usuario }] },
|
|
],
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este Servicio Social.');
|
|
switch (res.idStatus) {
|
|
case 5:
|
|
correoAlumno = correos.terminoRechazadoAlumno(
|
|
mensaje,
|
|
res.Usuario.nombre
|
|
);
|
|
correoResponsable = correos.terminoRechazadoResponsable(
|
|
mensaje,
|
|
res.Usuario.nombre
|
|
);
|
|
emailResponsable = res.Programa.Usuario.usuario;
|
|
return gmail(correoAlumno.subject, res.correo, correoAlumno.msj);
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
throw new Error('Aun no se puede rechazar el Informe Global.');
|
|
case 6:
|
|
throw new Error('Este Servicio Social ya finalizó.');
|
|
case 7:
|
|
case 8:
|
|
throw new Error(
|
|
'No se puede rechazar el Informe Global en este punto del Servicio Social.'
|
|
);
|
|
case 9:
|
|
throw new Error(
|
|
'Este Servicio Social ya tiene el Informe Global rechazado.'
|
|
);
|
|
case 10:
|
|
throw new Error('Este Servicio Social fue cancelado.');
|
|
default:
|
|
throw new Error('Id status no valido.');
|
|
}
|
|
})
|
|
.then((res) =>
|
|
gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj)
|
|
)
|
|
.then((res) =>
|
|
Servicio.update(
|
|
{ idStatus: 9, informeGlobal: '' },
|
|
{ where: { idServicio } }
|
|
)
|
|
)
|
|
.then((res) => ({
|
|
message: 'Se rechazo correctamente el Informe Global.',
|
|
}));
|
|
};
|
|
|
|
module.exports = cancelar;
|