Files
servicio_social_api/server/controller/Servicio/liberacion.js
T

69 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-03-01 19:14:04 -06:00
const moment = require('moment');
2021-05-05 18:49:23 -05:00
const helperPath = '../../helper';
const correos = require(`${helperPath}/correos`);
2021-05-13 14:06:07 -05:00
const gmail = require(`${helperPath}/gmail`);
const validar = require(`${helperPath}/validar`);
2021-05-05 18:49:23 -05:00
const dbPath = '../../db/tablas';
const Programa = require(`${dbPath}/Programa`);
const Servicio = require(`${dbPath}/Servicio`);
const Usuario = require(`${dbPath}/Usuario`);
2020-11-23 12:43:33 -06:00
const liberacion = async (body) => {
2022-01-02 15:07:49 -06:00
const idServicio = validar.validarNumeroEntero(
body.idServicio,
'id servicio'
);
2021-05-13 01:23:47 -05:00
const update = { idStatus: 6, fechaLiberacion: moment().format() };
2021-01-13 12:00:11 -06:00
let correo = {};
2020-11-23 12:43:33 -06:00
return Servicio.findOne({
where: { idServicio },
include: [{ model: Usuario }, { model: Programa }],
2020-11-23 12:43:33 -06:00
})
.then(async (res) => {
if (!res) throw new Error('No existe este Servicio Social.');
2021-01-14 03:13:37 -06:00
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.'
);
2020-11-23 12:43:33 -06:00
switch (res.idStatus) {
case 5:
2021-01-13 12:00:11 -06:00
correo = correos.terminoValidado(res.Usuario.nombre);
if (body.vistoBuenoAcatlan) update.vistoBuenoAcatlan = true;
2020-11-23 12:43:33 -06:00
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.');
default:
throw new Error('Id status no valido.');
2020-11-23 12:43:33 -06:00
}
})
2021-03-01 19:14:04 -06:00
.then((res) =>
Servicio.update(update, {
2021-04-05 15:24:18 -05:00
where: { idServicio },
2021-03-01 19:14:04 -06:00
})
)
2021-01-14 16:02:57 -06:00
.then((res) => ({
message:
'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.',
}));
2020-11-23 12:43:33 -06:00
};
module.exports = liberacion;