cuestionario, seccion, pregunta y opcion listos
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const validar = require(`../../helper/validar`);
|
||||
const Seccion = require(`../../db/tablas/Seccion`);
|
||||
const Cuestionario = require(`../../db/tablas/Cuestionario`);
|
||||
|
||||
const crear = async (body) => {
|
||||
const idCuestionario = validar.validarNumeroEntero(
|
||||
body.idCuestionario,
|
||||
'idCuestionario'
|
||||
);
|
||||
const titulo = validar.validacionBasicaStr(body.titulo, 'titulo', true, 100);
|
||||
const descripcion = validar.validacionBasicaStr(
|
||||
body.descripcion,
|
||||
'descripcion',
|
||||
false,
|
||||
100
|
||||
);
|
||||
|
||||
return Cuestionario.findOne({ where: { idCuestionario } }).then(
|
||||
async (res) => {
|
||||
if (!res) throw new Error('Este cuestionario no existe en la db');
|
||||
return Seccion.create({
|
||||
idCuestionario,
|
||||
titulo,
|
||||
descripcion,
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = crear;
|
||||
@@ -0,0 +1,39 @@
|
||||
const Seccion = require(`../../db/tablas/Seccion`);
|
||||
const validar = require(`../../helper/validar`);
|
||||
|
||||
const editar = async (body) => {
|
||||
const idSeccion = validar.validarNumeroEntero(
|
||||
body.idSeccion,
|
||||
'idSeccion'
|
||||
);
|
||||
const data = {};
|
||||
|
||||
if (!!body.titulo) {
|
||||
data.titulo = validar.validacionBasicaStr(body.titulo, 'titulo', true, 100);
|
||||
}
|
||||
if (!!body.descripcion) {
|
||||
data.descripcion = validar.validacionBasicaStr(
|
||||
body.descripcion,
|
||||
'descripcion',
|
||||
false,
|
||||
100
|
||||
);
|
||||
}
|
||||
|
||||
return Seccion.findOne({ where: { idSeccion } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta sección.');
|
||||
return Seccion.update(
|
||||
{
|
||||
titulo: data.titulo,
|
||||
descripcion: data.descripcion,
|
||||
},
|
||||
{ where: { idSeccion } }
|
||||
);
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se actualizó correctamente la sección.',
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = editar;
|
||||
@@ -0,0 +1,18 @@
|
||||
const Seccion = require('../../db/tablas/Seccion');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const traerPorIdCuestionario = async (query) => {
|
||||
const idCuestionario = validar.validarNumeroEntero(
|
||||
query.idCuestionario,
|
||||
'idCuestionario'
|
||||
);
|
||||
|
||||
return Seccion.findAll({
|
||||
where: { idCuestionario }
|
||||
}).then(res => {
|
||||
if(!res) throw new Error("No hay ninguna sección con este idCuestionario.")
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = traerPorIdCuestionario;
|
||||
Reference in New Issue
Block a user