- 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

@@ -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) {