update equipo listo
This commit is contained in:
@@ -1,20 +1,40 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
|
||||
const update = async (body) => {
|
||||
const idEquipo = validar.validarId(body.idEquipo);
|
||||
const idStatus = validar.validarId(body.idStatus);
|
||||
const idStatus = body.idStatus ? validar.validarId(body.idStatus) : null;
|
||||
const idCarrito = body.idCarrito ? validar.validarId(body.idCarrito) : null;
|
||||
const idPrograma = body.idPrograma
|
||||
? validar.validarId(body.idPrograma)
|
||||
: null;
|
||||
let update = {};
|
||||
|
||||
if (idStatus)
|
||||
await Status.findOne({ where: { idStatus } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este status.');
|
||||
update.idStatus = idStatus;
|
||||
});
|
||||
if (idCarrito)
|
||||
await Carrito.findOne({ where: { idCarrito } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este carrito.');
|
||||
update.idCarrito = idCarrito;
|
||||
});
|
||||
if (idPrograma)
|
||||
await Programa.findOne({ where: { idPrograma } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este programa.');
|
||||
update.idPrograma = idPrograma;
|
||||
});
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se envio nada para actualizar.');
|
||||
return Equipo.findOne({ where: { idEquipo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
return Status.findOne({ where: { idStatus } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este status.');
|
||||
return Equipo.update({ idStatus }, { where: { idEquipo } });
|
||||
return Equipo.update(update, { where: { idEquipo } });
|
||||
})
|
||||
.then((res) => ({ message: 'Se actualizó correctamente el equipo.' }));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user