cuestionario, seccion, pregunta y opcion listos
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user