24 lines
653 B
JavaScript
24 lines
653 B
JavaScript
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;
|