101 lines
3.0 KiB
JavaScript
101 lines
3.0 KiB
JavaScript
const helperPath = '../../helper';
|
|
const correos = require(`${helperPath}/correos`);
|
|
const gmail = require(`${helperPath}/gmail`);
|
|
const validar = require(`${helperPath}/validar`);
|
|
const dbPath = '../../db/tablas';
|
|
const Programa = require(`${dbPath}/Programa`);
|
|
const Servicio = require(`${dbPath}/Servicio`);
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
|
|
|
const registroValidado = async (body) => {
|
|
const idServicio = validar.validarNumeroEntero(
|
|
body.idServicio,
|
|
'id servicio'
|
|
);
|
|
const fechaNacimiento = validar.validarFecha(
|
|
body.fechaNacimiento,
|
|
'fecha de nacimiento',
|
|
false
|
|
);
|
|
const telefono = validar.validarNumero(body.telefono, 'teléfono', true, 15);
|
|
const direccion = validar.validarAlfanumerico(
|
|
body.direccion,
|
|
'dirección',
|
|
false,
|
|
200
|
|
);
|
|
let correoResponsable = {};
|
|
let correoAlumno = {};
|
|
let emailResponsable = '';
|
|
|
|
return Servicio.findOne({
|
|
where: { idServicio },
|
|
include: [
|
|
{ model: Usuario },
|
|
{ model: Programa, include: [{ model: Usuario }] },
|
|
],
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este Servicio Social.');
|
|
switch (res.idStatus) {
|
|
case 2:
|
|
correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
|
|
correoResponsable = correos.registroValidadoResponsable(
|
|
res.Usuario.nombre
|
|
);
|
|
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.');
|
|
}
|
|
})
|
|
.then((res) =>
|
|
gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj)
|
|
)
|
|
.then((res) =>
|
|
{
|
|
|
|
let tempStatus = 3
|
|
if (process.env.MODE == "pruebas") tempStatus = 4
|
|
|
|
return Servicio.update(
|
|
// Producción
|
|
// { idStatus: 3, direccion, telefono, fechaNacimiento },
|
|
// Pruebas
|
|
{ idStatus: tempStatus, direccion, telefono, fechaNacimiento },
|
|
{ where: { idServicio } }
|
|
)
|
|
}
|
|
)
|
|
.then((res) => ({
|
|
message: 'Haz terminado el registro de tu Servicio Social correctamente.',
|
|
}));
|
|
};
|
|
|
|
module.exports = registroValidado;
|