2022-05-13 22:10:54 -05:00
|
|
|
const Premiacion = require('../../db/tablas/Premiacion');
|
|
|
|
|
const { validarNumeroEntero, validarFecha } = require('../../helper/validar');
|
|
|
|
|
|
|
|
|
|
const editar = async (body) => {
|
2022-05-17 20:57:26 -05:00
|
|
|
if (!body.fecha && !body.hora)
|
|
|
|
|
throw new Error('Hay que enviar una fecha u hora nueva.');
|
2022-05-13 22:10:54 -05:00
|
|
|
let fecha;
|
|
|
|
|
let hora;
|
|
|
|
|
if (body.fecha) fecha = validarFecha(body.fecha);
|
|
|
|
|
if (body.hora) hora = body.hora;
|
|
|
|
|
|
|
|
|
|
const idPremiacion = validarNumeroEntero(
|
|
|
|
|
body.idPremiacion,
|
|
|
|
|
'idPremiacion',
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const premiacion = await Premiacion.findOne({ where: idPremiacion });
|
|
|
|
|
if (!premiacion) throw new Error('No existe esta premiación.');
|
2022-05-17 20:57:26 -05:00
|
|
|
return premiacion.update({ fecha, hora });
|
2022-05-13 22:10:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = editar;
|