Aggiornamento modifiche preOrdini

This commit is contained in:
Surya Paolo
2023-12-20 21:52:17 +01:00
parent 56b5bac5f0
commit 0e1fc359a0
11 changed files with 290 additions and 61 deletions

View File

@@ -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 });

View File

@@ -1466,9 +1466,9 @@ function load(req, res, version) {
cart = Cart.getCartByUserId(req.user.id, idapp);
if (User.isManager(req.user.perm)) {
// Prende Tutti gli Ordini !
orderscart = OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
orderscart = OrdersCart.getOrdersCartByUserId('ALL', idapp, 0, false);
} else {
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0, false);
}
}
let askedfriends = [];

View File

@@ -30,14 +30,15 @@ const OrdersCart = require('../models/orderscart');
router.get('/:userId', authenticate, function (req, res, next) {
let userId = req.body.userId
let idapp = req.body.idapp
OrdersCart.getOrdersCartByUserId(userId, idapp, 0, function (err, cart) {
if (err) return next(err)
OrdersCart.getOrdersCartByUserId(userId, idapp, 0, false)
.then((cart) => {
if (cart)
res.send({ code: server_constants.RIS_CODE_OK, cart });
else
res.status(400).send(e);
})
if (cart)
res.send({ code: server_constants.RIS_CODE_OK, cart });
else
res.status(400).send(e);
})
})
module.exports = router;

View File

@@ -36,9 +36,9 @@ router.post('/', auth_default, async function (req, res, next) {
let orders = null;
if (await User.isManagerById(userId)) {
// Prende Tutti gli Ordini !
orders = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
orders = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0, false);
} else {
orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0);
orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0, false);
}
if (products)