Aggiornamento modifiche preOrdini
This commit is contained in:
@@ -64,7 +64,6 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
let cart = null;
|
||||
let product = null;
|
||||
// no cart save empty cart to database then return response
|
||||
let myqty = 0;
|
||||
let nuovo = false;
|
||||
if (!mycart) {
|
||||
let oldCart = new CartClass(order)
|
||||
@@ -75,16 +74,19 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
}
|
||||
|
||||
let newCart = CartClass.constructByCart(mycart);
|
||||
// order = await Product.updateProductInOrder(order);
|
||||
if (!nuovo) {
|
||||
if (addqty) {
|
||||
myqty = await newCart.addqty(order);
|
||||
myord = await newCart.addqty(order);
|
||||
} else if (subqty) {
|
||||
myqty = await newCart.subqty(order);
|
||||
myord = await newCart.subqty(order);
|
||||
} else {
|
||||
const ind = newCart.addItem(order);
|
||||
myord = order;
|
||||
}
|
||||
} else {
|
||||
await newCart.updatetotals();
|
||||
myord = order;
|
||||
}
|
||||
cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
|
||||
|
||||
@@ -95,9 +97,10 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
product = await Product.getProductById(order.idProduct);
|
||||
else if (order.product)
|
||||
product = await Product.getProductById(order.product._id);
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, qty: myqty, product });
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, myord, product });
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
||||
console.error('Err:', err);
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null, myord: null });
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -360,9 +363,9 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
||||
|
||||
if (User.isManager(user.perm)) {
|
||||
// Prende Tutti gli Ordini !
|
||||
orderscart = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
|
||||
orderscart = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0, false);
|
||||
} else {
|
||||
orderscart = await OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
||||
orderscart = await OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0, false);
|
||||
}
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, status, orders: orderscart });
|
||||
|
||||
Reference in New Issue
Block a user