- aggiornato catalogo lista con filtri per editori e grafico
This commit is contained in:
@@ -58,6 +58,36 @@ CatProdSchema.statics.findAllIdApp = async function (idapp) {
|
||||
return await CatProd.find(myfind).sort({ name: 1 });
|
||||
};
|
||||
|
||||
CatProdSchema.statics.getCatProdWithTitleCount = async function (idapp) {
|
||||
try {
|
||||
const result = await CatProd.aggregate([
|
||||
{ $match: { idapp } },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'productinfos', // Nome della tua collezione productInfo
|
||||
localField: '_id',
|
||||
foreignField: 'idCatProds',
|
||||
as: 'products'
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 1,
|
||||
name: 1,
|
||||
quanti: { $size: '$products' } // Conta il numero di prodotti per ciascun CatProd
|
||||
}
|
||||
},
|
||||
{ $sort: { name: 1 } } // Ordina i risultati per nome
|
||||
]);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('Error retrieving CatProd with title count:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const CatProd = mongoose.model('CatProd', CatProdSchema);
|
||||
|
||||
CatProd.createIndexes((err) => {
|
||||
|
||||
@@ -181,6 +181,12 @@ const MyElemSchema = new Schema({
|
||||
width: {
|
||||
type: Number,
|
||||
},
|
||||
heightcard: {
|
||||
type: String,
|
||||
},
|
||||
widthcard: {
|
||||
type: String,
|
||||
},
|
||||
link: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user