122 lines
3.0 KiB
JavaScript
122 lines
3.0 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const CuestionarioAlumno = require('../../db/tablas/CuestionarioAlumno');
|
|
const Servicio = require('../../db/tablas/Servicio');
|
|
|
|
const nuevo = async (body) => {
|
|
let idServicio = validar.validarId(body.idServicio);
|
|
|
|
let sexo = '';
|
|
let edad = '';
|
|
let servicioMedico = '';
|
|
let pUno = '';
|
|
let pDos = '';
|
|
let pTres = '';
|
|
let pCuatro = '';
|
|
let pCinco = '';
|
|
let pSeis = '';
|
|
let pSiete = '';
|
|
let pOcho = '';
|
|
let pNueve = '';
|
|
let pDiez = '';
|
|
let pOnce = '';
|
|
let pDoce = '';
|
|
let pTrece = '';
|
|
let pCatorce = '';
|
|
let pQuince = '';
|
|
let pDieciseis = '';
|
|
let pDiecisiete = '';
|
|
let pDieciocho = '';
|
|
let pDiecinueve = '';
|
|
let pVeinte = '';
|
|
let pVeintiuno = '';
|
|
let pVeintidos = '';
|
|
let pVeintitres = '';
|
|
let pVeinticuatro = '';
|
|
let pVeinticinco = '';
|
|
let pVeintiseis = '';
|
|
let pVeintisiete = '';
|
|
let pVeintiocho = '';
|
|
let pVeintinueve = '';
|
|
let pTreinta = '';
|
|
|
|
return Servicio.findOne({ where: { idServicio } })
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este Servicio Social.');
|
|
if (res.idCuestionarioAlumno)
|
|
throw new Error(
|
|
'Este Servicio Social ya cuenta con cuestionario de alumno'
|
|
);
|
|
switch (res.idStatus) {
|
|
case 4:
|
|
return CuestionarioAlumno.create({
|
|
sexo,
|
|
edad,
|
|
servicioMedico,
|
|
pUno,
|
|
pDos,
|
|
pTres,
|
|
pCuatro,
|
|
pCinco,
|
|
pSeis,
|
|
pSiete,
|
|
pOcho,
|
|
pNueve,
|
|
pDiez,
|
|
pOnce,
|
|
pDoce,
|
|
pTrece,
|
|
pCatorce,
|
|
pQuince,
|
|
pDieciseis,
|
|
pDiecisiete,
|
|
pDieciocho,
|
|
pDiecinueve,
|
|
pVeinte,
|
|
pVeintiuno,
|
|
pVeintidos,
|
|
pVeintitres,
|
|
pVeinticuatro,
|
|
pVeinticinco,
|
|
pVeintiseis,
|
|
pVeintisiete,
|
|
pVeintiocho,
|
|
pVeintinueve,
|
|
pTreinta,
|
|
});
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
throw new Error(
|
|
'Aun no se puede contestar el cuestionario este Servicio Social.'
|
|
);
|
|
case 5:
|
|
case 6:
|
|
throw new Error(
|
|
'Este Servicio Social ya paso la fase de contestar el cuestionario.'
|
|
);
|
|
case 7:
|
|
case 8:
|
|
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 fue cancelado.');
|
|
}
|
|
})
|
|
.then((res) => {
|
|
return Servicio.update(
|
|
{ idCuestionarioAlumno: res.idCuestionarioAlumno },
|
|
{ where: { idServicio } }
|
|
);
|
|
})
|
|
.then((res) => {
|
|
return validar.validarPreTermino(idServicio);
|
|
})
|
|
.then((res) => {
|
|
return { message: `Se guardaron tus respuestas correctamente. ${res}` };
|
|
});
|
|
};
|
|
|
|
module.exports = nuevo;
|