lista ordini aggiornata

This commit is contained in:
Surya Paolo
2023-12-15 23:36:43 +01:00
parent 4d9eccd1ae
commit 1ca72118f1
5 changed files with 44 additions and 4 deletions

View File

@@ -224,7 +224,8 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
try {
const mycart = await Cart.findOne({ _id: cart_id });
let numorder = await OrdersCart.getLastNumOrder(userId, idapp);
let numorder = await OrdersCart.getLastNumOrder(idapp);
let numord_pers = await OrdersCart.getLastNumOrdPers(userId, idapp);
// Esiste l'ordine ?
let myorderCart = await OrdersCart.getRecCartByUserId(userId, idapp, numorder);
@@ -232,6 +233,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
// crea il nuovo numero d'ordine
numorder++;
numord_pers++;
// SE non esiste allora lo creo !
myorderCart = new OrdersCart({
@@ -243,6 +245,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
status,
note,
numorder,
numord_pers,
created_at: new Date(),
modify_at: new Date(),
})

View File

@@ -7,6 +7,8 @@ var server_constants = require('../tools/server_constants');
var { Project } = require('../models/project');
const { User } = require('../models/user');
var { authenticate, auth_default } = require('../middleware/authenticate');
const _ = require('lodash');
@@ -30,8 +32,14 @@ router.post('/', auth_default, async function (req, res, next) {
const idapp = req.body.idapp;
let userId = req.body.userId;
var products = await Product.findAllIdApp(idapp, "");
var orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0);
let products = await Product.findAllIdApp(idapp, "");
let orders = null;
if (await User.isManagerById(userId)) {
// Prende Tutti gli Ordini !
orders = await OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
} else {
orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0);
}
if (products)
res.send({ code: server_constants.RIS_CODE_OK, products, orders });