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,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 {