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;
|
||||
Reference in New Issue
Block a user