- 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

@@ -1,11 +1,11 @@
DATABASE=test_PiuCheBuono
DATABASE=test_FreePlanet
UDB=paofreeplanet
PDB=mypassword@1A
SEND_EMAIL=0
SEND_EMAIL_ORDERS=1
PORT=3000
appTelegram_TEST=["1","17","18"]
appTelegram=["1","17","18"]
appTelegram_TEST=["1","13"]
appTelegram=["1","13"]
DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=1
MONGODB_USER=admin

View File

@@ -185,3 +185,7 @@ Gio 25/04 ORE 14:37: [<b>Circuito RIS Bologna</b>]: Inviate Monete da paoloar77
Saldi:
paoloar77: 0 RIS]
SuryaArena: 37 RIS]
Gio 09/05 ORE 17:27: [<b>Circuito RIS Catania</b>]: Inviate Monete da paoloar77 a Giovannifruttadisicilia 1.5 RIS [causale: prova]
Saldi:
paoloar77: -1.50 RIS]
Giovannifruttadisicilia: 1.50 RIS]

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;
return SendNotif.find({
$and: [
let arrfilter = [
{ idapp },
{ 'dest': username },
{ 'datenotif': { $gt: new Date(lastdataread) } },
],
{ dest: username },
{ datenotif: { $gt: new Date(lastdataread) } }
];
if (typedir) {
arrfilter.push({typedir});
}
return SendNotif.find({
$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;

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;

View File

@@ -461,7 +461,7 @@ router.post('/import', authenticate, async (req, res) => {
name: arrrecauthor[i].trim()
}
if (arrrecauthor.length > i + 1) {
surname = arrrecauthor[i + 1].trim()
author.surname = arrrecauthor[i + 1].trim()
}
arrAuthor.push(author);
} catch (e) {
@@ -513,6 +513,7 @@ router.post('/import', authenticate, async (req, res) => {
}
}
if (productInfo.publisher) {
try {
publisher = productInfo.publisher.trim();
// Cerca la Sotto Categoria
let recpublisher = await Publisher.findOne({ idapp, name: publisher }).lean();
@@ -524,7 +525,10 @@ router.post('/import', authenticate, async (req, res) => {
}
if (recpublisher) {
productInfo.idPublisher.push(recpublisher._id);
productInfo.idPublisher = recpublisher._id;
}
} catch (e) {
console.error(e);
}
}

View File

@@ -84,13 +84,14 @@ router.post('/load', authenticate, async (req, res) => {
data.account = await Account.getAccountByUsernameAndCircuitId(idapp, '', data._id, false, false, '', data.path);
}
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
const arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
/// E' QUIIII !!!!
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);
await User.setLastCircuitOpened(idapp, req.user.username, path);
res.send({ circuit: data, users_in_circuit, arrrecnotif, useraccounts });
res.send({ circuit: data, users_in_circuit, arrrecnotif, arrrecnotifcoins, useraccounts });
} catch (e) {
console.error('Error in Circuits', e);

View File

@@ -73,6 +73,7 @@ const CatAI = require('../models/catai');
const SubCatProd = require('../models/subcatprod');
const Gasordine = require('../models/gasordine');
const Product = require('../models/product');
const Author = require('../models/author');
const ProductInfo = require('../models/productInfo');
const Scontistica = require('../models/scontistica');
const Department = require('../models/department');
@@ -1488,6 +1489,7 @@ function load(req, res, version) {
} catch (e) {
}
let products = Product.findAllIdApp(idapp, undefined, undefined, ismanager);
let authors = Author.findAllIdApp(idapp);
let productInfos = ProductInfo.findAllIdApp(idapp);
let scontisticas = Scontistica.findAllIdApp(idapp);
let departments = Department.findAllIdApp(idapp);
@@ -1584,6 +1586,7 @@ function load(req, res, version) {
subcatprods,
catprods_gas,
catAI,
authors,
]).then((arrdata) => {
// console.table(arrdata);
let myuser = req.user;
@@ -1676,6 +1679,7 @@ function load(req, res, version) {
catprods_gas: arrdata[47],
catAI: arrdata[48],
code: req.code,
authors: arrdata[49],
});
const prova = 1;
@@ -1696,7 +1700,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
return res.status(200).send();
}
await CfgServer.find({ idapp }).then((arrcfgrec) => {
await CfgServer.find({ idapp }).then(async (arrcfgrec) => {
if (!arrcfgrec)
return res.status(404).send();
@@ -1705,6 +1709,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
let last_msgs = null;
let last_notifs = null;
let last_notifcoins = null;
let usersList = null;
// const sall = '0';
@@ -1718,6 +1723,8 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 200, true);
last_notifcoins = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 1, false);
if (req.user) {
// If User is Admin, then send user Lists
@@ -1731,13 +1738,14 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
}
}
return Promise.all([usersList, last_msgs, last_notifs]).then((arrdata) => {
return Promise.all([usersList, last_msgs, last_notifs, last_notifcoins, last_notifcoins_inattesa]).then((arrdata) => {
// console.table(arrdata);
return res.send({
CfgServer: arrcfgrec,
usersList: arrdata[0],
last_msgs: arrdata[1],
last_notifs: arrdata[2],
last_notifcoins: [...arrdata[4], ...arrdata[3]],
});
});

View File

@@ -44,7 +44,7 @@ router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS) {
query.typedir = { $eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
} else if (qualinotif === shared_consts.QualiNotifs.OTHERS) {
query.typedir = {$neq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
}
const arrNotifs = await SendNotif.find(query).lean();
if (arrNotifs) {
@@ -83,17 +83,13 @@ router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
});
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
const idapp = req.params.idapp;
const username = req.params.username;
const myid = req.params.id;
const username_call = req.user.username;
async function delNotif(idapp, username, id, username_call) {
try {
if (username === username_call) {
await SendNotif.findOneAndRemove({idapp, _id: myid});
await SendNotif.findOneAndRemove({ idapp, _id: id });
return res.send(true);
}
} catch (e) {
@@ -102,8 +98,19 @@ router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
return res.send(false);
};
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
try {
return delNotif(req.params.idapp, req.params.username, req.params.id, req.user.username);
} catch (e) {
return res.status(400).send(e);
}
});
router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
const idapp = req.params.idapp;
@@ -118,7 +125,7 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS) {
query.typedir = { $eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
} else if (qualinotif === shared_consts.QualiNotifs.OTHERS) {
query.typedir = {$neq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
}
const ris = await SendNotif.deleteMany(query);
if (ris)
@@ -133,10 +140,22 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
});
router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
return getNotif(req, res);
});
router.get('/:username/:lastdataread/:idapp/:qualinotif', authenticate, (req, res) => {
return getNotif(req, res);
});
function getNotif(req, res) {
try {
// tools.mylog('GET NotifS : ', req.params);
const username = req.params.username;
const lastdataread = req.params.lastdataread;
const idapp = req.params.idapp;
const qualinotif = req.params.qualinotif;
// var category = req.params.category;
if (req.user.idapp !== idapp) {
@@ -144,7 +163,7 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
}
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER).then(async (arrnotif) => {
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, qualinotif).then(async (arrnotif) => {
// const wait = new Promise((resolve, reject) => {
// setTimeout(() => {
@@ -157,7 +176,9 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
console.log(e.message);
res.status(400).send(e);
});
});
} catch (e) {
console.log(e.message);
}
};
module.exports = router;

View File

@@ -902,9 +902,8 @@ router.post('/updatesaldo', authenticate, async (req, res) => {
userprofile
}
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
ris.arrrecnotif = arrrecnotif;
ris.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
ris.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
return res.send({ ris });

View File

@@ -940,7 +940,7 @@ const MyTelegramBot = {
keyb = cl.getInlineKeyboard(myuser.lang, [
{
text: '✅ Abilita ' + myuser.username,
text: '✅ Ammetti ' + myuser.username,
callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + userDest,
},
/*{

View File

@@ -2017,6 +2017,18 @@ module.exports = {
return query;
},
sanitizzaHtml(html) {
try {
return sanitizeHtml(html);
} catch (e) {
return html
}
},
sanitizzaLookup: function (str) {
return str;
},
sanitizzaProjection: function (mioproj) {
// mioproj = {valore: '$password'};
@@ -2406,8 +2418,8 @@ module.exports = {
let query = [];
if (params.filter && params.fieldsearch) {
params.filter = sanitizeHtml(params.filter);
params.fieldsearch = sanitizeHtml(params.fieldsearch);
params.filter = this.sanitizzaHtml(params.filter);
params.fieldsearch = this.sanitizzaHtml(params.fieldsearch);
const querytemp = this.getFilterParam(params.filter, params.fieldsearch);
if (querytemp) {
query = [...query, ...querytemp];
@@ -2424,7 +2436,7 @@ module.exports = {
// }
if (params.filterand) {
params.filterand = sanitizeHtml(params.filterand);
params.filterand = this.sanitizzaHtml(params.filterand);
if (params.filterand.includes(
shared_consts.FILTER_EXTRALIST_NOT_REGISTERED))
@@ -2545,7 +2557,7 @@ module.exports = {
}
if (params.filtercustom) {
params.filtercustom = sanitizeHtml(params.filtercustom);
params.filtercustom = this.sanitizzaHtml(params.filtercustom);
let condition = {};
for (const myfilter of params.filtercustom) {
if (myfilter['userId']) {
@@ -2572,7 +2584,7 @@ module.exports = {
}
if (params.filter_gte) {
params.filter_gte = sanitizeHtml(params.filter_gte);
params.filter_gte = this.sanitizzaHtml(params.filter_gte);
for (let ind = 0; ind < params.filter_gte.length; ind++) {
for (const [key, value] of Object.entries(params.filter_gte[ind])) {
if (value > 0) {
@@ -2585,7 +2597,7 @@ module.exports = {
}
if (params.filtersearch) {
params.filtersearch = sanitizeHtml(params.filtersearch);
params.filtersearch = this.sanitizzaHtml(params.filtersearch);
filtriadded.push(...params.filtersearch);
}
@@ -2597,13 +2609,13 @@ module.exports = {
if (params.filterextra) {
params.filterextra = sanitizeHtml(params.filterextra);
params.filterextra = this.sanitizzaHtml(params.filterextra);
if (params.filterextra.length > 0)
query = [...query, ...params.filterextra]
}
if (filtriadded) {
filtriadded = sanitizeHtml(filtriadded);
filtriadded = this.sanitizzaHtml(filtriadded);
if (filtriadded.length > 0)
query.push({ $match: { $and: filtriadded } });
}