- 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 });
|
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);
|
const CatProd = mongoose.model('CatProd', CatProdSchema);
|
||||||
|
|
||||||
CatProd.createIndexes((err) => {
|
CatProd.createIndexes((err) => {
|
||||||
|
|||||||
@@ -181,6 +181,12 @@ const MyElemSchema = new Schema({
|
|||||||
width: {
|
width: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
heightcard: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
widthcard: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
link: {
|
link: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const { ObjectId } = require('mongodb');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
list: [
|
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('605c72e2f9b1a019c1e4f4a2'), idapp: '18', title: 'Attualità e Informazione Libera' },
|
||||||
{ _id: ObjectId('605c72e2f9b1a019c1e4f4a3'), idapp: '18', title: 'Psicologia e Crescita Personale' },
|
{ _id: ObjectId('605c72e2f9b1a019c1e4f4a3'), idapp: '18', title: 'Psicologia e Crescita Personale' },
|
||||||
{ _id: ObjectId('605c72e2f9b1a019c1e4f4a4'), idapp: '18', title: 'Educazione e Formazione' },
|
{ _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('605c72e2f9b1a019c1e4f4b1'), idapp: '18', title: 'Sessualità e Relazione di coppia' },
|
||||||
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b2'), idapp: '18', title: 'Tarocchi, Oracoli e Carte' },
|
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b2'), idapp: '18', title: 'Tarocchi, Oracoli e Carte' },
|
||||||
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b3'), idapp: '18', title: 'Techiche per il corpo' },
|
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b3'), idapp: '18', title: 'Techiche per il corpo' },
|
||||||
{ _id: ObjectId('605c72e2f9b1a019c1e4f4b4'), idapp: '18', title: 'Antroposofia' },
|
*/
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -64,7 +64,7 @@ async function updateProductInfo(recproductInfoAttuale, product, idapp, mycatstr
|
|||||||
|
|
||||||
if (product.ListaArgomenti) {
|
if (product.ListaArgomenti) {
|
||||||
idArgomentoNum = parseInt(product.ListaArgomenti);
|
idArgomentoNum = parseInt(product.ListaArgomenti);
|
||||||
productInfo = { ...recproductInfoAttuale, IdArgomento: idArgomentoNum };
|
productInfo = { ...recproductInfoAttuale, idArgomento: idArgomentoNum };
|
||||||
} else {
|
} else {
|
||||||
productInfo = { ...recproductInfoAttuale };
|
productInfo = { ...recproductInfoAttuale };
|
||||||
}
|
}
|
||||||
@@ -78,26 +78,26 @@ async function updateProductInfo(recproductInfoAttuale, product, idapp, mycatstr
|
|||||||
return productInfo;
|
return productInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findOrCreateCatProd(idapp, IdArgomento, DescrArgomento) {
|
async function findOrCreateCatProd(idapp, idArgomento, DescrArgomento) {
|
||||||
let reccatprod = null;
|
let reccatprod = null;
|
||||||
if (IdArgomento) {
|
if (idArgomento) {
|
||||||
reccatprod = await CatProd.findOne({ idapp, IdArgomento }).lean();
|
reccatprod = await CatProd.findOne({ idapp, idArgomento }).lean();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reccatprod) {
|
if (!reccatprod) {
|
||||||
reccatprod = await CatProd.findOne({ idapp, name: DescrArgomento }).lean();
|
reccatprod = await CatProd.findOne({ idapp, name: DescrArgomento }).lean();
|
||||||
if (reccatprod) {
|
if (reccatprod) {
|
||||||
if (IdArgomento) {
|
if (idArgomento) {
|
||||||
await CatProd.findOneAndUpdate(
|
await CatProd.findOneAndUpdate(
|
||||||
{ _id: reccatprod._id },
|
{ _id: reccatprod._id },
|
||||||
{ $set: { IdArgomento } },
|
{ $set: { idArgomento } },
|
||||||
{ new: true, upsert: false }
|
{ new: true, upsert: false }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (IdArgomento) {
|
if (idArgomento) {
|
||||||
try {
|
try {
|
||||||
reccatprod = new CatProd({ idapp, IdArgomento, name: DescrArgomento });
|
reccatprod = new CatProd({ idapp, idArgomento, name: DescrArgomento });
|
||||||
await reccatprod.save();
|
await reccatprod.save();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Errore nella creazione di CatProd:', e);
|
console.error('Errore nella creazione di CatProd:', e);
|
||||||
@@ -112,8 +112,8 @@ async function findOrCreateCatProd(idapp, IdArgomento, DescrArgomento) {
|
|||||||
|
|
||||||
function updateProductInfoCatProds(productInfo, reccatprod) {
|
function updateProductInfoCatProds(productInfo, reccatprod) {
|
||||||
if (productInfo) {
|
if (productInfo) {
|
||||||
const isChanged = !productInfo.idCatProds || productInfo.idCatProds.length !== 1 ||
|
const isChanged = (!productInfo.idCatProds || productInfo.idCatProds.length < 1) ||
|
||||||
productInfo.idCatProds[0] !== reccatprod._id;
|
(productInfo.idCatProds[0].toString() !== reccatprod._id.toString());
|
||||||
|
|
||||||
if (isChanged) {
|
if (isChanged) {
|
||||||
productInfo.idCatProds = [reccatprod._id];
|
productInfo.idCatProds = [reccatprod._id];
|
||||||
@@ -843,7 +843,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
let imported = 0;
|
let imported = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
const ripopola = false; // SETTARE su TRUE
|
const ripopola = true; // SETTARE su TRUE
|
||||||
|
|
||||||
if (ripopola) {
|
if (ripopola) {
|
||||||
dataObjects = null;
|
dataObjects = null;
|
||||||
@@ -1143,6 +1143,12 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
checkout_link: product.checkout_link ? product.checkout_link : '',
|
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;
|
let versione = 0;
|
||||||
|
|
||||||
if (indprod % 100 === 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();
|
const recrankingisbn = await ImportaIsbn.findOne({ sku: product.sku }).lean();
|
||||||
if (recrankingisbn && recrankingisbn.DescrArgomento) {
|
if (recrankingisbn && recrankingisbn.DescrArgomento) {
|
||||||
|
|
||||||
productInfo.idCatProds = []; // Azzera
|
|
||||||
|
|
||||||
if (tools.isArray(recrankingisbn.ListaArgomenti) && recrankingisbn.ListaArgomenti.length > 1) {
|
if (tools.isArray(recrankingisbn.ListaArgomenti) && recrankingisbn.ListaArgomenti.length > 1) {
|
||||||
console.log('ListaArgomenti STA RITORNANDO UN ARRAY !!!! ', recrankingisbn.ListaArgomenti);
|
console.log('ListaArgomenti STA RITORNANDO UN ARRAY !!!! ', recrankingisbn.ListaArgomenti);
|
||||||
}
|
}
|
||||||
@@ -1342,7 +1346,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
product.active = true;
|
product.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
|
|
||||||
// Update ProductInfo
|
// Update ProductInfo
|
||||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
||||||
if (risrecInfo) {
|
if (risrecInfo) {
|
||||||
|
|||||||
@@ -1894,6 +1894,7 @@ function load(req, res, version) {
|
|||||||
let storehouses = Storehouse.findAllIdApp(idapp);
|
let storehouses = Storehouse.findAllIdApp(idapp);
|
||||||
let providers = Provider.findAllIdApp(idapp);
|
let providers = Provider.findAllIdApp(idapp);
|
||||||
let catprods = Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA);
|
let catprods = Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA);
|
||||||
|
let catprtotali = CatProd.getCatProdWithTitleCount(idapp);
|
||||||
let collane = Collana.findAllIdApp(idapp);
|
let collane = Collana.findAllIdApp(idapp);
|
||||||
let catalogs = Catalog.findAllIdApp(idapp);
|
let catalogs = Catalog.findAllIdApp(idapp);
|
||||||
let catprods_gas = Product.getArrCatProds(idapp, shared_consts.PROD.GAS);
|
let catprods_gas = Product.getArrCatProds(idapp, shared_consts.PROD.GAS);
|
||||||
@@ -2010,6 +2011,7 @@ function load(req, res, version) {
|
|||||||
myschedas,
|
myschedas,
|
||||||
collane,
|
collane,
|
||||||
catalogs,
|
catalogs,
|
||||||
|
catprtotali,
|
||||||
]).then((arrdata) => {
|
]).then((arrdata) => {
|
||||||
// console.table(arrdata);
|
// console.table(arrdata);
|
||||||
let myuser = req.user;
|
let myuser = req.user;
|
||||||
@@ -2107,6 +2109,7 @@ function load(req, res, version) {
|
|||||||
myschedas: arrdata[51],
|
myschedas: arrdata[51],
|
||||||
collane: arrdata[52],
|
collane: arrdata[52],
|
||||||
catalogs: arrdata[53],
|
catalogs: arrdata[53],
|
||||||
|
catprtotali: arrdata[54],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prova = 1;
|
const prova = 1;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.1.21
|
1.1.22
|
||||||
Reference in New Issue
Block a user