Merge branch 'Dev_PDB1' of ssh://risosrv:5522/~/repository/freeplanet_serverside into Dev_PDB1

This commit is contained in:
Surya Paolo
2023-12-21 10:58:18 +01:00
13 changed files with 575 additions and 80 deletions

View File

@@ -72,7 +72,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)
@@ -83,16 +82,21 @@ 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);
const arrord = await Order.getTotalOrderById(order._id);
myord = arrord ? arrord[0] : null;
}
} else {
await newCart.updatetotals();
const arrord = await Order.getTotalOrderById(order._id);
myord = arrord ? arrord[0] : null;
}
cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
@@ -103,9 +107,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 });
}
/*
@@ -308,6 +313,15 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
})
}
})
} else if (status < shared_consts.OrderStatus.CHECKOUT_SENT) {
// Aggiorna il carrello !
/*const cartpao = await Cart.getCartByUserId(userId, idapp);
let newCart = CartClass.constructByCart(cartpao);
if (newCart)
await newCart.updatetotals();
newCart;*/
}
}
@@ -377,9 +391,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

@@ -66,6 +66,7 @@ const Cart = require('../models/cart');
const OrdersCart = require('../models/orderscart');
const Storehouse = require('../models/storehouse');
const Provider = require('../models/provider');
const Gasordine = require('../models/gasordine');
const Scontistica = require('../models/scontistica');
const Department = require('../models/department');
const { Category } = require('../models/category');
@@ -1434,6 +1435,7 @@ function load(req, res, version) {
let workers = User.getusersWorkersList(idapp);
let storehouses = Storehouse.findAllIdApp(idapp);
let providers = Provider.findAllIdApp(idapp);
let gasordines = Gasordine.findAllIdApp(idapp);
let scontisticas = Scontistica.findAllIdApp(idapp);
let departments = Department.findAllIdApp(idapp);
let categories = Category.findAllIdApp(idapp);
@@ -1466,9 +1468,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 = [];
@@ -1523,6 +1525,7 @@ function load(req, res, version) {
categories, // 39
providers,
scontisticas,
gasordines,
]).then((arrdata) => {
// console.table(arrdata);
let myuser = req.user;
@@ -1607,6 +1610,7 @@ function load(req, res, version) {
categories: arrdata[39],
providers: arrdata[40],
scontisticas: arrdata[41],
gasordines: arrdata[42],
});
const prova = 1;

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)