- fix RIS in pendenti, se troppi msg, non compariva piu
- cataloghi, ricerca pickup
This commit is contained in:
@@ -227,6 +227,119 @@ module.exports.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.executeQueryPickup = async function (idapp, params) {
|
||||
|
||||
let strfind = params.search;
|
||||
|
||||
strfind = strfind.replace(/[-@]/g, '');
|
||||
|
||||
if (strfind === '' && !params.filter) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let filterfindexact = {};
|
||||
if (strfind) {
|
||||
filterfindexact = { comune: strfind };
|
||||
}
|
||||
|
||||
let limit = 10;
|
||||
let risexact = [];
|
||||
|
||||
let filterfind = {
|
||||
idapp,
|
||||
'productInfo.name': {
|
||||
$regex: `\\b${strfind}`, // Usa \\b per trovare solo le parole che iniziano con strfind
|
||||
$options: 'i' // Rendi la ricerca case-insensitive
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
let aggr1 = [
|
||||
{
|
||||
$lookup: {
|
||||
from: 'productinfos',
|
||||
localField: 'idProductInfo',
|
||||
foreignField: '_id',
|
||||
as: 'productInfo'
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'authors',
|
||||
localField: 'idAuthors',
|
||||
foreignField: '_id',
|
||||
as: 'authors'
|
||||
}
|
||||
},
|
||||
{
|
||||
$match: { 'productInfo.name': strfind },
|
||||
},
|
||||
{ $limit: 1 },
|
||||
{
|
||||
$project: {
|
||||
name: { $concat: ["$productInfo.name", " (", "$authors", ")"] },
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
if (params.filter) {
|
||||
filterfind = { ...params.filter, ...filterfind };
|
||||
limit = 200;
|
||||
} else {
|
||||
// risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
|
||||
risexact = await City.aggregate(aggr1);
|
||||
}
|
||||
*/
|
||||
|
||||
if (params.filter) {
|
||||
filterfind = { ...params.filter, ...filterfind };
|
||||
limit = 200;
|
||||
}
|
||||
|
||||
let aggr2 = [
|
||||
{
|
||||
$lookup: {
|
||||
from: 'productinfos',
|
||||
localField: 'idProductInfo',
|
||||
foreignField: '_id',
|
||||
as: 'productInfo'
|
||||
}
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$productInfo',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'authors',
|
||||
localField: 'idAuthors',
|
||||
foreignField: '_id',
|
||||
as: 'authors'
|
||||
}
|
||||
},
|
||||
{
|
||||
$match: filterfind,
|
||||
},
|
||||
{ $limit: limit },
|
||||
{
|
||||
$project: {
|
||||
name: '$productInfo.name',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
// let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(limit);
|
||||
let ris = await this.aggregate(aggr2).limit(limit);
|
||||
|
||||
return [...risexact, ...ris];
|
||||
|
||||
};
|
||||
|
||||
|
||||
module.exports.getProductByCode = function (idapp, code) {
|
||||
return Product.findAllIdApp(idapp, code);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user