liberacion
This commit is contained in:
@@ -6,7 +6,7 @@ const Carrera = require('../../db/tablas/Carrera');
|
||||
const Status = require('../../db/tablas/Status');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const admin = (body) => {
|
||||
const admin = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
|
||||
return Servicio.findOne({
|
||||
|
||||
@@ -47,11 +47,11 @@ const cartaTermino = async (body, file) => {
|
||||
.then((res) => {
|
||||
return Servicio.update({ cartaTermino: res }, { where: { idServicio } });
|
||||
})
|
||||
.then(async (res) => {
|
||||
let message = `Se subio el informe global correctamente.`;
|
||||
|
||||
message += await validar.validarPreTermino(idServicio);
|
||||
return { message };
|
||||
.then((res) => {
|
||||
return validar.validarPreTermino(idServicio);
|
||||
})
|
||||
.then((res) => {
|
||||
return { message: `Se subio el informe global correctamente. ${res}` };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -48,10 +48,10 @@ const informeGlobal = async (body, file) => {
|
||||
return Servicio.update({ informeGlobal: res }, { where: { idServicio } });
|
||||
})
|
||||
.then(async (res) => {
|
||||
let message = `Se subio el informe global correctamente.`;
|
||||
|
||||
message += await validar.validarPreTermino(idServicio);
|
||||
return { message };
|
||||
return validar.validarPreTermino(idServicio);
|
||||
})
|
||||
.then((res) => {
|
||||
return { message: `Se subio el informe global correctamente. ${res}` };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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) => {
|
||||
let 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 5:
|
||||
let correo = correos.terminoValidado(res.Usuario.nombre);
|
||||
|
||||
return gmail(correo.subject, res.correo, correo.msj);
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
throw new Error(
|
||||
'Este Servicio Social aun no puede pasar a Liberación.'
|
||||
);
|
||||
case 6:
|
||||
throw new Error(
|
||||
'Este Servicio Social ya se encuentra en Liberación.'
|
||||
);
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
throw new Error(
|
||||
'Este Servicio Social se encuentra rechazado. No se puede aceptar hasta que se corriga lo necesario.'
|
||||
);
|
||||
case 10:
|
||||
throw new Error('Este Servicio Social esta cancelado.');
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
return Servicio.update({ idStatus: 6 }, { where: { idServicio } });
|
||||
})
|
||||
.then((res) => {
|
||||
return {
|
||||
message:
|
||||
'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = liberacion;
|
||||
@@ -7,25 +7,23 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const registro = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let password = '';
|
||||
let correo = {};
|
||||
let idUsuario = null;
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
include: [{ model: Usuario }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este servicio.');
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este Servicio Social.');
|
||||
|
||||
switch (res.idStatus) {
|
||||
case 1:
|
||||
let password = encriptar.generarPassword();
|
||||
let correo = correos.preRegistro(password, res.Usuario.nombre);
|
||||
|
||||
await gmail(correo.subject, res.correo, correo.msj);
|
||||
|
||||
return Usuario.update(
|
||||
{ password: encriptar.encriptar(password) },
|
||||
{ where: { idUsuario: res.idUsuario } }
|
||||
);
|
||||
password = encriptar.generarPassword();
|
||||
correo = correos.preRegistro(password, res.Usuario.nombre);
|
||||
idUsuario = res.idUsuario;
|
||||
return gmail(correo.subject, res.correo, correo.msj);
|
||||
case 2:
|
||||
throw new Error('Este Servicio Social ya se encuentra en Registro.');
|
||||
case 3:
|
||||
@@ -43,6 +41,12 @@ const registro = async (body) => {
|
||||
throw new Error('Este Servicio Social esta cancelado.');
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
return Usuario.update(
|
||||
{ password: encriptar.encriptar(password) },
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return Servicio.update({ idStatus: 2 }, { where: { idServicio } });
|
||||
})
|
||||
|
||||
@@ -10,6 +10,9 @@ const registroValidado = async (body) => {
|
||||
let fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
let telefono = validar.validarNumero(body.telefono, 10);
|
||||
let direccion = validar.validar(body.direccion, 'La dirección', 200);
|
||||
let correoAlumno = {};
|
||||
let correoResponsable = {};
|
||||
let emailResponsable = '';
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
@@ -18,27 +21,17 @@ const registroValidado = async (body) => {
|
||||
{ model: Programa, include: [{ model: Usuario }] },
|
||||
],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este servicio.');
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este Servicio Social.');
|
||||
|
||||
switch (res.idStatus) {
|
||||
case 2:
|
||||
let correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
|
||||
let correoResponsable = correos.registroValidadoResponsable(
|
||||
correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
|
||||
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 } }
|
||||
);
|
||||
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.'
|
||||
@@ -65,6 +58,19 @@ const registroValidado = async (body) => {
|
||||
);
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
return gmail(
|
||||
correoResponsable.subject,
|
||||
emailResponsable,
|
||||
correoResponsable.msj
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return Servicio.update(
|
||||
{ idStatus: 3, direccion, telefono, fechaNacimiento },
|
||||
{ where: { idServicio } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return {
|
||||
message:
|
||||
|
||||
@@ -97,8 +97,9 @@ const validarPreTermino = (idServicio) => {
|
||||
return false;
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) return '';
|
||||
return ' Se actualizo correctamente el status del Servicio Social.';
|
||||
if (res)
|
||||
return 'Este Servicio Social paso a Termino, espera a que COESI autorice tu liberación.';
|
||||
return '';
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ const registro = require('../controller/Servicio/registro');
|
||||
const registroValidado = require('../controller/Servicio/registroValidado');
|
||||
const cartaTermino = require('../controller/Servicio/cartaTermino');
|
||||
const informeGlobal = require('../controller/Servicio/informeGlobal');
|
||||
const liberacion = require('../controller/Servicio/liberacion');
|
||||
|
||||
app.post(`${route}/nuevo`, upload.single('cartaAceptacion'), (req, res) => {
|
||||
return nuevo(JSON.parse(req.body.alumno), req.file.filename)
|
||||
@@ -125,4 +126,14 @@ app.put(
|
||||
}
|
||||
);
|
||||
|
||||
app.put(`${route}/liberacion`, (req, res) => {
|
||||
return liberacion(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user