rechazar carta aceptación, termino e informe global
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correos = require('../../helper/correos');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const cancelar = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
let correoResponsable = {};
|
||||
let emailResponsable = '';
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
include: [{ model: Programa, include: [{ model: Usuario }] }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este Servicio Social.');
|
||||
switch (res.idStatus) {
|
||||
case 5:
|
||||
let 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.');
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
return gmail(
|
||||
correoResponsable.subject,
|
||||
emailResponsable,
|
||||
correoResponsable.msj
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return Servicio.update({ idStatus: 9 }, { where: { idServicio } });
|
||||
})
|
||||
.then((res) => {
|
||||
return { message: 'Se rechazo correctamente el Informe Global.' };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = cancelar;
|
||||
Reference in New Issue
Block a user