Aggiornamento cataloghi...

This commit is contained in:
Surya Paolo
2025-04-11 18:49:59 +02:00
parent e1ca4ef17f
commit 8e8a3204a7
13 changed files with 509 additions and 88 deletions

View File

@@ -116,7 +116,7 @@ async function findOrCreateCatProd(idapp, idArgomento, DescrArgomento) {
function updateProductInfoCatProds(productInfo, reccatprod) {
if (productInfo) {
// Controllo che nell'array productInfo.idCatProds ci sia esattamente 1 record e che sia uguale a reccatprod._id
const cond3 = Array.isArray(productInfo.idCatProds) && productInfo.idCatProds[0].toString() !== reccatprod._id.toString();
const cond3 = Array.isArray(productInfo.idCatProds) && productInfo.idCatProds.length > 0 && productInfo.idCatProds[0].toString() !== reccatprod._id.toString();
const isChanged =
!Array.isArray(productInfo.idCatProds) || // Assicurati che sia un array
productInfo.idCatProds.length !== 1 || // L'array deve contenere esattamente 1 elemento
@@ -903,6 +903,8 @@ router.post('/import', authenticate, async (req, res) => {
const trovato = await ImportaIsbn.findOne({ isbn: product.code }).lean();
if (trovato) {
// togli a recisbn l'_id
delete trovato._id;
recisbn = trovato;
}
@@ -916,14 +918,18 @@ router.post('/import', authenticate, async (req, res) => {
recisbn.sottotitolo = productInfo.sottotitolo;
// recisbn.idapp = idapp;
let risisbn = await ImportaIsbn.findOneAndUpdate({ isbn: product.code }, { $set: recisbn }, { new: true, upsert: true, strict: false });
try {
let risisbn = await ImportaIsbn.findOneAndUpdate({ isbn: product.code }, { $set: recisbn }, { new: true, upsert: true, strict: false });
// Update ProductInfo, non crea nuovi record !
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: false });
// Update ProductInfo, non crea nuovi record !
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: false });
indprod++;
if (indprod % 100 === 0)
console.log(indprod + '/' + numprod);
indprod++;
if (indprod % 100 === 0)
console.log(indprod + '/' + numprod);
} catch (e) {
console.error(e);
}
}
}
@@ -1052,6 +1058,7 @@ router.post('/import', authenticate, async (req, res) => {
totFat: product.totFat || 0,
vLast3M: product.vLast3M || 0,
fatLast3M: product.fatLast3M || 0,
fatLast6M: product.fatLast6M || 0,
vLast6M: product.vLast6M || 0,
vLastY: product.vLastY || 0,
vLast2Y: product.vLast2Y || 0,
@@ -1120,7 +1127,7 @@ router.post('/import', authenticate, async (req, res) => {
let imported = 0;
let errors = 0;
const ripopola = false; //++MODIFICARE!
const ripopola = true; //++MODIFICARE!
if (ripopola) {
dataObjects = null;
@@ -1221,7 +1228,12 @@ router.post('/import', authenticate, async (req, res) => {
// se non esiste l'ISBN, allora me lo cerco in base a sku !
if (!product.isbn) {
let trova = false
if (product._id === '30310') {
trova = true
}
if (!product.isbn || product.isbn.startsWith('field')) {
const rectrovare = await ImportaIsbn.findOne({ sku: product.sku }).lean();
if (rectrovare) {
// se l'isbn non inizia con 'field' allora è buono