57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
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 liberacion = async (body) => {
|
|
const idServicio = validar.validarId(body.idServicio);
|
|
const update = { idStatus: 6 };
|
|
let correo = {};
|
|
|
|
return Servicio.findOne({
|
|
where: { idServicio },
|
|
include: [{ model: Usuario }, { model: Programa }],
|
|
})
|
|
.then(async (res) => {
|
|
if (!res) throw new Error('No existe este Servicio Social.');
|
|
if (res.Programa.acatlan && !body.vistoBuenoAcatlan)
|
|
throw new Error(
|
|
'El programa de este Servicio Social es Acatlán Contigo y no se envio la variable validando este servicio.'
|
|
);
|
|
switch (res.idStatus) {
|
|
case 5:
|
|
correo = correos.terminoValidado(res.Usuario.nombre);
|
|
if (body.vistoBuenoAcatlan) update.vistoBuenoAcatlan = true;
|
|
return gmail(correo.subject, res.correo, correo.msj);
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
throw new Error(
|
|
'Este Servicio Social aun no puede pasar a Liberación.'
|
|
);
|
|
case 6:
|
|
throw new Error(
|
|
'Este Servicio Social ya se encuentra en Liberación.'
|
|
);
|
|
case 7:
|
|
case 8:
|
|
case 9:
|
|
throw new Error(
|
|
'Este Servicio Social se encuentra rechazado. No se puede aceptar hasta que se corriga lo necesario.'
|
|
);
|
|
case 10:
|
|
throw new Error('Este Servicio Social esta cancelado.');
|
|
}
|
|
})
|
|
.then((res) => Servicio.update(update, { where: { idServicio } }))
|
|
.then((res) => ({
|
|
message:
|
|
'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.',
|
|
}));
|
|
};
|
|
|
|
module.exports = liberacion;
|