07ec951c8c
tablas de cuestionario
250 lines
6.8 KiB
JavaScript
250 lines
6.8 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const CuestionarioAlumno = require(`${dbPath}/CuestionarioAlumno`);
|
|
const CuestionarioPrograma2 = require(`${dbPath}/CuestionarioPrograma2`);
|
|
|
|
const Cuestionario = require(`${dbPath}/Cuestionario`);
|
|
const Servicio = require(`${dbPath}/Servicio`);
|
|
|
|
const nuevo = async (body) => {
|
|
// console.log(body);
|
|
|
|
let idServicio = body.idServicio;
|
|
/*
|
|
const idServicio = validar.validarNumeroEntero(
|
|
body.idServicio,
|
|
'id servicio'
|
|
); */
|
|
|
|
// pasar preguntas de array a string
|
|
|
|
return Servicio.findOne({ where: { idServicio } })
|
|
.then(async (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 programa'
|
|
); */
|
|
|
|
console.log('el servicio social si existe');
|
|
// console.log(res);
|
|
|
|
/**
|
|
* existe el servicio social?
|
|
* tiene cuestionario alumno en la tabla cuestionario? select * from cuestionario where idServicio = 1
|
|
* si no existe, entonces se puede crear el cuestionario
|
|
* creamos el cuestionario y guardamos las respuestas
|
|
*/
|
|
|
|
const messageByStatus = {
|
|
1: 'Aun no se puede contestar el cuestionario este Servicio Social.',
|
|
2: 'Aun no se puede contestar el cuestionario este Servicio Social.',
|
|
3: 'Aun no se puede contestar el cuestionario este Servicio Social.',
|
|
5: 'Este Servicio Social ya paso la fase de contestar el cuestionario.',
|
|
6: 'Este Servicio Social ya paso la fase de contestar el cuestionario.',
|
|
7: 'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corrija lo necesario.',
|
|
8: 'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corrija lo necesario.',
|
|
9: 'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corrija lo necesario.',
|
|
10: 'Este Servicio Social fue cancelado.',
|
|
};
|
|
|
|
// if (res.idStatus === 4) return CuestionarioPrograma2.create({ ...body });
|
|
console.log('antes de create ques2');
|
|
|
|
// if (res.idStatus) return CuestionarioPrograma2.create({ ...body });
|
|
// si idStatus está en el objeto, arrojamos el mensaje
|
|
/* if (messageByStatus.hasOwnProperty(res.idStatus))
|
|
throw new Error(messageByStatus[res.idStatus]); */
|
|
// throw new Error('Id status no valido.'); // si no coincide con nada, error por defecto
|
|
|
|
|
|
|
|
|
|
|
|
let dataCuestionario = await Cuestionario.findOne({
|
|
where: { idServicio, dirigidoA: 'programas' },
|
|
});
|
|
console.log('data cuestionario', dataCuestionario);
|
|
|
|
if (dataCuestionario) {
|
|
throw new Error('Ya existe un cuestionario para este servicio social');
|
|
}
|
|
|
|
|
|
|
|
|
|
let cuestionarioRegistro = await Cuestionario.create({
|
|
idServicio,
|
|
idCuestionarioPrograma: respuestasRegistradas.idCuestionarioPrograma,
|
|
version: '2',
|
|
dirigidoA: 'programas',
|
|
titulo: 'Cuestionario de programa v2',
|
|
desc: 'Cuestionario de programa v2',
|
|
createdAt: new Date(),
|
|
});
|
|
|
|
console.log('cuestionario registrado', cuestionarioRegistro);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let respuestasRegistradas = await CuestionarioPrograma2.create({
|
|
...body,
|
|
idCuestionario: cuestionarioRegistro.idCuestionario
|
|
});
|
|
|
|
console.log('despues de registrar cuestionario', respuestasRegistradas);
|
|
|
|
// si el cuestionario ya existe solo hay que actualizar el id de cuestionarioprograma o alumno
|
|
|
|
|
|
return cuestionarioRegistro;
|
|
})
|
|
|
|
.then((res) => ({
|
|
message: `Se guardaron tus respuestas correctamente. ${res}`,
|
|
}));
|
|
};
|
|
|
|
const convertirSTR = () => {
|
|
for (let i = 0; i < body.p3.length; i++) {
|
|
p3 += body.p3[i];
|
|
if (i < body.p3.length - 1) p3 += ',';
|
|
}
|
|
for (let i = 0; i < body.p5.length; i++) {
|
|
p5 += body.p5[i];
|
|
if (i < body.p5.length - 1) p5 += ',';
|
|
}
|
|
for (let i = 0; i < body.p8.length; i++) {
|
|
p8 += body.p8[i];
|
|
if (i < body.p8.length - 1) p8 += ',';
|
|
}
|
|
for (let i = 0; i < body.p14.length; i++) {
|
|
p14 += body.p14[i];
|
|
if (i < body.p14.length - 1) p14 += ',';
|
|
}
|
|
for (let i = 0; i < body.p15.length; i++) {
|
|
p15 += body.p15[i];
|
|
if (i < body.p15.length - 1) p15 += ',';
|
|
}
|
|
for (let i = 0; i < body.p17.length; i++) {
|
|
p17 += body.p17[i];
|
|
if (i < body.p17.length - 1) p17 += ',';
|
|
}
|
|
for (let i = 0; i < body.p21.length; i++) {
|
|
p21 += body.p21[i];
|
|
if (i < body.p21.length - 1) p21 += ',';
|
|
}
|
|
for (let i = 0; i < body.p22.length; i++) {
|
|
p22 += body.p22[i];
|
|
if (i < body.p22.length - 1) p22 += ',';
|
|
}
|
|
for (let i = 0; i < body.p23.length; i++) {
|
|
p23 += body.p23[i];
|
|
if (i < body.p23.length - 1) p23 += ',';
|
|
}
|
|
for (let i = 0; i < body.p24.length; i++) {
|
|
p24 += body.p24[i];
|
|
if (i < body.p24.length - 1) p24 += ',';
|
|
}
|
|
};
|
|
|
|
module.exports = nuevo;
|
|
|
|
/*
|
|
|
|
<!-- respuestas de cuestionario formulario2
|
|
todas las preguntas se guardan correctamente
|
|
{
|
|
"p3_A_1": "Deficiente",
|
|
"p3_A_2": "Deficiente",
|
|
"p3_A_3": "Deficiente",
|
|
"p3_A_4": "Deficiente",
|
|
"p3_B_1": "Básico",
|
|
"p3_B_2": "Básico",
|
|
"p3_B_3": "Básico",
|
|
"p3_B_4": "Básico",
|
|
"p3_C_1": "Intermedio",
|
|
"p3_C_2": "Intermedio",
|
|
"p3_C_3": "Intermedio",
|
|
"p3_C_4": "Intermedio",
|
|
"p3_C_5": "Intermedio",
|
|
"p3_D_1": "Destacado",
|
|
"p3_D_2": "Destacado",
|
|
"p3_D_3": "Destacado",
|
|
"p3_D_4": "Destacado",
|
|
"p3_D_5": "Destacado",
|
|
"p3_E_1": "Deficiente",
|
|
"p1": "respuesta1",
|
|
"p2": "Excelente",
|
|
"p4": "respuesta4",
|
|
"p5": "Sí",
|
|
"p6": "respuesta 6"
|
|
}
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<!-- respuestas de cuestionario formulario alumno
|
|
|
|
|
|
{
|
|
"p1": [
|
|
"Dependencia de la UNAM",
|
|
"Asesoría académica",
|
|
"Oportunidad de desarrollo de tesis"
|
|
],
|
|
"p12_A_1": "Deficiente",
|
|
"p12_A_2": "Deficiente",
|
|
"p12_A_3": "Deficiente",
|
|
"p12_A_4": "Deficiente",
|
|
"p12_B_1": "Básico",
|
|
"p12_B_2": "Básico",
|
|
"p12_B_3": "Básico",
|
|
"p12_B_4": "Básico",
|
|
"p12_C_1": "Intermedio",
|
|
"p12_C_2": "Intermedio",
|
|
"p12_C_3": "Intermedio",
|
|
"p12_C_4": "Intermedio",
|
|
"p10_1": "si",
|
|
"p10_2": "si",
|
|
"p10_3": "si",
|
|
"p11_1": "Nunca",
|
|
"p11_2": "Rara vez",
|
|
"p11_3": "Algunas veces",
|
|
"p11_4": "Siempre",
|
|
"p17_1": "si",
|
|
"p17_2": "no",
|
|
"p17_3": "si",
|
|
"p3_1": "si",
|
|
"p3_2": "si",
|
|
"p3_3": "si",
|
|
"p3_4": "si",
|
|
"p12_D_1": "Destacado",
|
|
"p12_D_2": "Destacado",
|
|
"p12_D_3": "Destacado",
|
|
"p12_D_4": "Destacado",
|
|
"p12_D_5": "Destacado",
|
|
"p2": "Deficiente",
|
|
"p4": "No",
|
|
"p5": "respuesta5",
|
|
"p6": "Sí",
|
|
"p7": "Sí",
|
|
"p8": "respuesta8",
|
|
"p9": "Sí",
|
|
"p13": "Responsable directo del programa",
|
|
"p14": "Se te otorgó de acuerdo a lo establecido",
|
|
"p15": "Sí",
|
|
"p16": "respuesta 16",
|
|
"p18": "respuesta18"
|
|
}
|
|
|
|
|
|
-->
|
|
|
|
*/
|