recibir el mensaje de cancelación y enviar correo a alumno y responsable
This commit is contained in:
@@ -1,17 +1,52 @@
|
||||
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 cancelar = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
let correoResponsable = {};
|
||||
let emailResponsable = '';
|
||||
let idUsuario;
|
||||
|
||||
return Servicio.findOne({ where: { idServicio } })
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
include: [{ model: Programa, include: [{ model: Usuario }] }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este servicio.');
|
||||
if (res.idStatus === 10)
|
||||
throw new Error('Este servicio ya fue cancelado');
|
||||
return Usuario.update({ activo: false }, { where: res.idUsuario });
|
||||
throw new Error('Este Servicio Social ya fue cancelado.');
|
||||
if (res.idStatus === 6)
|
||||
throw new Error(
|
||||
'Este Servicio Social ya fue finalizado, no se puede cancelar.'
|
||||
);
|
||||
|
||||
let correoAlumno = correos.canceladoAlumno(mensaje, res.Usuario.nombre);
|
||||
|
||||
idUsuario = res.idUsuario;
|
||||
correoResponsable = correos.canceladoResponsable(
|
||||
mensaje,
|
||||
res.Usuario.nombre
|
||||
);
|
||||
emailResponsable = res.Programa.Usuario.usuario;
|
||||
return gmail(correoAlumno.subject, res.correo, correoAlumno.msj);
|
||||
})
|
||||
.then((res) => {
|
||||
return gmail(
|
||||
correoResponsable.subject,
|
||||
emailResponsable,
|
||||
correoResponsable.msj
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return Usuario.update(
|
||||
{ activo: false, password: null },
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return Servicio.update({ idStatus: 10 }, { where: { idServicio } });
|
||||
|
||||
@@ -9,8 +9,11 @@ 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.validarAlfanumerico(body.direccion, 'La dirección', 200);
|
||||
let correoAlumno = {};
|
||||
let direccion = validar.validarAlfanumerico(
|
||||
body.direccion,
|
||||
'La dirección',
|
||||
200
|
||||
);
|
||||
let correoResponsable = {};
|
||||
let emailResponsable = '';
|
||||
|
||||
@@ -26,7 +29,8 @@ const registroValidado = async (body) => {
|
||||
|
||||
switch (res.idStatus) {
|
||||
case 2:
|
||||
correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
|
||||
let correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
|
||||
|
||||
correoResponsable = correos.registroValidadoResponsable(
|
||||
res.Usuario.nombre
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user