- fix RIS in pendenti, se troppi msg, non compariva piu

- cataloghi, ricerca pickup
This commit is contained in:
Surya Paolo
2024-05-09 23:36:46 +02:00
parent 54443e784e
commit 3b1b2b9c83
13 changed files with 296 additions and 94 deletions

View File

@@ -46,7 +46,7 @@ module.exports.executeQueryTable = function (idapp, params) {
module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await Author.find(myfind);
return await Author.find(myfind).sort({name: 1, surname: 1});
};
module.exports.createIndexes((err) => {

View File

@@ -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);
}

View File

@@ -161,18 +161,24 @@ sendNotifSchema.statics.getRecNotif = function (id) {
};
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp, limitrecord) {
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp, limitrecord, typedir) {
const SendNotif = this;
if (!lastdataread)
lastdataread = 0;
let arrfilter = [
{ idapp },
{ dest: username },
{ datenotif: { $gt: new Date(lastdataread) } }
];
if (typedir) {
arrfilter.push({typedir});
}
return SendNotif.find({
$and: [
{ idapp },
{ 'dest': username },
{ 'datenotif': { $gt: new Date(lastdataread) } },
],
$and: arrfilter,
}).lean().limit(limitrecord).sort({ datenotif: -1 }).then(async (arrnotif) => {
// console.log('arrnotif', arrnotif.length);
@@ -612,6 +618,7 @@ sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function (username, ida
$match: {
idapp,
dest: username,
typedir: { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS },
},
},
{ $limit: limit },
@@ -627,6 +634,38 @@ sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function (username, ida
};
sendNotifSchema.statics.findLastNotifCoinsByUserIdAndIdApp = function (username, idapp, limit, inattesa) {
const SendNotif = this;
let filter = {
idapp,
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
dest: username,
}
if (inattesa) {
filter.status = 0;
} else {
filter.status = { $ne: 0 };
}
return SendNotif.aggregate([
{
$match: filter,
},
{ $limit: limit },
{
$sort: { datenotif: -1 },
},
]).then(async (arrnotif) => {
return this.compileOtherFields(arrnotif);
}).catch((err) => {
console.error(err);
});
};
sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res, user) {
const SendNotif = this;
@@ -1097,18 +1136,18 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
}
}
/*} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
send = true;
/*} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
send = true;
}
}
}
} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.CircuitsNotif.STATUS_NEW)) {
send = true;
}
}*/
} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.CircuitsNotif.STATUS_NEW)) {
send = true;
}
}*/
}
if (send) {

View File

@@ -3281,7 +3281,8 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
}
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
outres.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
} else {
outres.cansend = false;