subri carta de termino e informe global listo

This commit is contained in:
2020-11-23 00:52:38 -06:00
parent 2ae79c3962
commit 7973212dbb
10 changed files with 247 additions and 44 deletions
@@ -0,0 +1,7 @@
const validar = require('../../helper/validar');
const CuestionarioAlumno = require('../../db/tablas/CuestionarioAlumno');
const Servicio = require('../../db/tablas/Servicio');
const nuevo = async (body) => {};
module.exports = nuevo;
@@ -0,0 +1,7 @@
const validar = require('../../helper/validar');
const CuestionarioPrograma = require('../../db/tablas/CuestionarioPrograma');
const Servicio = require('../../db/tablas/Servicio');
const nuevo = async (body) => {};
module.exports = nuevo;
@@ -0,0 +1,58 @@
const validar = require('../../helper/validar');
const drive = require('../../helper/drive');
const Servicio = require('../../db/tablas/Servicio');
const cartaTermino = async (body, file) => {
let idServicio = validar.validarId(body.idServicio);
return Servicio.findOne({
where: { idServicio },
})
.then((res) => {
if (!res) throw new Error('Este servicio no existe.');
if (res.cartaTermino) throw new Error('Ya se subio la carta de termino.');
switch (res.idStatus) {
case 4:
case 8:
let path = `./server/uploads/${validar.validar(file, 'El archivo')}`;
return drive.uploadFile(
path,
`Carta_Termino.pdf`,
'application/pdf',
res.carpeta
);
case 1:
case 2:
case 3:
throw new Error(
'Aun no se puede subir la carta de termino a este Servicio Social.'
);
case 5:
case 6:
throw new Error(
'Este Servicio Social ya paso la fase de subir la carta de termino.'
);
case 7:
case 9:
throw new Error(
'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corriga lo necesario.'
);
case 10:
throw new Error('Este Servicio Social esta cancelado.');
}
})
.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 };
});
};
module.exports = cartaTermino;
@@ -0,0 +1,58 @@
const validar = require('../../helper/validar');
const drive = require('../../helper/drive');
const Servicio = require('../../db/tablas/Servicio');
const informeGlobal = async (body, file) => {
let idServicio = validar.validarId(body.idServicio);
return Servicio.findOne({
where: { idServicio },
})
.then((res) => {
if (!res) throw new Error('Este servicio no existe.');
if (res.informeGlobal) throw new Error('Ya se subio el informe global.');
switch (res.idStatus) {
case 4:
case 9:
let path = `./server/uploads/${validar.validar(file, 'El archivo')}`;
return drive.uploadFile(
path,
`Informe_Global.pdf`,
'application/pdf',
res.carpeta
);
case 1:
case 2:
case 3:
throw new Error(
'Aun no se puede subir el informe global a este Servicio Social.'
);
case 5:
case 6:
throw new Error(
'Este Servicio Social ya paso la fase de subir el informe global.'
);
case 7:
case 8:
throw new Error(
'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corriga lo necesario.'
);
case 10:
throw new Error('Este Servicio Social esta cancelado.');
}
})
.then((res) => {
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 };
});
};
module.exports = informeGlobal;
+3 -1
View File
@@ -12,10 +12,12 @@ const nuevo = async (body, file) => {
let idCarrera = validar.validarId(body.idCarrera);
return Usuario.findOne({
where: { idUsuario, idTipoUsuario: 3 },
where: { idUsuario },
})
.then((res) => {
if (!res) throw new Error('Este alumno no existe en la db.');
if (res.idTipoUsuario === 3)
throw new Error('Este usuario no es de tipo Alumno.');
return Programa.findOne({ where: { idPrograma } });
})
.then((res) => {
+25 -15
View File
@@ -14,24 +14,34 @@ const registro = async (body) => {
})
.then(async (res) => {
if (!res) throw new Error('No existe este servicio.');
if (res.idStatus === 2)
throw new Error('Este servicio ya se encuentra en Registro.');
else if (res.idStatus >= 7)
throw new Error(
'Este servicio se encuentra cancelado o rechazado. No se puede aceptar hasta que se corriga lo necesario.'
);
else if (res.idStatus > 1)
throw new Error('Este servicio ya paso por el Registro.');
let password = encriptar.generarPassword();
let correo = correos.preRegistro(password, res.Usuario.nombre);
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);
await gmail(correo.subject, res.correo, correo.msj);
return Usuario.update(
{ password: encriptar.encriptar(password) },
{ where: { idUsuario: res.idUsuario } }
);
return Usuario.update(
{ password: encriptar.encriptar(password) },
{ where: { idUsuario: res.idUsuario } }
);
case 2:
throw new Error('Este Servicio Social ya se encuentra en Registro.');
case 3:
case 4:
case 5:
case 6:
throw new Error('Este Servicio Social ya paso por el Registro.');
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: 2 }, { where: { idServicio } });
+41 -26
View File
@@ -20,35 +20,50 @@ const registroValidado = async (body) => {
})
.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
);
switch (res.idStatus) {
case 2:
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
);
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 } }
);
return Servicio.update(
{ idStatus: 3, direccion, telefono, fechaNacimiento },
{ where: { idServicio } }
);
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:
case 6:
throw new Error(
'Este Servicio Social ya paso por el Registro Validado.'
);
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 esta cancelado. Comunicate con COESI para solucionar tu problema.'
);
}
})
.then((res) => {
return {
+1 -1
View File
@@ -91,7 +91,7 @@ const dataStatus = async () => {
'Liberación',
'Carta Aceptación Rechazada',
'Carta Termino Rechazada',
'Informe General Rechazada',
'Informe Global Rechazado',
'Cancelado',
];
+21 -1
View File
@@ -1,5 +1,6 @@
const validator = require('validator');
const moment = require('moment');
const validator = require('validator');
const Servicio = require('../db/tablas/Servicio');
const noValido = (campo) => {
throw new Error(`${campo} no es valido.`);
@@ -83,6 +84,24 @@ const validarNumero = (numero, length) => {
return numero;
};
const validarPreTermino = (idServicio) => {
return Servicio.findOne({ where: { idServicio } })
.then((res) => {
if (
res.idCuestionarioPrograma &&
res.idCuestionarioAlumno &&
res.cartaTermino &&
res.informeGlobal
)
return Servicio.update({ idStatus: 5 }, { where: { idServicio } });
return false;
})
.then((res) => {
if (!res) return '';
return ' Se actualizo correctamente el status del Servicio Social.';
});
};
module.exports = {
validar,
noValido,
@@ -94,4 +113,5 @@ module.exports = {
validarNumeroCuenta,
validarFecha,
validarNumero,
validarPreTermino,
};
+26
View File
@@ -11,6 +11,8 @@ const alumno = require('../controller/Servicio/alumno');
const cancelar = require('../controller/Servicio/cancelar');
const registro = require('../controller/Servicio/registro');
const registroValidado = require('../controller/Servicio/registroValidado');
const cartaTermino = require('../controller/Servicio/cartaTermino');
const informeGlobal = require('../controller/Servicio/informeGlobal');
app.post(`${route}/nuevo`, upload.single('cartaAceptacion'), (req, res) => {
return nuevo(JSON.parse(req.body.alumno), req.file.filename)
@@ -92,4 +94,28 @@ app.put(`${route}/registro_validado`, (req, res) => {
});
});
app.put(`${route}/carta_termino`, upload.single('cartaTermino'), (req, res) => {
return cartaTermino(JSON.parse(req.body.data), req.file.filename)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
app.put(
`${route}/informe_global`,
upload.single('informeGlobal'),
(req, res) => {
return informeGlobal(JSON.parse(req.body.data), req.file.filename)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
}
);
module.exports = app;