aggiornamento cataloghi, search

This commit is contained in:
Surya Paolo
2025-04-22 18:30:48 +02:00
parent ad45ce60ee
commit 58431c144c
9 changed files with 194 additions and 42 deletions

View File

@@ -262,7 +262,7 @@ module.exports.executeQueryPickup = async function (idapp, params) {
$or: [
{
'productInfo.name': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind
$regex: `(?i).*${tools.removeAccents(strfind)}.*`, // Cerca una o più parole che sono contenute
$options: 'i' // Rende la ricerca case-insensitive
}
},
@@ -273,20 +273,17 @@ module.exports.executeQueryPickup = async function (idapp, params) {
}
},
{
'productInfo.sku': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind
$options: 'i' // Rende la ricerca case-insensitive
}
'productInfo.sku': strfind
},
{
'productInfo.authors.name': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind nel nome dell'autore
$regex: `(?i).*${tools.removeAccents(strfind)}.*`, // Cerca una o più parole che sono contenute
$options: 'i' // Rende la ricerca case-insensitive
}
},
{
'productInfo.authors.surname': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind nel cognome dell'autore
$regex: `(?i)\\b${tools.removeAccents(strfind)}\\b`, // Cerca parole che iniziano con strfind, e ignora gli accenti
$options: 'i' // Rende la ricerca case-insensitive
}
},
@@ -336,8 +333,9 @@ module.exports.executeQueryPickup = async function (idapp, params) {
name: '$productInfo.name', // Nome del prodotto
authors: '$productInfo.authors',
productInfo: {
name: '$productInfo.name', // Nome del prodotto
name: '$productInfo.name', // Nome dell'autore
authors: '$productInfo.authors',
idStatoProdotto: "$productInfo.idStatoProdotto",
},
}
}

View File

@@ -58,9 +58,9 @@ mongoose.plugin(schema => {
*/
const T_WEB_ArticoliSchema = new Schema({
IdArticolo: { type: Number, index: true },
Ean13: { type: String, index: true },
Titolo: { type: String, index: true },
IdArticolo: { type: Number },
Ean13: { type: String },
Titolo: { type: String },
ListaAutori: String,
ListaArgomenti: String,
IdStatoProdotto: Number,
@@ -101,7 +101,7 @@ const T_WEB_ArticoliSchema = new Schema({
module.exports = mongoose.model('T_WEB_Articoli', T_WEB_ArticoliSchema);
module.exports.createIndexes()
module.exports.createIndexes({ IdArticolo: 1, DataOra: -1 })
.then(() => { })
.catch((err) => { throw err; });

View File

@@ -0,0 +1,52 @@
const mongoose = require('mongoose');
const TWebDisponibileSchema = new mongoose.Schema({
Progressivo: {
type: mongoose.Schema.Types.Long || Number, // Usa 'mongoose-long' se vuoi long int
required: true,
unique: true,
},
Codice: {
type: String,
maxlength: 50,
required: true,
index: true, // usato nei lookup e nei match
},
QtaDisponibile: {
type: mongoose.Decimal128,
default: 0,
},
Giac: {
type: mongoose.Decimal128,
default: 0,
},
DataOra: {
type: Date,
default: Date.now,
index: true, // per ordinamento
},
Enabled: {
type: Boolean,
default: true,
},
DataOraSito: {
type: Date,
},
Ean13: {
type: String,
maxlength: 20,
},
QtaDisponibileOld: {
type: Number,
default: 0,
},
}, {
collection: 't_web_disponibiles', // nome della collezione esatto
timestamps: false,
});
module.exports = mongoose.model('TWebDisponibile', TWebDisponibileSchema);
module.exports.createIndexes()
.then(() => { })
.catch((err) => { throw err; });

View File

@@ -30,29 +30,33 @@ module.exports.findAllIdApp = async function () {
const myfind = {};
const myquery = [
{
$sort: { DataOra: -1 } // Prima ordina per DataOra in modo decrescente
},
{
$group: {
_id: "$IdStatoProdotto",
record: { $max: "$DataOra" }
_id: "$IdStatoProdotto", // Raggruppa per IdStatoProdotto
latestRecord: { $first: "$$ROOT" } // Prendi il primo record per ogni gruppo (cioè il più recente)
}
},
{
$lookup: {
from: 't_web_statiprodottos',
localField: '_id',
localField: '_id', // Usa _id che è l'IdStatoProdotto
foreignField: 'IdStatoProdotto',
as: 'record'
}
},
{
$replaceRoot: { newRoot: { $arrayElemAt: ["$record", 0] } }
$replaceRoot: { newRoot: { $arrayElemAt: ["$record", 0] } } // Estrai il primo (e unico) record dal risultato di $lookup
},
{
$sort: { IdStatoProdotto: 1 }
$sort: { IdStatoProdotto: 1 } // Ordina per IdStatoProdotto, se necessario
}
];
return await T_WEB_StatiProdotto.aggregate(myquery);
const rec = await T_WEB_StatiProdotto.aggregate(myquery);
return rec;
};

View File

@@ -804,7 +804,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
}, project);
}
const end_find = process.hrtime.bigint();
console.log(` User.findOne impiega ${Math.round(Number(end_find - start_find) / 1e6) / 1000} secondi.`);
// console.log(` User.findOne impiega ${Math.round(Number(end_find - start_find) / 1e6) / 1000} secondi.`);
} else {
project = { perm: 1, _id: 1, idapp: 1, username: 1, deleted: 1, aportador_solidario: 1, aportador_solidario_nome_completo: 1, 'profile.socioresidente': 1 };
@@ -822,6 +822,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
const end_find = process.hrtime.bigint();
// console.log(` User.findOne LEAN impiega ${Math.round(Number(end_find - start_find) / 1e6) / 1000} secondi.`);
}
if (user) {
const checkExpiry = tools.getEnableTokenExpiredByIdApp(user.idapp);