Corretto incongruenze OrdersCart
This commit is contained in:
@@ -22,7 +22,6 @@ const OrdersCartSchema = new Schema({
|
||||
numord_pers: { type: Number },
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
totalQty: { type: Number, default: 0 },
|
||||
TotalPriceProduct: { type: Number, default: 0 },
|
||||
totalQtyPreordered: { type: Number, default: 0 },
|
||||
totalPrice: { type: Number, default: 0 },
|
||||
department: {
|
||||
@@ -130,10 +129,10 @@ module.exports.getLastNumOrder = async function (idapp) {
|
||||
module.exports.getLastNumOrdPers = async function (uid, idapp) {
|
||||
let query = { userId: uid, idapp, deleted: false }
|
||||
let numorder = 1;
|
||||
let numorderrec = await OrdersCart.find(query).sort({ numorder: -1 }).limit(1);
|
||||
let numorderrec = await OrdersCart.find(query).sort({ numord_pers: -1 }).limit(1);
|
||||
|
||||
if (numorderrec && numorderrec.length > 0)
|
||||
numorder = numorderrec[0].numorder;
|
||||
numorder = numorderrec[0].numord_pers;
|
||||
else
|
||||
numorder = 0;
|
||||
|
||||
@@ -178,7 +177,7 @@ module.exports.getOrdersCartById = async function (id) {
|
||||
|
||||
}
|
||||
|
||||
module.exports.getOrdersCartByQuery = async function (query) {
|
||||
module.exports.getOLDOrdersCartByQuery = async function (query) {
|
||||
|
||||
let myorderscart = await OrdersCart.find(query)
|
||||
.populate('items.order')
|
||||
@@ -252,6 +251,82 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
||||
return myorderscart;
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports.getOrdersCartByQuery = async function (query) {
|
||||
|
||||
let myorderscart = await OrdersCart.find(query)
|
||||
.populate('items.order')
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idProduct',
|
||||
model: 'Product'
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idProducer',
|
||||
model: 'Producer'
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idProvider',
|
||||
model: 'Provider'
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idStorehouse',
|
||||
model: 'Storehouse'
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idScontisticas',
|
||||
model: 'Scontistica'
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'userId',
|
||||
model: 'User',
|
||||
select: '_id name surname username profile', // Specify the fields you want to retrieve
|
||||
})
|
||||
.lean();
|
||||
|
||||
myorderscart = myorderscart.map(order => {
|
||||
order.user = order.userId
|
||||
order.userId = order.user._id
|
||||
order.items = order.items.map(item => {
|
||||
if (item.order) {
|
||||
try {
|
||||
item.order.product = item.order.idProduct;
|
||||
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
||||
item.order.producer = item.order.idProducer;
|
||||
item.order.idProducer = item.order.producer ? item.order.producer._id : '';
|
||||
item.order.storehouse = item.order.idStorehouse;
|
||||
item.order.idStorehouse = item.order.storehouse ? item.order.storehouse._id : '';
|
||||
item.order.provider = item.order.idProvider;
|
||||
item.order.idProvider = item.order.provider ? item.order.provider._id : '';
|
||||
item.order.scontisticas = item.order.scontisticas;
|
||||
item.order.idScontisticas = item.order.idScontisticas ? item.order.idScontisticas._id : '';
|
||||
} catch (e) {
|
||||
console.error('Err: ', e);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
});
|
||||
return order;
|
||||
});
|
||||
|
||||
return myorderscart;
|
||||
}
|
||||
|
||||
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder, filterStatus) {
|
||||
|
||||
try {
|
||||
@@ -306,7 +381,6 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
totalQty: newOrdersCart.totalQty,
|
||||
totalQtyPreordered: newOrdersCart.totalQtyPreordered,
|
||||
totalPrice: newOrdersCart.totalPrice,
|
||||
totalPriceProduct: newOrdersCart.totalPriceProduct,
|
||||
userId: userId,
|
||||
status: newOrdersCart.status,
|
||||
numorder: newOrdersCart.numorder,
|
||||
@@ -559,7 +633,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
|
||||
if (ord.order.quantity > 0)
|
||||
qtystr += 'Ordinate: ' + ord.order.quantity
|
||||
if (ord.order.quantitypreordered > 0)
|
||||
qtystr += 'Prenotate: ' + ord.order.quantitypreordered
|
||||
qtystr += ' Pre-Ordinate: ' + ord.order.quantitypreordered
|
||||
msg += '✅ [' + qtystr + '] ' + ord.order.product.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user