- Categorie
- ProductInfo
This commit is contained in:
@@ -10,6 +10,7 @@ const Storehouse = require('../models/storehouse');
|
||||
const Provider = require('../models/provider');
|
||||
const Gasordine = require('../models/gasordine');
|
||||
const Product = require('../models/product');
|
||||
const ProductInfo = require('../models/productinfo');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
@@ -178,90 +179,6 @@ module.exports.getOrdersCartById = async function (id) {
|
||||
|
||||
}
|
||||
|
||||
module.exports.getOLDOrdersCartByQuery = 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: 'idGasordine',
|
||||
model: 'Gasordine'
|
||||
},
|
||||
})
|
||||
.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.gasordine = item.order.idGasordine;
|
||||
item.order.idGasordine = item.order.gasordine ? item.order.gasordine._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.getOrdersCartByQuery = async function (query) {
|
||||
|
||||
@@ -274,6 +191,16 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
||||
model: 'Product'
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idProduct',
|
||||
populate: {
|
||||
path: 'idProductInfo',
|
||||
model: 'ProductInfo'
|
||||
},
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
@@ -324,6 +251,10 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
||||
try {
|
||||
item.order.product = item.order.idProduct;
|
||||
item.order.idProduct = item.order.product ? item.order.product._id : '';
|
||||
if (item.order.product.idProductInfo) {
|
||||
item.order.product.productInfo = item.order.product.idProductInfo;
|
||||
item.order.product.idProductInfo = item.order.product ? item.order.product.productInfo._id : '';
|
||||
}
|
||||
item.order.producer = item.order.idProducer;
|
||||
item.order.idProducer = item.order.producer ? item.order.producer._id : '';
|
||||
item.order.storehouse = item.order.idStorehouse;
|
||||
@@ -653,7 +584,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
|
||||
qtystr += 'Ordinate: ' + ord.order.quantity
|
||||
if (ord.order.quantitypreordered > 0)
|
||||
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 + '€ )';
|
||||
msg += '✅ [' + qtystr + '] ' + ord.order.product.productInfo.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
|
||||
}
|
||||
|
||||
msg += '<br>';
|
||||
|
||||
Reference in New Issue
Block a user