40 lines
936 B
JavaScript
40 lines
936 B
JavaScript
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;
|