44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
const helperPath = '../../helper';
|
|
const correos = require(`${helperPath}/correos`);
|
|
const gmail = require(`${helperPath}/gmail`);
|
|
const { validarNumeroEntero } = require(`${helperPath}/validar`);
|
|
const dbPath = '../../db/tablas';
|
|
const CasoEspecial = require(`${dbPath}/CasoEspecial`);
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
|
|
|
const liberacion = async (body) => {
|
|
const idCasoEspecial = validarNumeroEntero(
|
|
body.idCasoEspecial,
|
|
'id caso especial'
|
|
);
|
|
let update = {};
|
|
|
|
return CasoEspecial.findOne({
|
|
where: { idCasoEspecial },
|
|
include: [{ model: Usuario }],
|
|
})
|
|
.then(async (res) => {
|
|
if (!res) throw new Error('No existe este Caso Especial.');
|
|
switch (res.idStatus) {
|
|
case 11:
|
|
case 12:
|
|
let correo = correos.terminoValidado(res.Usuario.nombre);
|
|
|
|
if (res.idStatus === 11) update.idStatus = 13;
|
|
else update.idStatus = 14;
|
|
return gmail(correo.subject, res.correo, correo.msj);
|
|
case 6:
|
|
throw new Error('Este Caso Especial ya se encuentra en Liberación.');
|
|
default:
|
|
throw new Error('Id status no valido.');
|
|
}
|
|
})
|
|
.then((res) => CasoEspecial.update(update, { where: { idCasoEspecial } }))
|
|
.then((res) => ({
|
|
message:
|
|
'Se cambió de estatus correctamente y se envió un correo al alumno informandole de su liberación.',
|
|
}));
|
|
};
|
|
|
|
module.exports = liberacion;
|