- le categorie visibili solo se ci sono prodotti attivi
This commit is contained in:
@@ -580,42 +580,65 @@ module.exports.convertAfterImportALLPROD = async function (idapp, dataObjects) {
|
||||
module.exports.getArrCatProds = async function (idapp, cosa) {
|
||||
|
||||
try {
|
||||
let addquery = {};
|
||||
let addquery = [];
|
||||
let arr = [];
|
||||
if (cosa === shared_consts.PROD.GAS) {
|
||||
addquery = { idapp, idGasordine: { $exists: true, $ne: null, $type: 'objectId' } }
|
||||
addquery = [
|
||||
{ $match: { idapp, idGasordine: { $exists: true, $ne: null, $type: 'objectId' } } }
|
||||
];
|
||||
|
||||
addquery.push(
|
||||
{
|
||||
$lookup: {
|
||||
from: 'gasordines',
|
||||
localField: 'idGasordine',
|
||||
foreignField: '_id',
|
||||
as: 'gasordine'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
addquery.push(
|
||||
{
|
||||
$match: {
|
||||
"gasordine.active": true
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
} else if (cosa === shared_consts.PROD.BOTTEGA) {
|
||||
addquery = {
|
||||
idapp, $or: [
|
||||
{ idGasordine: { $exists: false } },
|
||||
{ idGasordine: { $exists: true, $eq: null } }
|
||||
]
|
||||
}
|
||||
addquery = [{
|
||||
$match: {
|
||||
idapp, $or: [
|
||||
{ idGasordine: { $exists: false } },
|
||||
{ idGasordine: { $exists: true, $eq: null } }
|
||||
]
|
||||
}
|
||||
}]
|
||||
} else {
|
||||
addquery = { idapp };
|
||||
addquery = [{ $match: { idapp } }];
|
||||
}
|
||||
|
||||
let myquery = [
|
||||
{ $match: addquery },
|
||||
{
|
||||
$lookup: {
|
||||
from: "productinfos",
|
||||
localField: "idProductInfo",
|
||||
foreignField: "_id",
|
||||
as: "productInfo",
|
||||
},
|
||||
let myquery = [...addquery,
|
||||
{
|
||||
$lookup: {
|
||||
from: "productinfos",
|
||||
localField: "idProductInfo",
|
||||
foreignField: "_id",
|
||||
as: "productInfo",
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "catprods",
|
||||
localField: "productInfo.idCatProds",
|
||||
foreignField: "_id",
|
||||
as: "category"
|
||||
}
|
||||
},
|
||||
{ $unwind: "$category" },
|
||||
{ $group: { _id: "$category._id", name: { $first: "$category.name" } } },
|
||||
{ $sort: { name: 1 } }
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "catprods",
|
||||
localField: "productInfo.idCatProds",
|
||||
foreignField: "_id",
|
||||
as: "category"
|
||||
}
|
||||
},
|
||||
{ $unwind: "$category" },
|
||||
{ $group: { _id: "$category._id", name: { $first: "$category.name" } } },
|
||||
{ $sort: { name: 1 } }
|
||||
];
|
||||
|
||||
arr = await Product.aggregate(myquery, (err, result) => {
|
||||
|
||||
Reference in New Issue
Block a user