62 lines
2.1 KiB
JavaScript
62 lines
2.1 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 registroValidado = async (body) => {
|
|
let idServicio = validar.validarId(body.idServicio);
|
|
let fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
|
let telefono = validar.validarNumero(body.telefono, 10);
|
|
let direccion = validar.validar(body.direccion, 'La dirección', 200);
|
|
|
|
return Servicio.findOne({
|
|
where: { idServicio },
|
|
include: [
|
|
{ model: Usuario },
|
|
{ model: Programa, include: [{ model: Usuario }] },
|
|
],
|
|
})
|
|
.then(async (res) => {
|
|
if (!res) throw new Error('No existe este servicio.');
|
|
if (res.idStatus === 3)
|
|
throw new Error('Este servicio ya se encuentra en Registro Validado.');
|
|
else if (res.idStatus >= 7)
|
|
throw new Error(
|
|
'Este servicio se encuentra cancelado o rechazado. Comunicate con COESI para solucionar tu problema.'
|
|
);
|
|
else if (res.idStatus > 2)
|
|
throw new Error('Este servicio ya paso por el Registro Validado.');
|
|
else if (res.idStatus === 1)
|
|
throw new Error(
|
|
'Este servicio aun no puede pasar a Registro Validado.'
|
|
);
|
|
|
|
let correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
|
|
let correoResponsable = correos.registroValidadoResponsable(
|
|
res.Usuario.nombre
|
|
);
|
|
|
|
await gmail(correoAlumno.subject, res.correo, correoAlumno.msj);
|
|
await gmail(
|
|
correoResponsable.subject,
|
|
res.Programa.Usuario.usuario,
|
|
correoResponsable.msj
|
|
);
|
|
|
|
return Servicio.update(
|
|
{ idStatus: 3, direccion, telefono, fechaNacimiento },
|
|
{ where: { idServicio } }
|
|
);
|
|
})
|
|
.then((res) => {
|
|
return {
|
|
message:
|
|
'Se cambio de estatus correctamente y se envio un correo al alumno y al responsable de programa.',
|
|
};
|
|
});
|
|
};
|
|
|
|
module.exports = registroValidado;
|