31 lines
799 B
JavaScript
31 lines
799 B
JavaScript
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;
|