- aggiornato catalogo lista con filtri per editori e grafico

This commit is contained in:
Surya Paolo
2025-02-13 21:14:51 +01:00
parent d77f9381e5
commit f8de205cf6
6 changed files with 60 additions and 17 deletions

View File

@@ -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) => {

View File

@@ -181,6 +181,12 @@ const MyElemSchema = new Schema({
width: {
type: Number,
},
heightcard: {
type: String,
},
widthcard: {
type: String,
},
link: {
type: String,
},