liberacion y obtener servicios especiales listo

This commit is contained in:
2021-02-10 01:59:57 -06:00
parent 1ef5cc8a07
commit 027fddf9cc
15 changed files with 117 additions and 0 deletions
@@ -0,0 +1,37 @@
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 liberacion = async (body) => {
const idServicio = validar.validarId(body.idServicio);
return Servicio.findOne({
where: { idServicio },
include: [{ model: Usuario }],
})
.then(async (res) => {
if (!res) throw new Error('No existe este Servicio Social.');
switch (res.idStatus) {
case 11:
case 12:
let correo = correos.terminoValidado(res.Usuario.nombre);
return gmail(correo.subject, res.correo, correo.msj);
case 6:
throw new Error(
'Este Servicio Social ya se encuentra en Liberación.'
);
default:
throw new Error('Id status no valido.');
}
})
.then((res) => Servicio.update({ idStatus: 6 }, { where: { idServicio } }))
.then((res) => ({
message:
'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.',
}));
};
module.exports = liberacion;
@@ -0,0 +1,58 @@
const { Op } = require('sequelize');
const validar = require('../../helper/validar');
const CasoEspecial = require('../../db/tablas/CasoEspecial');
const Usuario = require('../../db/tablas/Usuario');
const Carrera = require('../../db/tablas/Carrera');
const Status = require('../../db/tablas/Status');
const TipoUsuario = require('../../db/tablas/TipoUsuario');
const serviciosEspeciales = async (body) => {
const pagina = validar.validarId(body.pagina);
const where = body.idStatus
? { idStatus: validar.validarId(body.idStatus) }
: { [Op.or]: [{ idStatus: 6 }, { idStatus: { [Op.gt]: 10 } }] };
const nombre = body.nombre
? validar.validarTexto(body.nombre, 'El nombre', 60)
: '';
const numeroCuenta = body.numeroCuenta
? validar.validarNumeroCuenta(body.numeroCuenta)
: '';
const data = [];
return CasoEspecial.findAll({
include: [
{
model: Usuario,
include: { model: TipoUsuario },
where: {
usuario: { [Op.like]: `%${numeroCuenta}%` },
nombre: { [Op.like]: `%${nombre}%` },
},
},
{ model: Carrera },
{ model: Status, where },
],
order: [['updatedAt', 'DESC']],
}).then((res) => {
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
data.push({
idServicio: res[i].idServicio,
createdAt: res[i].createdAt,
Usuario: {
idUsuario: res[i].Usuario.idUsuario,
usuario: res[i].Usuario.usuario,
nombre: res[i].Usuario.nombre,
TipoUsuario: res[i].Usuario.TipoUsuario,
},
Carrera: res[i].Carrera,
Status: res[i].Status,
});
return {
registros: res.length,
faltantes: res.length - data.length - (pagina - 1) * 25,
servicios: data,
};
});
};
module.exports = serviciosEspeciales;
@@ -141,6 +141,8 @@ const nuevo = async (body) => {
);
case 10:
throw new Error('Este Servicio Social fue cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
@@ -56,6 +56,8 @@ const nuevo = async (body) => {
);
case 10:
throw new Error('Este Servicio Social fue cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
@@ -43,6 +43,8 @@ const cartaTermino = async (body, file) => {
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) =>
@@ -42,6 +42,8 @@ const cartaTermino = async (body, file) => {
throw new Error(
'Este Servicio Social esta cancelado. Comunicate con COESI para solucionar tu problema.'
);
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
@@ -42,6 +42,8 @@ const informeGlobal = async (body, file) => {
throw new Error(
'Este Servicio Social esta cancelado. Comunicate con COESI para solucionar tu problema.'
);
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
+2
View File
@@ -44,6 +44,8 @@ const liberacion = async (body) => {
);
case 10:
throw new Error('Este Servicio Social esta cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) => Servicio.update(update, { where: { idServicio } }))
@@ -50,6 +50,8 @@ const cancelar = async (body) => {
);
case 10:
throw new Error('Este Servicio Social fue cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
@@ -51,6 +51,8 @@ const cancelar = async (body) => {
);
case 10:
throw new Error('Este Servicio Social fue cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
@@ -51,6 +51,8 @@ const cancelar = async (body) => {
);
case 10:
throw new Error('Este Servicio Social fue cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
+2
View File
@@ -39,6 +39,8 @@ const registro = async (body) => {
);
case 10:
throw new Error('Este Servicio Social fue cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) => {
@@ -60,6 +60,8 @@ const registroValidado = async (body) => {
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) =>