- corretto gruppomacro catalogo, info prodotti, estrazione dati da amazon corretto.

This commit is contained in:
Surya Paolo
2025-09-27 17:24:46 +02:00
parent 08cf4b6d9f
commit 1d52ab1d08
10 changed files with 214 additions and 165 deletions

View File

@@ -974,20 +974,6 @@ async function completaSettaggioProduct_AndProductInfo(
}
}
if (rec.hasOwnProperty('old_code')) {
const old_code = rec['old_code'];
let oldrec = await ProductInfo.findOne({ code: old_code }).lean();
if (oldrec) {
const precid = productInfo._id;
const preccode = productInfo.code;
productInfo = oldrec;
if (precid) productInfo._id = precid;
else delete productInfo._id;
productInfo.code = preccode;
}
}
if (rec.hasOwnProperty('productTypes')) {
productInfo.productTypes = productInfo.productTypes;
} else {
@@ -1291,7 +1277,7 @@ router.post('/import', authenticate, async (req, res) => {
);
// Update ProductInfo, non crea nuovi record !
let risrecInfo = await ProductInfo.findOneAndUpdate(
let risrecInfo = await Product.findOneAndUpdate(
{ code: productInfo.code },
{ $set: productInfo },
{ new: true, upsert: false }
@@ -1413,7 +1399,7 @@ router.post('/import', authenticate, async (req, res) => {
if (risrecInfo) {
productImported.productInfo = risrecInfo._id;
recnewInfo = await ProductInfo.findOne({ code: productInfo.code }).lean();
recnewInfo = await Product.findOne({ code: product.code }).lean();
if (risrecInfo._id) {
// Record existed, so it was updated
@@ -1564,22 +1550,20 @@ router.post('/import', authenticate, async (req, res) => {
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
}
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
let esisteindb = await Product.findOne({ code: productInfo.code }).lean();
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate(
{ code: productInfo.code },
{ $set: productInfo },
// Update Product
let risrecInfo = await Product.findOneAndUpdate(
{ code: product.code },
{ $set: product },
{ new: true, upsert: true }
);
if (risrecInfo) {
product.idProductInfo = risrecInfo._id;
recnewInfo = await ProductInfo.findOne({ code: productInfo.code }).lean();
recnewInfo = await Product.findOne({ code: product.code }).lean();
if (risrecInfo._id) {
// Record existed, so it was updated
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo);
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo.productInfo);
if (arrfieldchange && arrfieldchange.length > 0) {
// updated++;
console.log('Changed: ', recnewInfo.name + ': ' + arrfieldchange);