- Cataloghi

- Import ed Export Pagine
- ObjectID sostituita con ObjectId
This commit is contained in:
Surya Paolo
2024-12-17 17:55:47 +01:00
parent 14b3e18986
commit 300bab2125
91 changed files with 404 additions and 272 deletions

View File

@@ -634,7 +634,7 @@ router.post('/import', authenticate, async (req, res) => {
let imported = 0;
let errors = 0;
const ripopola = false;
const ripopola = true;
dataObjects = null;
@@ -650,10 +650,12 @@ router.post('/import', authenticate, async (req, res) => {
if (myarr && ripopola) {
console.log('*** INIZIO IMPORT RIPOPOLAMENTO ... ', myarr.length);
// Cancella la collection ImportaMacros
await ImportaDescr.deleteMany({ idapp });
// Aggiungi i record su ImportaMacros
// Aggiungi i record su ImportaDescr
for (const recinv of myarr) {
let isnuovo = false
let setta = false
@@ -669,12 +671,15 @@ router.post('/import', authenticate, async (req, res) => {
let queryprod = { idapp, code: recmacro._id };
try {
let risrec = await ImportaDescr.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
// non inserisce nuovi record, se non lo trova ! perché sono troppi !
let risrec = await ImportaDescr.findOneAndUpdate(queryprod,
{ $set: recmacro }, { new: true, upsert: true, strict: false }
);
if (risrec) {
imported++;
// if (imported > 1000)
// break;
if (imported % 10 === 0)
if (imported % 50 === 0)
console.log('importato ', imported, 'su ', myarr.length);
}
@@ -717,23 +722,23 @@ router.post('/import', authenticate, async (req, res) => {
// IMPOSTA I VALORI SOLO SE NON ESISTONO ! ALTRIMENTI LASCIA QUELLI GIA' IMPORTATI (O MODIFICATI)
if (getvalueByJsonText(product.url)) {
if (!myproductInfo.link_macro)
if ((myproductInfo && !myproductInfo.link_macro) || !myproductInfo)
productInfo.link_macro = getvalueByJsonText(product.url);
}
if (getvalueByJsonText(product.descrizione)) {
if (!myproductInfo.descrizione_completa_macro)
if ((myproductInfo && !myproductInfo.descrizione_breve_macro) || !myproductInfo)
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione);
}
if (getvalueByJsonText(product.descrizione_completa)) {
if (!myproductInfo.descrizione_completa_macro)
if ((myproductInfo && !myproductInfo.descrizione_completa_macro) || !myproductInfo)
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa)
}
if (getvalueByJsonText(product.sottotitolo)) {
if (!myproductInfo.sottotitolo)
if ((myproductInfo && !myproductInfo.sottotitolo) || !myproductInfo)
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
}
if (getvalueByJsonText(product.titolo)) {
if (!myproductInfo.name)
if ((myproductInfo && !myproductInfo.name) || !myproductInfo)
productInfo.name = getvalueByJsonText(product.titolo);
}
@@ -756,7 +761,7 @@ router.post('/import', authenticate, async (req, res) => {
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
indprod++;
if (indprod % 10 === 0)
if (indprod % 50 === 0)
console.log(indprod + '/' + numprod);
}
}
@@ -783,14 +788,14 @@ router.post('/import', authenticate, async (req, res) => {
if (dataObjects && dataObjects[0]) {
// Cancella la collection ImportaMacros
// Cancella la collection ImportaIsbn
await ImportaIsbn.deleteMany({ idapp });
const numtot = dataObjects[0].length
console.log('Numero di RECORD da Importare = ', numtot);
// Aggiungi i record su ImportaMacros
// Aggiungi i record su ImportaIsbn
for (const recinv of dataObjects[0]) {
let recmacro = recinv;
@@ -809,7 +814,7 @@ router.post('/import', authenticate, async (req, res) => {
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
if ((imported % 10) === 0)
if ((imported % 50) === 0)
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
}
@@ -836,11 +841,11 @@ router.post('/import', authenticate, async (req, res) => {
// Rimuove prima tutti i valori precedenti
let risupdate = await ProductInfo.updateMany({ idapp }, {
$set: {
totaleVenduti: 0,
venditeLastM: 0,
venditeLast6M: 0,
venditeLastY: 0,
venditeLast2Y: 0,
totVen: 0,
vLastM: 0,
vLast6M: 0,
vLastY: 0,
vLast2Y: 0,
rank3M: 0,
rank6M: 0,
rank1Y: 0,
@@ -876,20 +881,20 @@ router.post('/import', authenticate, async (req, res) => {
// id_wp: product._id,
// name: product.title,
totaleVenduti: product.totaleVenduti || 0,
venditeLastM: product.venditeLastM || 0,
venditeLast6M: product.venditeLast6M || 0,
venditeLastY: product.venditeLastY || 0,
venditeLast2Y: product.venditeLast2Y || 0,
totVen: product.totVen || 0,
vLastM: product.vLastM || 0,
vLast6M: product.vLast6M || 0,
vLastY: product.vLastY || 0,
vLast2Y: product.vLast2Y || 0,
rank3M: product.rank3M || 0,
rank6M: product.rank6M || 0,
rank1Y: product.rank1Y || 0,
}
if (product.DataPubblicazione) {
productInfo.date_publishing = new Date(product.DataPubblicazione);
productInfo.date_pub = new Date(product.DataPubblicazione);
// convert data to timestamp
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
productInfo.date_pub_ts = productInfo.date_pub.getTime();
}
if (product.dataUltimoOrdine) {
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
@@ -897,10 +902,10 @@ router.post('/import', authenticate, async (req, res) => {
// 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: false });
if (risrecInfo) {
imported++;
if (imported % 10 === 0)
if (imported % 50 === 0)
console.log('Importati... ', imported + '/' + numprod);
}
}
@@ -965,7 +970,7 @@ router.post('/import', authenticate, async (req, res) => {
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
if (imported % 10 === 0)
if (imported % 50 === 0)
console.log('Importati su dir Temporanea ', imported);
}
@@ -1034,7 +1039,7 @@ router.post('/import', authenticate, async (req, res) => {
let versione = 0;
if (indprod % 10 === 0)
if (indprod % 50 === 0)
console.log(indprod + '/' + numprod);
@@ -1070,9 +1075,9 @@ router.post('/import', authenticate, async (req, res) => {
/*if (product.Data) {
productInfo.date_publishing = new Date(product.Data * 1000);
productInfo.date_pub = new Date(product.Data * 1000);
// convert data to timestamp
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
productInfo.date_pub_ts = productInfo.date_pub.getTime();
}*/
productInfo.name = productInfo.name.replace(/ - Usato$| - Nuovo$| - Epub$| - Ebook$| - Mobi$| - DVD$| - Streaming$| - Download$/, "");