lista ordini aggiornata
This commit is contained in:
@@ -19,6 +19,7 @@ const OrdersCartSchema = new Schema({
|
|||||||
type: String
|
type: String
|
||||||
},
|
},
|
||||||
numorder: { type: Number },
|
numorder: { type: Number },
|
||||||
|
numord_pers: { type: Number },
|
||||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||||
totalQty: { type: Number, default: 0 },
|
totalQty: { type: Number, default: 0 },
|
||||||
totalPrice: { type: Number, default: 0 },
|
totalPrice: { type: Number, default: 0 },
|
||||||
@@ -110,7 +111,21 @@ module.exports.getFieldsForSearch = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports.getLastNumOrder = async function (uid, idapp) {
|
module.exports.getLastNumOrder = async function (idapp) {
|
||||||
|
let query = { idapp, deleted: false }
|
||||||
|
let numorder = 100;
|
||||||
|
let numorderrec = await OrdersCart.find(query).sort({ numorder: -1 }).limit(1);
|
||||||
|
|
||||||
|
if (numorderrec && numorderrec.length > 0)
|
||||||
|
numorder = numorderrec[0].numorder;
|
||||||
|
else
|
||||||
|
numorder = 100;
|
||||||
|
|
||||||
|
return numorder;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.getLastNumOrdPers = async function (uid, idapp) {
|
||||||
let query = { userId: uid, idapp, deleted: false }
|
let query = { userId: uid, idapp, deleted: false }
|
||||||
let numorder = 1;
|
let numorder = 1;
|
||||||
let numorderrec = await OrdersCart.find(query).sort({ numorder: -1 }).limit(1);
|
let numorderrec = await OrdersCart.find(query).sort({ numorder: -1 }).limit(1);
|
||||||
@@ -266,6 +281,7 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
|||||||
userId: userId,
|
userId: userId,
|
||||||
status: newOrdersCart.status,
|
status: newOrdersCart.status,
|
||||||
numorder: newOrdersCart.numorder,
|
numorder: newOrdersCart.numorder,
|
||||||
|
numord_pers: newOrdersCart.numord_pers,
|
||||||
note: newOrdersCart.note,
|
note: newOrdersCart.note,
|
||||||
modify_at: new Date(),
|
modify_at: new Date(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,6 +176,9 @@ const SiteSchema = new Schema({
|
|||||||
info2: { type: String, default: '' },
|
info2: { type: String, default: '' },
|
||||||
cell: { type: String, default: '' },
|
cell: { type: String, default: '' },
|
||||||
},
|
},
|
||||||
|
ecomm: {
|
||||||
|
enablePreOrders: { type: Boolean, default: false },
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var Site = module.exports = mongoose.model('Site', SiteSchema);
|
var Site = module.exports = mongoose.model('Site', SiteSchema);
|
||||||
|
|||||||
@@ -625,6 +625,16 @@ UserSchema.statics.isManager = function (perm) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.isManagerById = async function (id) {
|
||||||
|
try {
|
||||||
|
const ris = await User.findOne({ _id: id }, { perm: 1 }).lean();
|
||||||
|
return ((ris.perm & shared_consts.Permissions.Manager) ===
|
||||||
|
shared_consts.Permissions.Manager);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.isEditor = function (perm) {
|
UserSchema.statics.isEditor = function (perm) {
|
||||||
try {
|
try {
|
||||||
return ((perm & shared_consts.Permissions.Editor) ===
|
return ((perm & shared_consts.Permissions.Editor) ===
|
||||||
|
|||||||
@@ -224,7 +224,8 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
try {
|
try {
|
||||||
const mycart = await Cart.findOne({ _id: cart_id });
|
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 ?
|
// Esiste l'ordine ?
|
||||||
let myorderCart = await OrdersCart.getRecCartByUserId(userId, idapp, numorder);
|
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
|
// crea il nuovo numero d'ordine
|
||||||
numorder++;
|
numorder++;
|
||||||
|
numord_pers++;
|
||||||
|
|
||||||
// SE non esiste allora lo creo !
|
// SE non esiste allora lo creo !
|
||||||
myorderCart = new OrdersCart({
|
myorderCart = new OrdersCart({
|
||||||
@@ -243,6 +245,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
|||||||
status,
|
status,
|
||||||
note,
|
note,
|
||||||
numorder,
|
numorder,
|
||||||
|
numord_pers,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
modify_at: new Date(),
|
modify_at: new Date(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ var server_constants = require('../tools/server_constants');
|
|||||||
|
|
||||||
var { Project } = require('../models/project');
|
var { Project } = require('../models/project');
|
||||||
|
|
||||||
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
var { authenticate, auth_default } = require('../middleware/authenticate');
|
var { authenticate, auth_default } = require('../middleware/authenticate');
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
@@ -30,8 +32,14 @@ router.post('/', auth_default, async function (req, res, next) {
|
|||||||
const idapp = req.body.idapp;
|
const idapp = req.body.idapp;
|
||||||
let userId = req.body.userId;
|
let userId = req.body.userId;
|
||||||
|
|
||||||
var products = await Product.findAllIdApp(idapp, "");
|
let products = await Product.findAllIdApp(idapp, "");
|
||||||
var orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0);
|
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)
|
if (products)
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, products, orders });
|
res.send({ code: server_constants.RIS_CODE_OK, products, orders });
|
||||||
|
|||||||
Reference in New Issue
Block a user