72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const CuestionarioPrograma = require('../../db/tablas/CuestionarioPrograma');
|
|
const Servicio = require('../../db/tablas/Servicio');
|
|
|
|
const nuevo = async (body) => {
|
|
let idServicio = validar.validarId(body.idServicio);
|
|
// let actividad1 = body.asnwers.actividad1;
|
|
// let actividad2 = body.asnwers.actividad2;
|
|
// let actividad3 = body.asnwers.actividad3;
|
|
// let actividad4 = body.asnwers.actividad4;
|
|
// let actividad5 = body.asnwers.actividad5;
|
|
// let retroalimentacion = body.asnwers.retroalimentacion;
|
|
// let p6 = body.asnwers.p6;
|
|
// let p7 = body.asnwers.p7;
|
|
|
|
return Servicio.findOne({ where: { idServicio } })
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este Servicio Social.');
|
|
if (res.idCuestionarioPrograma)
|
|
throw new Error(
|
|
'Este Servicio Social ya cuenta con cuestionario de programa'
|
|
);
|
|
switch (res.idStatus) {
|
|
case 4:
|
|
return CuestionarioPrograma.create({
|
|
actividad1: '',
|
|
actividad2: '',
|
|
actividad3: '',
|
|
actividad4: '',
|
|
actividad5: '',
|
|
retroalimentacion: '',
|
|
p6: '',
|
|
p7: '',
|
|
});
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
throw new Error(
|
|
'Aun no se puede contestar el cuestionario este Servicio Social.'
|
|
);
|
|
case 5:
|
|
throw new Error(
|
|
'Este Servicio Social ya paso la fase de contestar el cuestionario.'
|
|
);
|
|
case 6:
|
|
throw new Error('Este Servicio Social ya finalizó.');
|
|
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(
|
|
{ idCuestionarioPrograma: res.idCuestionarioPrograma },
|
|
{ where: { idServicio } }
|
|
);
|
|
})
|
|
.then((res) => {
|
|
return validar.validarPreTermino(idServicio);
|
|
})
|
|
.then((res) => {
|
|
return { message: `Se guradaron tus respuestas correctamente. ${res}` };
|
|
});
|
|
};
|
|
|
|
module.exports = nuevo;
|