- 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,
},

View File

@@ -2,7 +2,7 @@ const { ObjectId } = require('mongodb');
module.exports = {
list: [
{ _id: ObjectId('605c72e2f9b1a019c1e4f4a1'), idapp: '18', title: 'Alimentazione Sana' },
/*{ _id: ObjectId('605c72e2f9b1a019c1e4f4a1'), idapp: '18', title: 'Alimentazione Sana' },
{ _id: ObjectId('605c72e2f9b1a019c1e4f4a2'), idapp: '18', title: 'Attualità e Informazione Libera' },
{ _id: ObjectId('605c72e2f9b1a019c1e4f4a3'), idapp: '18', title: 'Psicologia e Crescita Personale' },
{ _id: ObjectId('605c72e2f9b1a019c1e4f4a4'), idapp: '18', title: 'Educazione e Formazione' },
@@ -21,6 +21,6 @@ module.exports = {
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b1'), idapp: '18', title: 'Sessualità e Relazione di coppia' },
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b2'), idapp: '18', title: 'Tarocchi, Oracoli e Carte' },
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b3'), idapp: '18', title: 'Techiche per il corpo' },
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b4'), idapp: '18', title: 'Antroposofia' },
*/
],
};

View File

@@ -64,7 +64,7 @@ async function updateProductInfo(recproductInfoAttuale, product, idapp, mycatstr
if (product.ListaArgomenti) {
idArgomentoNum = parseInt(product.ListaArgomenti);
productInfo = { ...recproductInfoAttuale, IdArgomento: idArgomentoNum };
productInfo = { ...recproductInfoAttuale, idArgomento: idArgomentoNum };
} else {
productInfo = { ...recproductInfoAttuale };
}
@@ -78,26 +78,26 @@ async function updateProductInfo(recproductInfoAttuale, product, idapp, mycatstr
return productInfo;
}
async function findOrCreateCatProd(idapp, IdArgomento, DescrArgomento) {
async function findOrCreateCatProd(idapp, idArgomento, DescrArgomento) {
let reccatprod = null;
if (IdArgomento) {
reccatprod = await CatProd.findOne({ idapp, IdArgomento }).lean();
if (idArgomento) {
reccatprod = await CatProd.findOne({ idapp, idArgomento }).lean();
}
if (!reccatprod) {
reccatprod = await CatProd.findOne({ idapp, name: DescrArgomento }).lean();
if (reccatprod) {
if (IdArgomento) {
if (idArgomento) {
await CatProd.findOneAndUpdate(
{ _id: reccatprod._id },
{ $set: { IdArgomento } },
{ $set: { idArgomento } },
{ new: true, upsert: false }
);
}
} else {
if (IdArgomento) {
if (idArgomento) {
try {
reccatprod = new CatProd({ idapp, IdArgomento, name: DescrArgomento });
reccatprod = new CatProd({ idapp, idArgomento, name: DescrArgomento });
await reccatprod.save();
} catch (e) {
console.error('Errore nella creazione di CatProd:', e);
@@ -112,8 +112,8 @@ async function findOrCreateCatProd(idapp, IdArgomento, DescrArgomento) {
function updateProductInfoCatProds(productInfo, reccatprod) {
if (productInfo) {
const isChanged = !productInfo.idCatProds || productInfo.idCatProds.length !== 1 ||
productInfo.idCatProds[0] !== reccatprod._id;
const isChanged = (!productInfo.idCatProds || productInfo.idCatProds.length < 1) ||
(productInfo.idCatProds[0].toString() !== reccatprod._id.toString());
if (isChanged) {
productInfo.idCatProds = [reccatprod._id];
@@ -843,7 +843,7 @@ router.post('/import', authenticate, async (req, res) => {
let imported = 0;
let errors = 0;
const ripopola = false; // SETTARE su TRUE
const ripopola = true; // SETTARE su TRUE
if (ripopola) {
dataObjects = null;
@@ -1143,6 +1143,12 @@ router.post('/import', authenticate, async (req, res) => {
checkout_link: product.checkout_link ? product.checkout_link : '',
}
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
if (esisteindb) {
productInfo.idCatProds = esisteindb.idCatProds;
productInfo.idSubCatProds = esisteindb.idSubCatProds;
}
let versione = 0;
if (indprod % 100 === 0)
@@ -1196,8 +1202,6 @@ router.post('/import', authenticate, async (req, res) => {
const recrankingisbn = await ImportaIsbn.findOne({ sku: product.sku }).lean();
if (recrankingisbn && recrankingisbn.DescrArgomento) {
productInfo.idCatProds = []; // Azzera
if (tools.isArray(recrankingisbn.ListaArgomenti) && recrankingisbn.ListaArgomenti.length > 1) {
console.log('ListaArgomenti STA RITORNANDO UN ARRAY !!!! ', recrankingisbn.ListaArgomenti);
}
@@ -1342,7 +1346,7 @@ router.post('/import', authenticate, async (req, res) => {
product.active = true;
}
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
if (risrecInfo) {

View File

@@ -1894,6 +1894,7 @@ function load(req, res, version) {
let storehouses = Storehouse.findAllIdApp(idapp);
let providers = Provider.findAllIdApp(idapp);
let catprods = Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA);
let catprtotali = CatProd.getCatProdWithTitleCount(idapp);
let collane = Collana.findAllIdApp(idapp);
let catalogs = Catalog.findAllIdApp(idapp);
let catprods_gas = Product.getArrCatProds(idapp, shared_consts.PROD.GAS);
@@ -2010,6 +2011,7 @@ function load(req, res, version) {
myschedas,
collane,
catalogs,
catprtotali,
]).then((arrdata) => {
// console.table(arrdata);
let myuser = req.user;
@@ -2107,6 +2109,7 @@ function load(req, res, version) {
myschedas: arrdata[51],
collane: arrdata[52],
catalogs: arrdata[53],
catprtotali: arrdata[54],
});
const prova = 1;

View File

@@ -1 +1 @@
1.1.21
1.1.22