- corretto gruppomacro catalogo, info prodotti, estrazione dati da amazon corretto.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -386,7 +386,10 @@ router.post('/search-books', authenticate, async (req, res) => {
|
||||
for (const book of books) {
|
||||
let trovatoISBN = false;
|
||||
let trovato = false;
|
||||
let productfind = null;
|
||||
|
||||
for (let field of book) {
|
||||
|
||||
field = field.trim();
|
||||
let valido = typeof field === 'string' && field.length > 4 && field.length < 50;
|
||||
if (valido) {
|
||||
@@ -400,7 +403,7 @@ router.post('/search-books', authenticate, async (req, res) => {
|
||||
|
||||
// Priorità se lo trovo per ISBN:
|
||||
if (productInfoarrISBN.length === 1) {
|
||||
productInfo = productInfoarrISBN[0];
|
||||
productfind = productInfoarrISBN[0];
|
||||
trovatoISBN = true;
|
||||
trovato = true;
|
||||
}
|
||||
@@ -412,12 +415,12 @@ router.post('/search-books', authenticate, async (req, res) => {
|
||||
'productInfo.name': field,
|
||||
}).exec();
|
||||
if (productarrTitle.length === 1) {
|
||||
productInfo = productarrTitle[0];
|
||||
productfind = productarrTitle[0];
|
||||
trovato = true;
|
||||
} else {
|
||||
if (productarrTitle.length > 1) {
|
||||
// Prendi l'Ultimo !
|
||||
productInfo = productarrTitle[productarrTitle.length - 1];
|
||||
productfind = productarrTitle[productarrTitle.length - 1];
|
||||
trovato = true;
|
||||
}
|
||||
}
|
||||
@@ -428,12 +431,12 @@ router.post('/search-books', authenticate, async (req, res) => {
|
||||
'productInfo.name': new RegExp(`.*${escapeRegExp(tools.removeAccents(field.toUpperCase()))}.*`, 'i'),
|
||||
}).exec();
|
||||
if (productarrTitle.length === 1) {
|
||||
productInfo = productarrTitle[0];
|
||||
productfind = productarrTitle[0];
|
||||
trovato = true;
|
||||
} else {
|
||||
if (productarrTitle.length > 1) {
|
||||
// Prendi l'Ultimo !
|
||||
productInfo = productarrTitle[productarrTitle.length - 1];
|
||||
productfind = productarrTitle[productarrTitle.length - 1];
|
||||
trovato = true;
|
||||
}
|
||||
}
|
||||
@@ -444,8 +447,8 @@ router.post('/search-books', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
if (trovato) {
|
||||
if (productInfo) {
|
||||
product = await Product.findOne({ idProductInfo: productInfo._id }).exec();
|
||||
if (productfind) {
|
||||
product = await Product.findOne({ _id: productfind._id }).exec();
|
||||
if (product) {
|
||||
const existingResult = results.find((r) => r._id.toString() === product._id.toString());
|
||||
if (!existingResult) {
|
||||
|
||||
Reference in New Issue
Block a user