- aggiornati gli argomenti in base a GM
This commit is contained in:
@@ -16,6 +16,9 @@ const CatProdSchema = new Schema({
|
|||||||
idapp: {
|
idapp: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
idArgomento: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -141,6 +141,9 @@ const MyElemSchema = new Schema({
|
|||||||
parambool3: {
|
parambool3: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
|
parambool4: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
number: {
|
number: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
@@ -429,45 +432,48 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
|
|||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
const duplicateIds = schedeTemplate.reduce((acc, scheda) => {
|
if (idapp === '18') {
|
||||||
const id = scheda.scheda._id; // Ottieni l'ID della scheda
|
|
||||||
if (!acc[id]) {
|
const duplicateIds = schedeTemplate.reduce((acc, scheda) => {
|
||||||
acc[id] = []; // Inizializza un array per tenere traccia delle pagine
|
const id = scheda.scheda._id; // Ottieni l'ID della scheda
|
||||||
|
if (!acc[id]) {
|
||||||
|
acc[id] = []; // Inizializza un array per tenere traccia delle pagine
|
||||||
|
}
|
||||||
|
acc[id].push(scheda.idPageOrig); // Aggiungi l'idPage all'array
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// Filtra i duplicati
|
||||||
|
const duplicates = Object.entries(duplicateIds)
|
||||||
|
.filter(([_, pages]) => pages.length > 1) // Mantieni solo gli ID con più di un'istanza
|
||||||
|
.map(([id, pages]) => ({ id, pages })); // Ottieni ID e pagine corrispondenti
|
||||||
|
|
||||||
|
// Recupera i dettagli delle pagine
|
||||||
|
const pageIds = duplicates.flatMap(dup => dup.pages); // Estrai tutti gli idPage
|
||||||
|
const pages = await MyPage.find({ idapp, _id: { $in: pageIds } }).lean();
|
||||||
|
|
||||||
|
// Crea una mappatura tra idPage e title
|
||||||
|
const pageMap = pages.reduce((acc, page) => {
|
||||||
|
acc[page._id] = page.title; // Mappa idPage a title
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// Associa i titoli delle pagine agli ID duplicati
|
||||||
|
const resultWithTitles = duplicates.map(dup => ({
|
||||||
|
id: dup.id,
|
||||||
|
pages: dup.pages.map(_id => ({
|
||||||
|
_id,
|
||||||
|
title: pageMap[_id] || 'Titolo non trovato' // Usa la mappatura per trovare il titolo
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (resultWithTitles.length > 0) {
|
||||||
|
console.log('Duplicati e titoli delle pagine:', JSON.stringify(resultWithTitles, null, 2));
|
||||||
|
await deleteOldMyElems(idapp);
|
||||||
}
|
}
|
||||||
acc[id].push(scheda.idPageOrig); // Aggiungi l'idPage all'array
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
// Filtra i duplicati
|
|
||||||
const duplicates = Object.entries(duplicateIds)
|
|
||||||
.filter(([_, pages]) => pages.length > 1) // Mantieni solo gli ID con più di un'istanza
|
|
||||||
.map(([id, pages]) => ({ id, pages })); // Ottieni ID e pagine corrispondenti
|
|
||||||
|
|
||||||
// Recupera i dettagli delle pagine
|
|
||||||
const pageIds = duplicates.flatMap(dup => dup.pages); // Estrai tutti gli idPage
|
|
||||||
const pages = await MyPage.find({ idapp, _id: { $in: pageIds } }).lean();
|
|
||||||
|
|
||||||
// Crea una mappatura tra idPage e title
|
|
||||||
const pageMap = pages.reduce((acc, page) => {
|
|
||||||
acc[page._id] = page.title; // Mappa idPage a title
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
// Associa i titoli delle pagine agli ID duplicati
|
|
||||||
const resultWithTitles = duplicates.map(dup => ({
|
|
||||||
id: dup.id,
|
|
||||||
pages: dup.pages.map(_id => ({
|
|
||||||
_id,
|
|
||||||
title: pageMap[_id] || 'Titolo non trovato' // Usa la mappatura per trovare il titolo
|
|
||||||
}))
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (resultWithTitles.length > 0) {
|
|
||||||
console.log('Duplicati e titoli delle pagine:', JSON.stringify(resultWithTitles, null, 2));
|
|
||||||
await deleteOldMyElems(idapp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return schedeTemplate;
|
return schedeTemplate;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err', e);
|
console.error('Err', e);
|
||||||
|
|||||||
@@ -124,6 +124,9 @@ const productInfoSchema = new Schema({
|
|||||||
collezione: {
|
collezione: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
ListaArgomenti: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
date_pub: {
|
date_pub: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -695,6 +695,14 @@ UserSchema.statics.isEditor = function (perm) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
UserSchema.statics.isGrafico = function (perm) {
|
||||||
|
try {
|
||||||
|
return ((perm & shared_consts.Permissions.Grafico) ===
|
||||||
|
shared_consts.Permissions.Grafico);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.isZoomeri = function (perm) {
|
UserSchema.statics.isZoomeri = function (perm) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -55,6 +55,73 @@ const { exec } = require('child_process');
|
|||||||
const execPromise = util.promisify(exec);
|
const execPromise = util.promisify(exec);
|
||||||
|
|
||||||
|
|
||||||
|
async function updateProductInfo(recproductInfoAttuale, product, idapp, mycatstr) {
|
||||||
|
if (!recproductInfoAttuale || !mycatstr) return recproductInfoAttuale;
|
||||||
|
|
||||||
|
let idArgomentoNum = null;
|
||||||
|
|
||||||
|
let productInfo = null;
|
||||||
|
|
||||||
|
if (product.ListaArgomenti) {
|
||||||
|
idArgomentoNum = parseInt(product.ListaArgomenti);
|
||||||
|
productInfo = { ...recproductInfoAttuale, IdArgomento: idArgomentoNum };
|
||||||
|
} else {
|
||||||
|
productInfo = { ...recproductInfoAttuale };
|
||||||
|
}
|
||||||
|
|
||||||
|
let reccatprod = await findOrCreateCatProd(idapp, idArgomentoNum, mycatstr);
|
||||||
|
|
||||||
|
if (reccatprod) {
|
||||||
|
updateProductInfoCatProds(productInfo, reccatprod);
|
||||||
|
}
|
||||||
|
|
||||||
|
return productInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function findOrCreateCatProd(idapp, IdArgomento, DescrArgomento) {
|
||||||
|
let reccatprod = null;
|
||||||
|
if (IdArgomento) {
|
||||||
|
reccatprod = await CatProd.findOne({ idapp, IdArgomento }).lean();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reccatprod) {
|
||||||
|
reccatprod = await CatProd.findOne({ idapp, name: DescrArgomento }).lean();
|
||||||
|
if (reccatprod) {
|
||||||
|
if (IdArgomento) {
|
||||||
|
await CatProd.findOneAndUpdate(
|
||||||
|
{ _id: reccatprod._id },
|
||||||
|
{ $set: { IdArgomento } },
|
||||||
|
{ new: true, upsert: false }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (IdArgomento) {
|
||||||
|
try {
|
||||||
|
reccatprod = new CatProd({ idapp, IdArgomento, name: DescrArgomento });
|
||||||
|
await reccatprod.save();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Errore nella creazione di CatProd:', e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return reccatprod;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateProductInfoCatProds(productInfo, reccatprod) {
|
||||||
|
if (productInfo) {
|
||||||
|
const isChanged = !productInfo.idCatProds || productInfo.idCatProds.length !== 1 ||
|
||||||
|
productInfo.idCatProds[0] !== reccatprod._id;
|
||||||
|
|
||||||
|
if (isChanged) {
|
||||||
|
productInfo.idCatProds = [reccatprod._id];
|
||||||
|
console.log('ARGOMENTO VARIATO!', reccatprod.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function compressPdf(inputFile, outputFile, compressione) {
|
async function compressPdf(inputFile, outputFile, compressione) {
|
||||||
try {
|
try {
|
||||||
const tempFolder = path.join(cwd, "temp");
|
const tempFolder = path.join(cwd, "temp");
|
||||||
@@ -776,7 +843,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
let imported = 0;
|
let imported = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
const ripopola = true;
|
const ripopola = false; // SETTARE su TRUE
|
||||||
|
|
||||||
if (ripopola) {
|
if (ripopola) {
|
||||||
dataObjects = null;
|
dataObjects = null;
|
||||||
@@ -882,6 +949,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
idapp: product.idapp,
|
idapp: product.idapp,
|
||||||
code: product.isbn ? product.isbn : product.code,
|
code: product.isbn ? product.isbn : product.code,
|
||||||
sku: product.sku,
|
sku: product.sku,
|
||||||
|
idCatProds: recproductInfoAttuale?.idCatProds,
|
||||||
|
|
||||||
// id_wp: product._id,
|
// id_wp: product._id,
|
||||||
|
|
||||||
@@ -899,12 +967,18 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!productInfo.idCatProds) {
|
||||||
|
productInfo.idCatProds = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Aggiorna la collana solo se non è stata già impostata nel record attuale
|
// Aggiorna la collana solo se non è stata già impostata nel record attuale
|
||||||
//if (recproductInfoAttuale && !recproductInfoAttuale.idCollana && product.DescrizioneCollana) {
|
//if (recproductInfoAttuale && !recproductInfoAttuale.idCollana && product.DescrizioneCollana) {
|
||||||
if (recproductInfoAttuale && product.DescrizioneCollana) {
|
if (recproductInfoAttuale && product.DescrizioneCollana) {
|
||||||
const idCollanaNum = parseInt(product.IdCollana)
|
const idCollanaNum = parseInt(product.IdCollana)
|
||||||
productInfo.idCollana = idCollanaNum;
|
productInfo.idCollana = idCollanaNum;
|
||||||
|
|
||||||
|
|
||||||
reccollana = await Collana.findOne({ idapp, idCollana: idCollanaNum }).lean();
|
reccollana = await Collana.findOne({ idapp, idCollana: idCollanaNum }).lean();
|
||||||
if (!reccollana) {
|
if (!reccollana) {
|
||||||
try {
|
try {
|
||||||
@@ -918,6 +992,11 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (recproductInfoAttuale && product.DescrArgomento) {
|
||||||
|
|
||||||
|
productInfo = await updateProductInfo(productInfo, product, idapp, product.DescrArgomento);
|
||||||
|
}
|
||||||
|
|
||||||
if (product.DataPubblicazione) {
|
if (product.DataPubblicazione) {
|
||||||
productInfo.date_pub = new Date(product.DataPubblicazione);
|
productInfo.date_pub = new Date(product.DataPubblicazione);
|
||||||
// convert data to timestamp
|
// convert data to timestamp
|
||||||
@@ -1109,32 +1188,56 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
productInfo.name = productInfo.name.replace(/ - Usato$| - Nuovo$| - Epub$| - Ebook$| - Mobi$| - DVD$| - Streaming$| - Download$/, "");
|
productInfo.name = productInfo.name.replace(/ - Usato$| - Nuovo$| - Epub$| - Ebook$| - Mobi$| - DVD$| - Streaming$| - Download$/, "");
|
||||||
|
|
||||||
|
|
||||||
let reccateg = null;
|
let reccateg = null;
|
||||||
|
|
||||||
if (product.categories) {
|
if (product.categories) {
|
||||||
arrcat = product.categories.trim().split(',');
|
// Verifica prima se questa categoria è stata aggiornata !
|
||||||
for (const mycat of arrcat) {
|
const recrankingisbn = await ImportaIsbn.findOne({ sku: product.sku }).lean();
|
||||||
let mycatstr = mycat.trim();
|
if (recrankingisbn && recrankingisbn.DescrArgomento) {
|
||||||
|
|
||||||
// Controlla se ci sono le sottocategorie:
|
productInfo.idCatProds = []; // Azzera
|
||||||
arrsubcat = mycatstr.trim().split('>');
|
|
||||||
|
|
||||||
if (arrsubcat.length > 1) {
|
if (tools.isArray(recrankingisbn.ListaArgomenti) && recrankingisbn.ListaArgomenti.length > 1) {
|
||||||
// Ci sono delle sottocategorie
|
console.log('ListaArgomenti STA RITORNANDO UN ARRAY !!!! ', recrankingisbn.ListaArgomenti);
|
||||||
mycatstr = arrsubcat[0].trim();
|
|
||||||
product.subcat_name = arrsubcat[1].trim();;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cerca la Categoria
|
// !!!!
|
||||||
reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
|
for (const idArgomento of recrankingisbn.ListaArgomenti) {
|
||||||
if (!reccateg) {
|
mycatstr = recrankingisbn.DescrArgomento;
|
||||||
// Non esiste questo produttore, quindi lo creo !
|
|
||||||
reccateg = new CatProd({ idapp, name: mycatstr });
|
if (mycatstr)
|
||||||
ris = await reccateg.save();
|
productInfo = await updateProductInfo(productInfo, product, idapp, mycatstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
arrcat = product.categories.trim().split(',');
|
||||||
|
for (const mycat of arrcat) {
|
||||||
|
let mycatstr = mycat.trim();
|
||||||
|
|
||||||
|
// Controlla se ci sono le sottocategorie:
|
||||||
|
arrsubcat = mycatstr.trim().split('>');
|
||||||
|
|
||||||
|
if (arrsubcat.length > 1) {
|
||||||
|
// Ci sono delle sottocategorie
|
||||||
|
mycatstr = arrsubcat[0].trim();
|
||||||
|
product.subcat_name = arrsubcat[1].trim();;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cerca la Categoria
|
||||||
reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
|
reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
|
||||||
}
|
if (!reccateg) {
|
||||||
|
// Non esiste questo produttore, quindi lo creo !
|
||||||
|
reccateg = new CatProd({ idapp, name: mycatstr });
|
||||||
|
ris = await reccateg.save();
|
||||||
|
console.log('CREA con ARGOMENTO VECCHIO... ', mycatstr);
|
||||||
|
reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
|
||||||
|
}
|
||||||
|
|
||||||
if (reccateg) {
|
if (reccateg) {
|
||||||
productInfo.idCatProds.push(reccateg._id);
|
productInfo.idCatProds.push(reccateg._id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -357,6 +357,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
if ((!User.isAdmin(req.user.perm)
|
if ((!User.isAdmin(req.user.perm)
|
||||||
&& !User.isManager(req.user.perm)
|
&& !User.isManager(req.user.perm)
|
||||||
&& !User.isEditor(req.user.perm)
|
&& !User.isEditor(req.user.perm)
|
||||||
|
&& !User.isGrafico(req.user.perm)
|
||||||
&& !User.isFacilitatore(req.user.perm))
|
&& !User.isFacilitatore(req.user.perm))
|
||||||
&&
|
&&
|
||||||
await !tools.ModificheConsentite(req, params.table, fieldsvalue, mydata ? mydata._id : '')) {
|
await !tools.ModificheConsentite(req, params.table, fieldsvalue, mydata ? mydata._id : '')) {
|
||||||
@@ -412,12 +413,18 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
delete mydata['__v'];
|
delete mydata['__v'];
|
||||||
delete mydata['__proto__'];
|
delete mydata['__proto__'];
|
||||||
|
|
||||||
let mytablerec = new mytable(mydata);
|
const isNotNew = (mydata['_id'] !== undefined && mydata['_id'] !== 0 && mydata['_id'] !== '');
|
||||||
|
|
||||||
|
let mytablerec = null;
|
||||||
|
|
||||||
|
mytablerec = new mytable(mydata);
|
||||||
|
|
||||||
// console.log('mytablerec', mytablerec);
|
// console.log('mytablerec', mytablerec);
|
||||||
|
|
||||||
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
||||||
|
|
||||||
if (mydata['_id'] !== undefined && mydata['_id'] !== 0 && mydata['_id'] !== '') {
|
|
||||||
|
if (isNotNew) {
|
||||||
mytablerec.isNew = false;
|
mytablerec.isNew = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,7 +434,9 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
} else if (params.table === 'hours') {
|
} else if (params.table === 'hours') {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined || mytablerec._id === '0')) {
|
if ((mydata['_id'] === undefined || mydata['_id'] === '' ||
|
||||||
|
(mytablerec.isNew && mydata['_id'] === 0))
|
||||||
|
&& (mytablerec._id === undefined || mytablerec._id === '0')) {
|
||||||
mytablerec._id = new ObjectId();
|
mytablerec._id = new ObjectId();
|
||||||
mydata._id = new ObjectId();
|
mydata._id = new ObjectId();
|
||||||
mytablerec.isNew = true;
|
mytablerec.isNew = true;
|
||||||
@@ -493,6 +502,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
return await myPromise
|
return await myPromise
|
||||||
.then(async (doupdate) => {
|
.then(async (doupdate) => {
|
||||||
|
|
||||||
|
if (false) {
|
||||||
|
let plainObject = mytablerec.toObject();
|
||||||
|
console.log(plainObject);
|
||||||
|
}
|
||||||
|
|
||||||
if (doupdate)
|
if (doupdate)
|
||||||
return mytable.updateOne({ _id: mytablerec._id }, mydata, { new: true })
|
return mytable.updateOne({ _id: mytablerec._id }, mydata, { new: true })
|
||||||
else
|
else
|
||||||
@@ -673,7 +687,7 @@ router.post('/getobj', authenticate_noerror, async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
let cmd = req.body.cmd;
|
let cmd = req.body.cmd;
|
||||||
let idapp = req.user ? req.user.idapp : sanitizeHtml(req.body.idapp); // Cambiato from params.idapp a req.body.idapp
|
let idapp = req.user ? req.user.idapp : sanitizeHtml(req.body.idapp); // Cambiato from params.idapp a req.body.idapp
|
||||||
let ris = null;
|
let ris = null;
|
||||||
|
|
||||||
if (cmd === 'lista_editori') {
|
if (cmd === 'lista_editori') {
|
||||||
ris = await User.find(
|
ris = await User.find(
|
||||||
|
|||||||
@@ -1098,6 +1098,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
} else if (mydata.dbop === 'ReplaceAllCircuits') {
|
} else if (mydata.dbop === 'ReplaceAllCircuits') {
|
||||||
// ++ Replace All Circuitname with 'Circuito RIS %s'
|
// ++ Replace All Circuitname with 'Circuito RIS %s'
|
||||||
await Circuit.replaceAllCircuitNames(idapp);
|
await Circuit.replaceAllCircuitNames(idapp);
|
||||||
|
} else if (mydata.dbop === 'eliminaCatProds') {
|
||||||
|
|
||||||
|
await CatProd.deleteMany({ idapp });
|
||||||
|
await SubCatProd.deleteMany({ idapp });
|
||||||
} else if (mydata.dbop === 'visuStat') {
|
} else if (mydata.dbop === 'visuStat') {
|
||||||
// ris = await User.visuUtentiNonInNavi(idapp);
|
// ris = await User.visuUtentiNonInNavi(idapp);
|
||||||
//} else if (mydata.dbop === 'creaNavi') {
|
//} else if (mydata.dbop === 'creaNavi') {
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ module.exports = {
|
|||||||
Editor: 16,
|
Editor: 16,
|
||||||
Zoomeri: 32,
|
Zoomeri: 32,
|
||||||
Department: 64,
|
Department: 64,
|
||||||
|
Grafico: 128,
|
||||||
},
|
},
|
||||||
|
|
||||||
MessageOptions: {
|
MessageOptions: {
|
||||||
|
|||||||
Reference in New Issue
Block a user