22 lines
640 B
JavaScript
22 lines
640 B
JavaScript
const Premiacion = require('../../db/tablas/Premiacion');
|
|
const { validarNumeroEntero } = require('../../helper/validar');
|
|
|
|
const activarDesactivar = async (body) => {
|
|
if (typeof body.activa === "undefined")
|
|
throw new Error('Se necesita saber si se quiere activar o desactivar.');
|
|
|
|
const idPremiacion = validarNumeroEntero(
|
|
body.idPremiacion,
|
|
'idPremiacion',
|
|
true
|
|
);
|
|
|
|
const activa = body.activa;
|
|
|
|
const premiacion = await Premiacion.findOne({ where: idPremiacion });
|
|
if (!premiacion) throw new Error('No existe esta premiación.');
|
|
return premiacion.update({ activa });
|
|
};
|
|
|
|
module.exports = activarDesactivar;
|