- 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,6 +432,8 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
|
|||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (idapp === '18') {
|
||||||
|
|
||||||
const duplicateIds = schedeTemplate.reduce((acc, scheda) => {
|
const duplicateIds = schedeTemplate.reduce((acc, scheda) => {
|
||||||
const id = scheda.scheda._id; // Ottieni l'ID della scheda
|
const id = scheda.scheda._id; // Ottieni l'ID della scheda
|
||||||
if (!acc[id]) {
|
if (!acc[id]) {
|
||||||
@@ -467,6 +472,7 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
|
|||||||
await deleteOldMyElems(idapp);
|
await deleteOldMyElems(idapp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return schedeTemplate;
|
return schedeTemplate;
|
||||||
} catch (e) {
|
} catch (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,8 +1188,30 @@ 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) {
|
||||||
|
// Verifica prima se questa categoria è stata aggiornata !
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// !!!!
|
||||||
|
for (const idArgomento of recrankingisbn.ListaArgomenti) {
|
||||||
|
mycatstr = recrankingisbn.DescrArgomento;
|
||||||
|
|
||||||
|
if (mycatstr)
|
||||||
|
productInfo = await updateProductInfo(productInfo, product, idapp, mycatstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
arrcat = product.categories.trim().split(',');
|
arrcat = product.categories.trim().split(',');
|
||||||
for (const mycat of arrcat) {
|
for (const mycat of arrcat) {
|
||||||
let mycatstr = mycat.trim();
|
let mycatstr = mycat.trim();
|
||||||
@@ -1130,6 +1231,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
// Non esiste questo produttore, quindi lo creo !
|
// Non esiste questo produttore, quindi lo creo !
|
||||||
reccateg = new CatProd({ idapp, name: mycatstr });
|
reccateg = new CatProd({ idapp, name: mycatstr });
|
||||||
ris = await reccateg.save();
|
ris = await reccateg.save();
|
||||||
|
console.log('CREA con ARGOMENTO VECCHIO... ', mycatstr);
|
||||||
reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
|
reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1138,6 +1240,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// "Autore" : "Silia,Marucelli, Stefano,Cattinelli",
|
// "Autore" : "Silia,Marucelli, Stefano,Cattinelli",
|
||||||
let arrAuthor = [];
|
let arrAuthor = [];
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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