24 lines
695 B
JavaScript
24 lines
695 B
JavaScript
const Premiacion = require('../../db/tablas/Premiacion');
|
|
const { validarNumeroEntero, validarFecha } = require('../../helper/validar');
|
|
|
|
const editar = async (body) => {
|
|
if (!body.fecha && !body.hora)
|
|
throw new Error('Hay que enviar una fecha u hora nueva.');
|
|
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.');
|
|
return premiacion.update({ fecha, hora });
|
|
};
|
|
|
|
module.exports = editar;
|