Files

95 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

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-22 21:05:50 -06:00
const registroValidado = async (body) => {
2022-01-02 15:07:49 -06:00
const idServicio = validar.validarNumeroEntero(
body.idServicio,
'id servicio'
);
2022-01-02 17:56:42 -06:00
const fechaNacimiento = validar.validarFecha(
body.fechaNacimiento,
'fecha de nacimiento',
false
);
2022-01-02 18:25:31 -06:00
const telefono = validar.validarNumero(body.telefono, 'teléfono', true, 15);
2021-01-14 03:13:37 -06:00
const direccion = validar.validarAlfanumerico(
body.direccion,
2022-01-02 17:45:29 -06:00
'dirección',
false,
200
);
2020-11-23 12:43:33 -06:00
let correoResponsable = {};
2021-01-13 12:00:11 -06:00
let correoAlumno = {};
2020-11-23 12:43:33 -06:00
let emailResponsable = '';
2020-11-22 21:05:50 -06:00
return Servicio.findOne({
where: { idServicio },
include: [
{ model: Usuario },
{ model: Programa, include: [{ model: Usuario }] },
],
})
2020-11-23 12:43:33 -06:00
.then((res) => {
if (!res) throw new Error('No existe este Servicio Social.');
switch (res.idStatus) {
case 2:
2021-01-13 12:00:11 -06:00
correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
2020-11-23 12:43:33 -06:00
correoResponsable = correos.registroValidadoResponsable(
res.Usuario.nombre
);
2020-11-23 12:43:33 -06:00
emailResponsable = res.Programa.Usuario.usuario;
return gmail(correoAlumno.subject, res.correo, correoAlumno.msj);
case 1:
throw new Error(
'Este Servicio Social aun no puede pasar a Registro Validado.'
);
case 3:
throw new Error(
'Este servicio ya se encuentra en Registro Validado.'
);
case 4:
case 5:
throw new Error(
'Este Servicio Social ya paso por el Registro Validado.'
);
case 6:
throw new Error('Este Servicio Social ya finalizó.');
case 7:
case 8:
case 9:
throw new Error(
'Este Servicio Social se encuentra rechazado. Comunicate con COESI para solucionar tu problema.'
);
case 10:
throw new Error(
'Este Servicio Social fue cancelado. Comunicate con COESI para solucionar tu problema.'
);
default:
throw new Error('Id status no valido.');
}
2020-11-22 21:05:50 -06:00
})
2021-01-13 12:00:11 -06:00
.then((res) =>
gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj)
)
.then((res) =>
Servicio.update(
2021-01-14 03:13:37 -06:00
// Producción
2021-01-27 21:15:22 -06:00
{ idStatus: 3, direccion, telefono, fechaNacimiento },
2021-01-14 03:13:37 -06:00
// Pruebas
2021-01-27 21:15:22 -06:00
// { idStatus: 4, direccion, telefono, fechaNacimiento },
2020-11-23 12:43:33 -06:00
{ where: { idServicio } }
2021-01-13 12:00:11 -06:00
)
)
2021-01-14 16:02:57 -06:00
.then((res) => ({
message: 'Haz terminado el registro de tu Servicio Social correctamente.',
}));
2020-11-22 21:05:50 -06:00
};
module.exports = registroValidado;