cuestionario, seccion, pregunta y opcion listos
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
const validar = require(`../../helper/validar`);
|
||||
const Pregunta = require(`../../db/tablas/Pregunta`);
|
||||
const Opcion = require(`../../db/tablas/Opcion`);
|
||||
|
||||
const crear = async (body) => {
|
||||
const idPregunta = validar.validarNumeroEntero(body.idPregunta, 'idPregunta');
|
||||
const opcion = validar.validacionBasicaStr(body.opcion, 'opcion', false, 256);
|
||||
|
||||
return Pregunta.findOne({ where: { idPregunta } }).then(async (res) => {
|
||||
if (!res) throw new Error('Esta pregunta no existe en la db');
|
||||
|
||||
return Opcion.create({
|
||||
idPregunta,
|
||||
opcion,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = crear;
|
||||
@@ -0,0 +1,23 @@
|
||||
const Opcion = require(`../../db/tablas/Opcion`);
|
||||
const validar = require(`../../helper/validar`);
|
||||
|
||||
const editar = async (body) => {
|
||||
const idOpcion = validar.validarNumeroEntero(body.idOpcion, 'idOpcion');
|
||||
const opcion = validar.validacionBasicaStr(body.opcion, 'opcion', false, 256);
|
||||
|
||||
return Opcion.findOne({ where: { idOpcion } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta opción.');
|
||||
return Opcion.update(
|
||||
{
|
||||
opcion,
|
||||
},
|
||||
{ where: { idOpcion } }
|
||||
);
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se actualizó correctamente la opción.',
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = editar;
|
||||
@@ -0,0 +1,18 @@
|
||||
const Opcion = require('../../db/tablas/Opcion');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const traerPoridPregunta = async (query) => {
|
||||
const idPregunta = validar.validarNumeroEntero(
|
||||
query.idPregunta,
|
||||
'idPregunta'
|
||||
);
|
||||
|
||||
return Opcion.findAll({
|
||||
where: { idPregunta }
|
||||
}).then(res => {
|
||||
if(!res) throw new Error("No hay ninguna Opcion con este idPregunta.")
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = traerPoridPregunta;
|
||||
Reference in New Issue
Block a user