- Modifiche a ProductInfo... Continua
This commit is contained in:
@@ -108,10 +108,10 @@ class CronMod {
|
||||
await CatProd.deleteMany({ idapp });
|
||||
await SubCatProd.deleteMany({ idapp });
|
||||
} else if (mydata.dbop === 'removeProductInfoWithoutDateUpdatedFromGM') {
|
||||
mystr = await ProductInfo.removeProductInfoWithoutDateUpdatedFromGM(idapp);
|
||||
mystr = await Product.removeProductInfoWithoutDateUpdatedFromGM(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'resetImageNotFound') {
|
||||
mystr = await ProductInfo.resetImageNotFound();
|
||||
mystr = await Product.resetImageNotFound();
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'StatMacro') {
|
||||
const macro = new Macro(idapp, {});
|
||||
@@ -220,7 +220,7 @@ class CronMod {
|
||||
mystr = await CatProd.updateCatDeleteEmpty(req.body.idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'UpdateStatFatturato') {
|
||||
mystr = await ProductInfo.updateProductInfoByStats(req.body.idapp);
|
||||
mystr = await Product.updateProductInfoByStats(req.body.idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'MigrateMSSQLToMongoDb') {
|
||||
const { mssqlmigrateTables } = require('../controllers/articleController');
|
||||
@@ -464,11 +464,11 @@ class CronMod {
|
||||
await Circuit.createCircuitIfNotExist(req, idapp, recprov.prov);
|
||||
}
|
||||
} else if (mydata.dbop === 'correggiProductTypes') {
|
||||
await ProductInfo.correggiProductTypes();
|
||||
await Product.correggiProductTypes();
|
||||
} else if (mydata.dbop === 'replaceProductImgToImageFile') {
|
||||
await ProductInfo.replaceProductImgToImageFile(true);
|
||||
await Product.replaceProductImgToImageFile(true);
|
||||
} else if (mydata.dbop === 'removeUploadProducts_Path') {
|
||||
await ProductInfo.replaceProductImgToImageFile(false);
|
||||
await Product.replaceProductImgToImageFile(false);
|
||||
} else if (mydata.dbop === 'correggiCircuitiANull') {
|
||||
await User.updateMany({}, { $pull: { 'profile.mycircuits': { circuitname: null } } });
|
||||
} else if (mydata.dbop === 'ImpostaMinMaxPersonali') {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const Importamacro = require('../models/importamacro'); // Assicurati di avere i modelli corretti
|
||||
const ImportaIsbn = require('../models/importaisbn');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
const Product = require('../models/product');
|
||||
const CatProd = require('../models/catprod');
|
||||
const SubCatProd = require('../models/subcatprod');
|
||||
@@ -444,13 +443,13 @@ class Macro {
|
||||
let count = 0;
|
||||
if (Array.isArray(recproducts)) {
|
||||
if (recproducts.length > 10 && lavoromassivo && options.rimuovieventualiCancellati) {
|
||||
// rimuovi dalla tabella productInfo tutti i campi date_updated_fromGM
|
||||
const result = await ProductInfo.updateMany(
|
||||
// disattiva dalla tabella productInfo tutti i campi date_updated_fromGM
|
||||
const result = await Product.updateMany(
|
||||
{ idapp: options.idapp },
|
||||
{ $unset: { date_updated_fromGM: null } }
|
||||
{ $unset: { 'productInfo.date_updated_fromGM': null } }
|
||||
);
|
||||
let quanti_rimossi = result.modifiedCount;
|
||||
console.log(`Sbianca date_updated_fromGM da ProductInfo: (${quanti_rimossi} su ${result.matchedCount})`);
|
||||
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
|
||||
rimuoviTabellePerIniziare = true;
|
||||
}
|
||||
|
||||
@@ -634,7 +633,7 @@ class Macro {
|
||||
if (!product.title || !product.sku) importa = false;
|
||||
|
||||
if (importa) {
|
||||
const productInfo = this.preparaProductInfo(product);
|
||||
product.productInfo = this.preparaProductInfo(product);
|
||||
|
||||
if (this.localoptions?.importadaFDV) {
|
||||
const recrankingisbn = await ImportaIsbn.findOne({ sku: product.sku }).lean();
|
||||
@@ -647,12 +646,12 @@ class Macro {
|
||||
product.active = true;
|
||||
}
|
||||
|
||||
await this.gestisciCategorie(productInfo, product);
|
||||
await this.gestisciAutori(productInfo, product);
|
||||
await this.gestisciEditore(productInfo, product);
|
||||
await this.gestisciCollana(productInfo, product);
|
||||
await this.gestisciCategorie(product);
|
||||
await this.gestisciAutori(product);
|
||||
await this.gestisciEditore(product);
|
||||
await this.gestisciCollana(product);
|
||||
|
||||
const risrecInfo = await ProductInfo.findOneAndUpdate(
|
||||
const risrecInfo = await Product.findOneAndUpdate(
|
||||
{ code: productInfo.code },
|
||||
{ $set: productInfo },
|
||||
{ new: true, upsert: true, returnOriginal: false }
|
||||
@@ -705,7 +704,6 @@ class Macro {
|
||||
preparaProductInfo(product) {
|
||||
try {
|
||||
return {
|
||||
idapp: product.idapp,
|
||||
code: product.isbn,
|
||||
id_wp: product._id || undefined,
|
||||
sku: product.sku,
|
||||
@@ -869,10 +867,10 @@ class Macro {
|
||||
/**
|
||||
* Gestisce le categorie e sottocategorie del prodotto.
|
||||
*/
|
||||
async gestisciCategorie(productInfo, product) {
|
||||
async gestisciCategorie(product) {
|
||||
try {
|
||||
if (product.DescrArgomento) {
|
||||
productInfo.idCatProds = [];
|
||||
product.productInfo.idCatProds = [];
|
||||
const reccateg = await CatProd.findOne({ idapp: this.idapp, name: product.DescrArgomento });
|
||||
let nuovaCategoria = null;
|
||||
if (!reccateg) {
|
||||
@@ -892,12 +890,12 @@ class Macro {
|
||||
|
||||
|
||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||
if (myriscat) productInfo.idCatProds.push(myriscat);
|
||||
if (myriscat) product.productInfo.idCatProds.push(myriscat);
|
||||
} else {
|
||||
if (product.categories) {
|
||||
// const arrcat = product.categories.trim().split(',');
|
||||
const arrcat = product.categories.trim().split(',');
|
||||
productInfo.idCatProds = [];
|
||||
product.productInfo.idCatProds = [];
|
||||
|
||||
for (const mycat of arrcat) {
|
||||
const mycatstr = mycat.trim();
|
||||
@@ -910,7 +908,7 @@ class Macro {
|
||||
}
|
||||
|
||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||
if (myriscat) productInfo.idCatProds.push(myriscat);
|
||||
if (myriscat) product.productInfo.idCatProds.push(myriscat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -922,13 +920,13 @@ class Macro {
|
||||
/**
|
||||
* Gestisce gli autori del prodotto.
|
||||
*/
|
||||
async gestisciAutori(productInfo, product) {
|
||||
async gestisciAutori(product) {
|
||||
if (product.Autore) {
|
||||
let arrAuthor = [];
|
||||
if (product.id_wp) arrAuthor = this.estraiAutori_FDV(product.Autore);
|
||||
else arrAuthor = this.estraiAutori(product.Autore);
|
||||
|
||||
productInfo.idAuthors = [];
|
||||
product.productInfo.idAuthors = [];
|
||||
|
||||
for (const author of arrAuthor) {
|
||||
const recauthor = await Author.findOne({
|
||||
@@ -944,7 +942,7 @@ class Macro {
|
||||
}
|
||||
|
||||
const myrisautore = recauthor?._id || (nuovoAutore ? nuovoAutore._id : '');
|
||||
if (myrisautore) productInfo.idAuthors.push(myrisautore);
|
||||
if (myrisautore) product.productInfo.idAuthors.push(myrisautore);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -995,9 +993,9 @@ class Macro {
|
||||
/**
|
||||
* Gestisce l'editore del prodotto.
|
||||
*/
|
||||
async gestisciEditore(productInfo, product) {
|
||||
if (productInfo.publisher) {
|
||||
const publisher = productInfo.publisher.trim();
|
||||
async gestisciEditore(product) {
|
||||
if (product.productInfo.publisher) {
|
||||
const publisher = product.productInfo.publisher.trim();
|
||||
const recpublisher = await Publisher.findOne({ idapp: this.idapp, name: publisher }).lean();
|
||||
|
||||
let nuovoEditore = null;
|
||||
@@ -1009,14 +1007,14 @@ class Macro {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (recpublisher?._id || nuovoEditore?._id) productInfo.idPublisher = recpublisher?._id || nuovoEditore._id;
|
||||
if (recpublisher?._id || nuovoEditore?._id) product.productInfo.idPublisher = recpublisher?._id || nuovoEditore._id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gestisce la collana del prodotto.
|
||||
*/
|
||||
async gestisciCollana(productInfo, product) {
|
||||
async gestisciCollana(product) {
|
||||
if (product.collezione && product.numCollana) {
|
||||
const collana = product.collezione.trim();
|
||||
const reccollana = await Collana.findOne({ idapp: this.idapp, title: collana }).lean();
|
||||
@@ -1030,17 +1028,17 @@ class Macro {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (reccollana?._id || nuovaCollana?._id) productInfo.idCollana = reccollana?._id || nuovaCollana._id;
|
||||
if (reccollana?._id || nuovaCollana?._id) product.productInfo.idCollana = reccollana?._id || nuovaCollana._id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiorna l'immagine se necessario.
|
||||
*/
|
||||
async aggiornaImmagineSeNecessario(productInfo) {
|
||||
const { prodInfo, aggiornatoimg } = await tools.downloadImgIfMissing(productInfo);
|
||||
async aggiornaImmagineSeNecessario(product) {
|
||||
const { prodInfo, aggiornatoimg } = await tools.downloadImgIfMissing(product);
|
||||
if (aggiornatoimg) {
|
||||
await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: prodInfo });
|
||||
await Product.findOneAndUpdate({ _id: product._id }, { $set: { productInfo: prodInfo } });
|
||||
}
|
||||
|
||||
return aggiornatoimg;
|
||||
|
||||
@@ -2,7 +2,6 @@ const axios = require('axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const Product = require('../models/product');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
@@ -96,9 +95,9 @@ class AmazonBookScraper {
|
||||
}
|
||||
}
|
||||
|
||||
getTitleByProductInfo(productInfo) {
|
||||
getTitleByProduct(product) {
|
||||
try {
|
||||
return productInfo?.name.trim();
|
||||
return product?.productInfo.name.trim();
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
@@ -107,9 +106,9 @@ class AmazonBookScraper {
|
||||
async extractData(myproduct, html, url, isbn10) {
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const productInfo = await ProductInfo.findOne({ _id: myproduct.idProductInfo }).lean();
|
||||
const product = await Product.findOne({ _id: myproduct._id }).lean();
|
||||
|
||||
const title_ondb = this.getTitleByProductInfo(productInfo);
|
||||
const title_ondb = this.getTitleByProduct(product);
|
||||
|
||||
// Titolo
|
||||
let title = $('#productTitle').text().trim() || null;
|
||||
@@ -247,6 +246,7 @@ class AmazonBookScraper {
|
||||
|
||||
async scrapeISBN(myproduct, isbn, options) {
|
||||
try {
|
||||
const product = await Product.findOne({ _id: myproduct._id }).lean();
|
||||
const datastored = await this.findRecordMyScrapingBookByIsbn(isbn);
|
||||
|
||||
let data = null;
|
||||
@@ -289,7 +289,6 @@ class AmazonBookScraper {
|
||||
if (index < 0) index = 0;
|
||||
}
|
||||
|
||||
const productInfo = {};
|
||||
let aggiornaDataPubb = false;
|
||||
|
||||
let aggiornaPages = false;
|
||||
@@ -325,17 +324,17 @@ class AmazonBookScraper {
|
||||
}
|
||||
|
||||
// Determina se aggiornare data pubblicazione
|
||||
const currentDatePub = myproduct.idProductInfo.date_pub;
|
||||
const currentDatePub = myproduct.productInfo.date_pub;
|
||||
aggiornaDataPubb =
|
||||
(!options.aggiornasoloSeVuoti || !tools.isDateValid(currentDatePub)) &&
|
||||
tools.isDateValid(data.data_pubblicazione);
|
||||
if (aggiornaDataPubb && data.data_pubblicazione) {
|
||||
productInfo.date_pub = new Date(data.data_pubblicazione);
|
||||
product.productInfo.date_pub = new Date(data.data_pubblicazione);
|
||||
}
|
||||
|
||||
aggiornaSottotitolo = (!options.aggiornasoloSeVuoti || !myproduct.idProductInfo.sottotitolo) && data.sottotitolo;
|
||||
aggiornaSottotitolo = (!options.aggiornasoloSeVuoti || !myproduct.productInfo.sottotitolo) && data.sottotitolo;
|
||||
if (aggiornaSottotitolo && data.sottotitolo) {
|
||||
productInfo.sottotitolo = data.sottotitolo;
|
||||
product.productInfo.sottotitolo = data.sottotitolo;
|
||||
}
|
||||
|
||||
aggiornaSottotitolo = false; // !! PER ORA LO DISATTIVO PERCHE' non esiste sempre il sottotitolo in un libro.
|
||||
@@ -373,9 +372,9 @@ class AmazonBookScraper {
|
||||
if (aggiornaProductInfo) {
|
||||
// Aggiorna productInfo se contiene dati
|
||||
if (!tools.isObjectEmpty(productInfo)) {
|
||||
risupdate = await ProductInfo.findOneAndUpdate(
|
||||
{ _id: myproduct.idProductInfo },
|
||||
{ $set: productInfo },
|
||||
risupdate = await Product.findOneAndUpdate(
|
||||
{ _id: myproduct._id },
|
||||
{ $set: { productInfo: product.productInfo } },
|
||||
{ new: true, upsert: true, includeResultMetadata: true }
|
||||
).lean();
|
||||
}
|
||||
@@ -384,7 +383,7 @@ class AmazonBookScraper {
|
||||
|
||||
const concatenatedProduct = {
|
||||
...recModificato,
|
||||
...productInfo,
|
||||
...product.productInfo,
|
||||
};
|
||||
|
||||
if (updated) {
|
||||
|
||||
Reference in New Issue
Block a user