cambio en guardar el id del cuestionario en las
tablas de cuestionario
This commit is contained in:
@@ -66,7 +66,7 @@ const nuevo = async (body) => {
|
||||
|
||||
// throw new Error('Id status no valido.'); // si no coincide con nada, error por defecto
|
||||
|
||||
Cuestionario.findOne({});
|
||||
// Cuestionario.findOne({});
|
||||
|
||||
let dataCuestionario = await Cuestionario.findOne({
|
||||
where: { idServicio, dirigidoA: 'estudiantes' },
|
||||
@@ -77,12 +77,10 @@ const nuevo = async (body) => {
|
||||
throw new Error('Ya existe un cuestionario para este servicio social');
|
||||
}
|
||||
|
||||
let respuestasRegistradas = await CuestionarioAlumno2.create({ ...body });
|
||||
console.log('despues de registrar cuestionario', respuestasRegistradas);
|
||||
|
||||
let cuestionarioRegistro = await Cuestionario.create({
|
||||
idServicio,
|
||||
idCuestionarioAlumno: respuestasRegistradas.idCuestionarioAlumno,
|
||||
// idCuestionarioAlumno: respuestasRegistradas.idCuestionarioAlumno,
|
||||
version: '2',
|
||||
dirigidoA: 'estudiantes',
|
||||
titulo: 'Cuestionario de Alumn v2',
|
||||
@@ -90,6 +88,13 @@ const nuevo = async (body) => {
|
||||
createdAt: new Date(),
|
||||
});
|
||||
|
||||
|
||||
console.log("datos a registrar en la tabla cuestionarioAlumno2", { ...body, idCuestionario: cuestionarioRegistro.idCuestionario } );
|
||||
|
||||
let respuestasRegistradas = await CuestionarioAlumno2.create({ ...body, idCuestionario: cuestionarioRegistro.idCuestionario });
|
||||
console.log('despues de registrar cuestionario', respuestasRegistradas);
|
||||
|
||||
|
||||
console.log('cuestionario registrado', cuestionarioRegistro);
|
||||
|
||||
return cuestionarioRegistro;
|
||||
|
||||
@@ -57,6 +57,10 @@ const nuevo = async (body) => {
|
||||
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' },
|
||||
});
|
||||
@@ -66,14 +70,9 @@ const nuevo = async (body) => {
|
||||
throw new Error('Ya existe un cuestionario para este servicio social');
|
||||
}
|
||||
|
||||
let respuestasRegistradas = await CuestionarioPrograma2.create({
|
||||
...body,
|
||||
});
|
||||
|
||||
console.log('despues de registrar cuestionario', respuestasRegistradas);
|
||||
|
||||
// si el cuestionario ya existe solo hay que actualizar el id de cuestionarioprograma o alumno
|
||||
|
||||
|
||||
let cuestionarioRegistro = await Cuestionario.create({
|
||||
idServicio,
|
||||
idCuestionarioPrograma: respuestasRegistradas.idCuestionarioPrograma,
|
||||
@@ -86,6 +85,21 @@ const nuevo = async (body) => {
|
||||
|
||||
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;
|
||||
})
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/*
|
||||
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Usuario = require('./Usuario');
|
||||
@@ -27,14 +29,6 @@ Cuestionario.init(
|
||||
|
||||
|
||||
|
||||
idCuestionarioAlumno: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
idCuestionarioPrograma: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
|
||||
version: {
|
||||
@@ -69,6 +63,60 @@ Cuestionario.init(
|
||||
|
||||
|
||||
|
||||
Cuestionario.belongsTo(Servicio, { foreignKey: 'idServicio' });
|
||||
Servicio.hasMany(Cuestionario, { foreignKey: 'idServicio' });
|
||||
|
||||
|
||||
|
||||
Cuestionario.belongsTo(CuestionarioAlumno2, { foreignKey: 'idCuestionarioAlumno2' });
|
||||
CuestionarioAlumno2.hasOne(Cuestionario, { foreignKey: 'idCuestionarioAlumno2' });
|
||||
|
||||
Cuestionario.belongsTo(CuestionarioPrograma2, { foreignKey: 'idCuestionarioPrograma2' });
|
||||
CuestionarioPrograma2.hasOne(Cuestionario, { foreignKey: 'idCuestionarioPrograma2' });
|
||||
|
||||
|
||||
module.exports = Cuestionario;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Servicio = require('./Servicio');
|
||||
|
||||
class Cuestionario extends Model {}
|
||||
|
||||
Cuestionario.init(
|
||||
{
|
||||
idCuestionario: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
idServicio: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: Servicio,
|
||||
key: 'idServicio',
|
||||
},
|
||||
},
|
||||
version: DataTypes.STRING(50),
|
||||
titulo: DataTypes.STRING(50),
|
||||
desc: DataTypes.STRING(50),
|
||||
dirigidoA: DataTypes.STRING(50),
|
||||
createdAt: DataTypes.DATE,
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Cuestionario',
|
||||
tableName: 'Cuestionario',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
Cuestionario.belongsTo(Servicio, { foreignKey: 'idServicio' });
|
||||
Servicio.hasMany(Cuestionario, { foreignKey: 'idServicio' });
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
|
||||
/*
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
const Cuestionario = require('./Cuestionario');
|
||||
|
||||
|
||||
|
||||
class CuestionarioAlumno2 extends Model {}
|
||||
|
||||
CuestionarioAlumno2.init(
|
||||
@@ -13,6 +19,18 @@ CuestionarioAlumno2.init(
|
||||
autoIncrement: true,
|
||||
},
|
||||
|
||||
|
||||
|
||||
idCuestionario: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
p1: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
@@ -213,4 +231,253 @@ CuestionarioAlumno2.init(
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
CuestionarioAlumno2.belongsTo(Cuestionario, { foreignKey: 'idCuestionario' });
|
||||
Cuestionario.hasMany(CuestionarioAlumno2, { foreignKey: 'idCuestionario' });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = CuestionarioAlumno2;
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class CuestionarioAlumno2 extends Model {}
|
||||
|
||||
CuestionarioAlumno2.init(
|
||||
{
|
||||
idCuestionarioAlumno2: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
idCuestionario: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
p1: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
},
|
||||
p2: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
p4: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p5: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
p6: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p7: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p8: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
p9: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// p3_*: se definen como string (el JSON trae si/no)
|
||||
p3_1: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p3_2: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p3_3: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p3_4: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// p10_* y p11_*
|
||||
p10_1: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p10_2: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p10_3: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p11_1: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p11_2: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p11_3: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p11_4: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// p12_A_*, p12_B_*, p12_C_*, p12_D_*
|
||||
// Ajusta el tamaño de la cadena según requieras
|
||||
p12_A_1: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_A_2: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_A_3: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_A_4: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_B_1: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_B_2: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_B_3: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_B_4: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_C_1: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_C_2: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_C_3: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_C_4: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_D_1: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_D_2: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_D_3: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_D_4: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
p12_D_5: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// p13, p14, p15, p16...
|
||||
p13: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
},
|
||||
p14: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
},
|
||||
p15: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p16: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// p17_*
|
||||
p17_1: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p17_2: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
p17_3: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// p18
|
||||
p18: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'CuestionarioAlumno2',
|
||||
tableName: 'cuestionario_alumno_2',
|
||||
timestamps: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
}
|
||||
);
|
||||
|
||||
// Importación después de la definición para evitar dependencias circulares
|
||||
const Cuestionario = require('./Cuestionario');
|
||||
|
||||
// Definir relaciones después de importar correctamente
|
||||
CuestionarioAlumno2.belongsTo(Cuestionario, { foreignKey: 'idCuestionario' });
|
||||
Cuestionario.hasMany(CuestionarioAlumno2, { foreignKey: 'idCuestionario' });
|
||||
|
||||
module.exports = CuestionarioAlumno2;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
const Cuestionario = require('./Cuestionario');
|
||||
|
||||
|
||||
class CuestionarioPrograma2 extends Model {}
|
||||
|
||||
CuestionarioPrograma2.init(
|
||||
@@ -13,6 +16,14 @@ CuestionarioPrograma2.init(
|
||||
autoIncrement: true,
|
||||
},
|
||||
|
||||
|
||||
idCuestionario: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
|
||||
|
||||
// Sección p3_A_*
|
||||
p3_A_1: {
|
||||
type: DataTypes.STRING(50),
|
||||
@@ -131,4 +142,13 @@ CuestionarioPrograma2.init(
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
CuestionarioPrograma2.belongsTo(Cuestionario, { foreignKey: 'idCuestionario' });
|
||||
Cuestionario.hasMany(CuestionarioPrograma2, { foreignKey: 'idCuestionario' });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = CuestionarioPrograma2;
|
||||
|
||||
Reference in New Issue
Block a user