carrito get listos

This commit is contained in:
Lemuel Marquez
2021-05-26 19:47:13 -05:00
parent 5693660ff7
commit 005240b8b2
6 changed files with 98 additions and 23 deletions
+15 -4
View File
@@ -1,9 +1,20 @@
const validar = require('../../helper/validar');
const { validarId } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrito = require(`${dbPath}/Carrito`);
const Modulo = require(`${dbPath}/Modulo`);
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
const update = async (body) => {};
const update = async (body) => {
const idCarrito = validarId(body.idCarrito);
let update = {};
if (body.activo === 'desactivar') update.activo = false;
else if (body.activo === 'activar') update.activo = true;
else throw new Error('No se envio nada para actualizar.');
return Carrito.findOne({ where: { idCarrito } })
.then((res) => {
if (!res) throw new Error('No existe este carrito.');
return Carrito.update(update, { where: { idCarrito } });
})
.then((res) => ({ message: 'Se actualizó correctamente el carrito.' }));
};
module.exports = update;