22 lines
827 B
JavaScript
22 lines
827 B
JavaScript
const { validarNumeroEntero } = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrito = require(`${dbPath}/Carrito`);
|
|
|
|
const update = async (body) => {
|
|
const idCarrito = validarNumeroEntero(body.idCarrito, 'id carrito', true);
|
|
let update = {};
|
|
|
|
return Carrito.findOne({ where: { idCarrito } })
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este carrito.');
|
|
// habilitar cambio de modulo u tipo de equipo
|
|
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.update(update, { where: { idCarrito } });
|
|
})
|
|
.then(() => ({ message: 'Se actualizó correctamente el carrito.' }));
|
|
};
|
|
|
|
module.exports = update;
|