80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const CuestionarioPrograma = require(`${dbPath}/CuestionarioPrograma`);
|
|
const Servicio = require(`${dbPath}/Servicio`);
|
|
|
|
const nuevo = async (body) => {
|
|
const idServicio = validar.validarNumeroEntero(
|
|
body.idServicio,
|
|
'id servicio'
|
|
);
|
|
const actividad1 = body.actividad1;
|
|
const actividad2 = body.actividad2;
|
|
const actividad3 = body.actividad3;
|
|
const actividad4 = body.actividad4;
|
|
const actividad5 = body.actividad5;
|
|
const p6 = body.p6;
|
|
const p7 = body.p7;
|
|
let retroalimentacion = '';
|
|
|
|
for (let i = 0; i < body.retroalimentacion.length; i++) {
|
|
retroalimentacion += body.retroalimentacion[i];
|
|
if (i < body.retroalimentacion.length - 1) retroalimentacion += ',';
|
|
}
|
|
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.');
|
|
default:
|
|
throw new Error('Id status no valido.');
|
|
}
|
|
})
|
|
.then((res) =>
|
|
Servicio.update(
|
|
{ idCuestionarioPrograma: res.idCuestionarioPrograma },
|
|
{ where: { idServicio } }
|
|
)
|
|
)
|
|
.then((res) => validar.validarPreTermino(idServicio))
|
|
.then((res) => ({
|
|
message: `Se guradaron tus respuestas correctamente. ${res}`,
|
|
}));
|
|
};
|
|
|
|
module.exports = nuevo;
|