- miglioramenti ricerca titoli e modifica del trafiletto
- miglior visualizzazione delle liste
This commit is contained in:
@@ -45,6 +45,62 @@ module.exports.findAllIdApp = async function (idapp) {
|
||||
return await Publisher.find(myfind).sort({ name: 1 }).lean();
|
||||
};
|
||||
|
||||
module.exports.getEditoriWithTitleCount = async function (idapp) {
|
||||
try {
|
||||
|
||||
const myquery = [
|
||||
{ $match: { idapp } },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'productinfos', // Nome della tua collezione productInfo
|
||||
localField: '_id',
|
||||
foreignField: 'idPublisher',
|
||||
as: 'products'
|
||||
}
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
myproducts: {
|
||||
$filter: {
|
||||
input: "$products",
|
||||
as: "prod",
|
||||
cond: {
|
||||
$in: ["$$prod.idStatoProdotto", [1, 4, 34, 45, 46]]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
$project: {
|
||||
_id: 1,
|
||||
name: 1,
|
||||
quanti: { $size: '$myproducts' },
|
||||
products: {
|
||||
$map: {
|
||||
input: "$myproducts",
|
||||
as: "prod",
|
||||
in: {
|
||||
name: "$$prod.name"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ $match: { quanti: { $gt: 0 } } }, // esclude i record con quanti = 0
|
||||
{ $sort: { name: 1 } } // Ordina i risultati per nome
|
||||
];
|
||||
|
||||
const result = await Publisher.aggregate(myquery);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('Error retrieving idCollana with title count:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports.createIndexes()
|
||||
.then(() => { })
|
||||
.catch((err) => { throw err; });
|
||||
|
||||
Reference in New Issue
Block a user