correzione numseen, numfav, ...: ora li ho aggiunti alle tabelle...
This commit is contained in:
21
.vscode/launch.json
vendored
21
.vscode/launch.json
vendored
@@ -21,6 +21,27 @@
|
||||
"NODE_ENV":"development",
|
||||
"TESTING_ON":"1"
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Trace Warning",
|
||||
"program": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
|
||||
"restart": true,
|
||||
"runtimeExecutable": "node",
|
||||
"runtimeArgs": [
|
||||
"--trace-warnings" // Use "--inspect=0.0.0.0:9229" for remote debugging
|
||||
],
|
||||
"args": ["${workspaceFolder}/src/server/server.js"], // Replace with your entry file
|
||||
"cwd": "${workspaceFolder}",
|
||||
"autoAttachChildProcesses": true,
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"sourceMaps": true,
|
||||
"env": {
|
||||
"NODE_ENV":"development",
|
||||
"TESTING_ON":"1"
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "Server Debug",
|
||||
|
||||
@@ -43,3 +43,7 @@ Dom 18/06 ORE 19:59: USER [paoloar77]: /start inv
|
||||
Dom 18/06 ORE 19:59: USER [paoloar77]: /start inv
|
||||
|
||||
Ven 23/06 ORE 14:08: USER [paoloar77]: link da condividere
|
||||
|
||||
Sab 30/09 ORE 00:21: USER [SuryaArena]: vai al sito
|
||||
|
||||
Sab 30/09 ORE 00:32: USER [SuryaArena]: vai al sito
|
||||
|
||||
@@ -19,3 +19,5 @@ Ven 23/06 ORE 14:13: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
Dom 25/06 ORE 16:11: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
Ven 29/09 ORE 23:18: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
@@ -21,3 +21,7 @@ Lun 26/06 ORE 23:27: [<b>Circuito RIS Ragusa</b>]: Inviate Monete da paoloar77 a
|
||||
Saldi:
|
||||
paoloar77: -20 RIS]
|
||||
paogruppo2: 320 RIS]
|
||||
Sab 30/09 ORE 13:32: [<b>Circuito RIS Bologna</b>]: Inviate Monete da SuryaArena a paoloar77 1 RIS [causale: aaa]
|
||||
Saldi:
|
||||
SuryaArena: -1 RIS]
|
||||
paoloar77: 11 RIS]
|
||||
@@ -14,7 +14,7 @@
|
||||
"test-watch": "nodemon --exec 'npm test'"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.14.0"
|
||||
"node": "^16.19.0"
|
||||
},
|
||||
"author": "Paolo Arena",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -6,7 +6,12 @@
|
||||
"NEW_GOOD": "❇️ <strong>%s</strong> ha aggiunto un nuovo Bene: \n<strong>%s</strong>",
|
||||
"NEW_SERVICE": "❇️ <strong>%s</strong> ha aggiunto un nuovo Servizio: \n<strong>%s</strong>",
|
||||
"NEW_HOSP": "❇️ <strong>%s</strong> ha aggiunto una nuova Ospitalità: \n<strong>%s</strong>",
|
||||
"NEW_EVENT": "❇️ <strong>%s</strong> ha aggiunto un nuovo Evento: \n<strong>%s</strong>",
|
||||
"NEW_EVENT": "❇️ <strong>%s</strong> ha aggiunto un nuovo Evento: \n%s\n<strong>%s</strong>\n%s",
|
||||
"NEW_EVENT_TELEGRAM": "%s\n\n❇️ <strong>%s</strong>\n\n%s\n\n%s",
|
||||
"ADDED_FROM": "\n\n<i>(Evento aggiunto da <strong>%s</strong>)</i>",
|
||||
"CONTRIB": "\n💠 Contributo richiesto: %s",
|
||||
"ORGANIZED_BY": "\n<i>Organizzato da <strong>%s</strong></i>",
|
||||
"SHOW_POST": "👉🏻 vedi post su RISO",
|
||||
"OPEN PAGE": "<em>APRI la APP RISO oppure visita riso.app</em>",
|
||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> ti ha chiesto l'Amicizia",
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia",
|
||||
@@ -68,7 +73,7 @@
|
||||
"CIRCUIT_REMOVED_TO_ME": "❌ Sei stato rimosso dal '%s' (da parte di %s)",
|
||||
"CIRCUIT_SENDCOINSREQ": "%s ti sta inviando <strong>%s %s</strong> sul '%s'.",
|
||||
"COMUNITARIO": "Comunitario",
|
||||
"COLLETTIVO": "Collettivo",
|
||||
"COLLETTIVO": "Gruppo",
|
||||
"CIRCUIT_SENDCOINSREQ_GROUP": "%s sta inviando <strong>%s %s</strong> al Conto %s '%s' sul '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_USER": "il conto %s '%s' (%s) sta inviando <strong>%s %s</strong> a %s sul '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_YOU": "il conto %s '%s' (%s) ti sta inviando <strong>%s %s</strong> sul '%s'",
|
||||
@@ -98,5 +103,7 @@
|
||||
"EVENT_SEND_MSG": "%s ha mandato un messaggio sull'evento %s: \n%s",
|
||||
"SET_ATTEND": "%s ha detto che Parteciperà all'evento: %s",
|
||||
"SET_ATTEND_OTHERS": "%s e altre %s persone hanno detto che Parteciperanno all'evento: %s",
|
||||
"DATEDAYONLY": "%s dalle %s alle %s",
|
||||
"DATE_2DAYS": "%s dalle %s fino a %s alle %s",
|
||||
"CLICCA_QUI": "CLICCA QUI"
|
||||
}
|
||||
@@ -141,7 +141,7 @@ AccountSchema.statics.calcTotCircolante = async function (idapp, circuitId) {
|
||||
{ $group: { _id: null, count: { $sum: '$saldo' } } }
|
||||
];
|
||||
|
||||
ris = await Account.aggregate(aggr1);
|
||||
const ris = await Account.aggregate(aggr1);
|
||||
|
||||
return ris ? ris[0].count : 0;
|
||||
|
||||
@@ -340,6 +340,7 @@ AccountSchema.statics.createAccount = async function (idapp, username, circuitNa
|
||||
};
|
||||
|
||||
AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
@@ -391,17 +392,25 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
},
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
const ris = await this.aggregate(aggr1);
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
// console.log('1 - INIZIA getUserAccounts ')
|
||||
// console.log(aggr1);
|
||||
|
||||
if (ris) {
|
||||
for (const account of ris) {
|
||||
try {
|
||||
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
//++OTTIMIZZARE QUESTA PARTE ! (CON UNA QUERY...)
|
||||
// console.log(' 1B - PENDIND... ')
|
||||
|
||||
let pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
|
||||
let saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
if (saldopending !== 0) {
|
||||
account.saldo -= saldopending;
|
||||
account.totTransato = account.totTransato || 0;
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error('getUserAccounts 1) ', e);
|
||||
}
|
||||
@@ -409,6 +418,7 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(' 2 - FINE getUserAccounts LEN=', ris.length)
|
||||
return ris;
|
||||
} catch (e) {
|
||||
console.error('getUserAccounts', e);
|
||||
@@ -470,17 +480,21 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
},
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
const ris = await this.aggregate(aggr1);
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
if (ris) {
|
||||
// tools.startTimeLog('Query Pending')
|
||||
for (const account of ris) {
|
||||
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, '', account.circuit.name, groupname);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.result.extrarec.qty, 0);
|
||||
if (saldopending) {
|
||||
account.saldo -= saldopending;
|
||||
}
|
||||
}
|
||||
// tools.endTimeLog('Query Pending')
|
||||
}
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
@@ -493,7 +507,7 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
AccountSchema.statics.SetMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||
const Account = this;
|
||||
|
||||
ris = await Account.updateMany({ idapp, groupname: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany({ idapp, groupname: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -508,7 +522,7 @@ AccountSchema.statics.SetMinMaxCollettivi = async function (idapp, valmin, valma
|
||||
AccountSchema.statics.SetMinMaxComunitari = async function (idapp, valmin, valmax) {
|
||||
const Account = this;
|
||||
|
||||
ris = await Account.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -524,7 +538,7 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax
|
||||
const Account = this;
|
||||
|
||||
if (circuitId) {
|
||||
ris = await Account.updateMany({ idapp, circuitId, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany({ idapp, circuitId, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -533,7 +547,7 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ris = await Account.updateMany({ idapp, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany({ idapp, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -556,12 +570,12 @@ AccountSchema.statics.updateFido = async function (idapp, username, circuitId, f
|
||||
};
|
||||
|
||||
AccountSchema.statics.canEditAccountAdmins = async function (username, id) {
|
||||
const account = await Account.findOne({_id: id}).lean();
|
||||
const account = await Account.findOne({ _id: id }).lean();
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
if (account) {
|
||||
const circuit = await Circuit.findOne({_id: account.circuitId}).lean();
|
||||
const circuit = await Circuit.findOne({ _id: account.circuitId }).lean();
|
||||
if (circuit) {
|
||||
return circuit.admins.findIndex((admin) => admin.username === username) >= 0;
|
||||
}
|
||||
|
||||
@@ -642,7 +642,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: extrarec.dest }, update);
|
||||
const ris = await User.updateOne({ idapp, username: extrarec.dest }, update);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,7 +865,7 @@ CircuitSchema.statics.setstrProvByIdCityCircuits = async function (idapp) {
|
||||
|
||||
CircuitSchema.statics.AbilitaTuttiCircuiti = async function (idapp) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -878,7 +878,7 @@ CircuitSchema.statics.AbilitaTuttiCircuiti = async function (idapp) {
|
||||
|
||||
CircuitSchema.statics.AzzeraRegolamentiTuttiCircuiti = async function (idapp) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -893,7 +893,7 @@ CircuitSchema.statics.AzzeraRegolamentiTuttiCircuiti = async function (idapp) {
|
||||
CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, valmax, circuitId) {
|
||||
|
||||
if (circuitId) {
|
||||
ris = await Circuit.updateOne({ _id: circuitId },
|
||||
const ris = await Circuit.updateOne({ _id: circuitId },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -903,7 +903,7 @@ CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, val
|
||||
});
|
||||
} else {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -1065,7 +1065,7 @@ CircuitSchema.statics.getListCircuitsByUsername = async function (idapp, usernam
|
||||
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax, circuitId) {
|
||||
|
||||
if (circuitId) {
|
||||
ris = await Circuit.updateOne({ _id: circuitId },
|
||||
const ris = await Circuit.updateOne({ _id: circuitId },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -1074,7 +1074,7 @@ CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, va
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
|
||||
@@ -208,6 +208,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
|
||||
@@ -9,6 +9,8 @@ const tools = require('../tools/general');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const tableModel = shared_consts.TABLES_MYBACHECAS;
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
@@ -17,6 +19,7 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const MyBachecaSchema = new Schema({
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
default: function () {
|
||||
@@ -114,6 +117,8 @@ const MyBachecaSchema = new Schema({
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MyBachecaSchema.pre('save', async function (next) {
|
||||
|
||||
@@ -6,6 +6,8 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
@@ -16,6 +18,7 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const MyGoodSchema = new Schema({
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
},
|
||||
@@ -86,6 +89,8 @@ const MyGoodSchema = new Schema({
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MyGoodSchema.pre('save', async function (next) {
|
||||
@@ -309,7 +314,7 @@ MyGoodSchema.statics.getMyRecById = function (idapp, idGood) {
|
||||
$project: this.getProject(objadd.proj),
|
||||
};
|
||||
|
||||
query = [...query, {...toadd}];
|
||||
query = [...query, { ...toadd }];
|
||||
|
||||
return MyGood.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
|
||||
@@ -6,6 +6,8 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
@@ -15,6 +17,7 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const MyHospSchema = new Schema({
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
},
|
||||
@@ -90,6 +93,8 @@ const MyHospSchema = new Schema({
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MyHospSchema.pre('save', async function (next) {
|
||||
@@ -306,7 +311,7 @@ MyHospSchema.statics.getMyRecById = function (idapp, id) {
|
||||
$project: this.getProject(objadd.proj),
|
||||
};
|
||||
|
||||
query = [...query, {...toadd}];
|
||||
query = [...query, { ...toadd }];
|
||||
|
||||
return MyHosp.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
|
||||
@@ -6,16 +6,20 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const MySkillSchema = new Schema({
|
||||
const MySkillSchema = new Schema(
|
||||
{
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
default: function () {
|
||||
@@ -26,7 +30,7 @@ const MySkillSchema = new Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -92,12 +96,14 @@ const MySkillSchema = new Schema({
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
});
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MySkillSchema.index({ 'idapp': 1 });
|
||||
|
||||
|
||||
MySkillSchema.pre('save', async function(next) {
|
||||
MySkillSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
@@ -106,12 +112,12 @@ MySkillSchema.pre('save', async function(next) {
|
||||
next();
|
||||
});
|
||||
|
||||
MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
MySkillSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MySkill = this;
|
||||
|
||||
const query = [
|
||||
{$match: {idapp}},
|
||||
{$sort: {descr: 1}},
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
|
||||
return await MySkill.aggregate(query).then((arrrec) => {
|
||||
@@ -120,20 +126,20 @@ MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getFieldsForSearch = function() {
|
||||
MySkillSchema.statics.getFieldsForSearch = function () {
|
||||
return [];
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getFieldsLastForSearch = function() {
|
||||
MySkillSchema.statics.getFieldsLastForSearch = function () {
|
||||
return [
|
||||
{field: 'note', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{field: 'recSkill.descr', type: tools.FieldType.string},
|
||||
{field: 'myskill.descr', type: tools.FieldType.string},
|
||||
{ field: 'note', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string },
|
||||
{ field: 'recSkill.descr', type: tools.FieldType.string },
|
||||
{ field: 'myskill.descr', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MySkillSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
|
||||
@@ -148,12 +154,12 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
},
|
||||
};
|
||||
|
||||
params = {...params, ...otherparams};
|
||||
params = { ...params, ...otherparams };
|
||||
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
MySkillSchema.statics.getMyRecById = function (idapp, idSkill) {
|
||||
const MySkill = this;
|
||||
|
||||
let query = [
|
||||
@@ -314,7 +320,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
$project: this.getProject(objadd.proj),
|
||||
};
|
||||
|
||||
query = [...query, {...toadd}];
|
||||
query = [...query, { ...toadd }];
|
||||
|
||||
return MySkill.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
@@ -339,7 +345,7 @@ MySkillSchema.statics.getProject = function (proj_add2) {
|
||||
|
||||
}
|
||||
|
||||
MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
MySkillSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MySkill = this;
|
||||
|
||||
return MySkill.getMyRecById(idapp, id);
|
||||
@@ -348,4 +354,4 @@ MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
|
||||
const MySkill = mongoose.model('MySkill', MySkillSchema);
|
||||
|
||||
module.exports = {MySkill};
|
||||
module.exports = { MySkill };
|
||||
|
||||
@@ -48,16 +48,99 @@ const reactionSchema = new Schema({
|
||||
},
|
||||
});
|
||||
|
||||
reactionSchema.statics.getFieldsForSearch = function() {
|
||||
return [
|
||||
{field: 'username', type: tools.FieldType.string}];
|
||||
reactionSchema.statics.getFieldsForReactions = function () {
|
||||
let reactionsField = {
|
||||
numseen: {
|
||||
type: Number,
|
||||
},
|
||||
numbook: {
|
||||
type: Number,
|
||||
},
|
||||
numfav: {
|
||||
type: Number,
|
||||
},
|
||||
numattend: {
|
||||
type: Number,
|
||||
},
|
||||
};
|
||||
|
||||
return reactionsField;
|
||||
};
|
||||
|
||||
reactionSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
reactionSchema.statics.getFieldsForSearch = function () {
|
||||
return [
|
||||
{ field: 'username', type: tools.FieldType.string }];
|
||||
};
|
||||
|
||||
reactionSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
reactionSchema.statics.calcReactions = async function (idapp, id, tab) {
|
||||
|
||||
try {
|
||||
let myquerycountreaction = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
idrec: id,
|
||||
tab,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
numseen: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$seen", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numfav: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$fav", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numbook: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$book", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numattend: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$attend", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return await Reaction.aggregate(myquerycountreaction)
|
||||
.then((ris) => {
|
||||
return ris ? ris[0] : null;
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Aggiungo il Favorite
|
||||
reactionSchema.statics.addFavorite = async function (req, idapp, username, id, tab) {
|
||||
@@ -94,11 +177,11 @@ reactionSchema.statics.addFavorite = async function (req, idapp, username, id, t
|
||||
|
||||
}
|
||||
|
||||
return {ris, ok};
|
||||
return { ris, ok };
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err addFavorite', e);
|
||||
return {ris: null, ok: 0};
|
||||
return { ris: null, ok: 0 };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -111,7 +194,7 @@ reactionSchema.statics.addSeen = async function (req, idapp, username, id, tab)
|
||||
return await myrec.save()
|
||||
.then((ris) => {
|
||||
// console.log('salvato proj!');
|
||||
return {ris, ok: ris ? 1 : 0};
|
||||
return { ris, ok: ris ? 1 : 0 };
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Error addSeen", err.message);
|
||||
@@ -133,7 +216,7 @@ reactionSchema.statics.addBookmark = async function (req, idapp, username, id, t
|
||||
const myrec = new Reaction({ idrec: id, idapp, userId: req.user.id, username, tab, book: true });
|
||||
return await myrec.save()
|
||||
.then((ris) => {
|
||||
return {ris, ok: ris ? 1 : 0};
|
||||
return { ris, ok: ris ? 1 : 0 };
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Error addBookmark", err.message);
|
||||
@@ -155,7 +238,7 @@ reactionSchema.statics.addAttend = async function (req, idapp, username, id, tab
|
||||
const myrec = new Reaction({ idrec: id, idapp, userId: req.user.id, username, tab, attend: true });
|
||||
return await myrec.save()
|
||||
.then((ris) => {
|
||||
return {ris, ok: ris ? 1 : 0};
|
||||
return { ris, ok: ris ? 1 : 0 };
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Error addAttend", err.message);
|
||||
@@ -175,7 +258,7 @@ reactionSchema.statics.removeFavorite = async function (
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (myrec) {
|
||||
return Reaction.updateOne({ _id: myrec._id}, {
|
||||
return Reaction.updateOne({ _id: myrec._id }, {
|
||||
$set: {
|
||||
fav: false,
|
||||
}
|
||||
@@ -193,7 +276,7 @@ reactionSchema.statics.removeBookmark = async function (
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (myrec) {
|
||||
return Reaction.updateOne({ _id: myrec._id}, {
|
||||
return Reaction.updateOne({ _id: myrec._id }, {
|
||||
$set: {
|
||||
book: false,
|
||||
}
|
||||
|
||||
@@ -99,6 +99,9 @@ const sendNotifSchema = new Schema({
|
||||
textaddTelegram: {
|
||||
type: String,
|
||||
},
|
||||
textcontent_Telegram: {
|
||||
type: String,
|
||||
},
|
||||
linkaddTelegram: {
|
||||
type: String,
|
||||
}
|
||||
@@ -145,7 +148,7 @@ sendNotifSchema.statics.getRecNotif = function (id) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp) {
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp, limitrecord) {
|
||||
const SendNotif = this;
|
||||
|
||||
if (!lastdataread)
|
||||
@@ -157,7 +160,7 @@ sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, l
|
||||
{ 'dest': username },
|
||||
{ 'datenotif': { $gt: new Date(lastdataread) } },
|
||||
],
|
||||
}).lean().sort({ datenotif: -1 }).then(async (arrnotif) => {
|
||||
}).lean().limit(limitrecord).sort({ datenotif: -1 }).then(async (arrnotif) => {
|
||||
// console.log('arrnotif', arrnotif.length);
|
||||
|
||||
return this.compileOtherFields(arrnotif);
|
||||
@@ -172,6 +175,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
|
||||
const numchars = 80;
|
||||
let newdescr = '';
|
||||
let newdescrtelegram = '';
|
||||
let mydescr = '';
|
||||
let myidrec = '';
|
||||
let sender = recnotif.sender ? recnotif.sender : '';
|
||||
@@ -205,7 +209,9 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec;
|
||||
tag = 'newevent';
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_NEW_REC) {
|
||||
newdescr = i18n.__('NEW_EVENT', userorig, mydescr);
|
||||
let eventobj = await tools.getEventForTelegram(recnotif.myrectableorig, mydescr, userorig);
|
||||
newdescr = eventobj.newdescr;
|
||||
newdescrtelegram = eventobj.newdescrtelegram;
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_SEND_MSG) {
|
||||
newdescr = i18n.__('EVENT_SEND_MSG', userorig, recnotif.title, recnotif.msg);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_ATTEND) {
|
||||
@@ -217,11 +223,12 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
else
|
||||
newdescr = i18n.__('SET_ATTEND', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.descr);
|
||||
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
|
||||
tag = 'attend';
|
||||
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
|
||||
recnotif.linkaddTelegram = 'Vedi post';
|
||||
}
|
||||
recnotif.textcontent_Telegram = newdescrtelegram;
|
||||
recnotif.linkaddTelegram = i18n.__('SHOW_POST');
|
||||
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
@@ -539,7 +546,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
tag = 'favorite';
|
||||
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
|
||||
recnotif.linkaddTelegram = 'Vedi post';
|
||||
recnotif.linkaddTelegram = i18n.__('SHOW_POST');
|
||||
}
|
||||
|
||||
recnotif.tag = recnotif.tag ? recnotif.tag : tag;
|
||||
@@ -898,9 +905,11 @@ sendNotifSchema.statics.createNewNotification = async function (req, res, params
|
||||
myrecnotif.idrec = rec._id;
|
||||
}
|
||||
|
||||
|
||||
myrecnotif.typedir = typedir;
|
||||
myrecnotif.typeid = typeid;
|
||||
|
||||
|
||||
await SendNotif.sendToTheDestinations(myrecnotif, req, res);
|
||||
|
||||
return true;
|
||||
@@ -972,7 +981,9 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
|
||||
const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
|
||||
if (myrecnotifpass.idrec && myrecnotifpass.idrec !== '0') {
|
||||
// const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
|
||||
const myrectableorig = await mytable.getCompleteRecord(myrecnotifpass.idapp, myrecnotifpass.idrec);
|
||||
if (myrectableorig) {
|
||||
for (const city of myrectableorig.idCity) {
|
||||
const prov = await City.getProvinceByIdCity(city);
|
||||
@@ -992,6 +1003,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
||||
myrecnotifpass.myrectableorig = myrectableorig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
myrecnotifpass = await this.getDescrAndLinkByRecNotif(myrecnotifpass, req.user.username);
|
||||
delete myrecnotifpass._doc['_id'];
|
||||
|
||||
@@ -2834,7 +2834,7 @@ 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);
|
||||
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
|
||||
|
||||
} else {
|
||||
outres.cansend = false;
|
||||
@@ -3105,27 +3105,34 @@ UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({
|
||||
idapp, 'profile.teleg_id': teleg_id,
|
||||
idapp,
|
||||
'profile.teleg_id': teleg_id,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).lean().then((rec) => {
|
||||
}).lean().then(async (rec) => {
|
||||
if (!rec) {
|
||||
// Cerca se esiste in quello salvato in precedenza:
|
||||
const recold = await User.findOne({
|
||||
idapp,
|
||||
'profile.teleg_id_old': teleg_id
|
||||
}).lean();
|
||||
if (recold && recold.profile.teleg_id_old === teleg_id) {
|
||||
// Riaggiorna l'ID perché è ritornato sulla chat!
|
||||
await User.SetTelegramIdSuccess(idapp, recold._id, recold.profile.teleg_id_old);
|
||||
|
||||
rec = await User.findOne({
|
||||
idapp,
|
||||
'profile.teleg_id': teleg_id,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).lean();
|
||||
}
|
||||
|
||||
}
|
||||
return (!!rec) ? rec : null;
|
||||
}).catch((e) => {
|
||||
console.error('UserExistByIdTelegram', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.UsersByIdTelegram = async function (idapp, teleg_id) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({
|
||||
idapp, 'profile.teleg_id': teleg_id,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).lean().then((rec) => {
|
||||
return (!!rec) ? rec : null;
|
||||
}).catch((e) => {
|
||||
console.error('UserExistByIdTelegram', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.setPicProfile = async function (idapp, username, imgpic) {
|
||||
const User = this;
|
||||
@@ -3291,7 +3298,9 @@ UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) {
|
||||
'profile.teleg_id': 0,
|
||||
};
|
||||
|
||||
if (tools.sulServer()) {
|
||||
|
||||
// if (tools.sulServer()) {
|
||||
if (true) {
|
||||
|
||||
const ris = await User.findOneAndUpdate({
|
||||
idapp,
|
||||
@@ -4889,7 +4898,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}).lean();
|
||||
|
||||
recUser.profile.reaction = await Reaction.find({idapp, username: recUser.username}).lean();
|
||||
recUser.profile.reaction = await Reaction.find({ idapp, username: recUser.username }).lean();
|
||||
|
||||
recUser.profile.manage_mygroups = listManageGroups
|
||||
? listManageGroups
|
||||
@@ -5003,8 +5012,17 @@ UserSchema.statics.moverecordsFavorite = async function (tab) {
|
||||
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
console.log('fine moverecordsFavorite');
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.removerecordsFavorite = async function () {
|
||||
// Rimuovi i record del vecchio schema
|
||||
const attivacanc = false;
|
||||
const attivacanc = true;
|
||||
|
||||
if (attivacanc) {
|
||||
const queryfind = { idapp: '13' };
|
||||
@@ -5019,12 +5037,6 @@ UserSchema.statics.moverecordsFavorite = async function (tab) {
|
||||
});
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
console.log('fine moverecordsFavorite');
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.updateVersion = async function (userversion, recUser) {
|
||||
|
||||
@@ -5,6 +5,8 @@ const tools = require('../tools/general');
|
||||
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
@@ -82,7 +84,8 @@ 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);
|
||||
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
|
||||
/// E' QUIIII !!!!
|
||||
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);
|
||||
|
||||
await User.setLastCircuitOpened(idapp, req.user.username, path);
|
||||
|
||||
@@ -428,6 +428,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
|
||||
return await myPromise
|
||||
.then(async (doupdate) => {
|
||||
|
||||
if (doupdate)
|
||||
return mytable.updateOne({ _id: mytablerec._id }, mydata, { new: true })
|
||||
else
|
||||
|
||||
@@ -8,35 +8,39 @@ const tools = require('../tools/general');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
|
||||
var {authenticate, auth_default} = require('../middleware/authenticate');
|
||||
var { authenticate, authenticate_noerror, auth_default } = require('../middleware/authenticate');
|
||||
|
||||
var mongoose = require('mongoose').set('debug', false);
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
const _ = require('lodash');
|
||||
const {MyBacheca} = require('../models/mybacheca');
|
||||
var {User} = require('../models/user');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
var { User } = require('../models/user');
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
//GET orders
|
||||
router.post('/page', authenticate, function(req, res, next) {
|
||||
router.post('/page', authenticate_noerror, function (req, res, next) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
try {
|
||||
let table = req.body.table;
|
||||
let id = req.body.id;
|
||||
let idapp = req.body.idapp;
|
||||
|
||||
const username = req.user.username ? req.user.username : '';
|
||||
let username = ''
|
||||
if (req.user)
|
||||
username = req.user.username ? req.user.username : '';
|
||||
|
||||
if (username) {
|
||||
// Check if ìs a Notif to read
|
||||
const idnotif = req.body.idnotif ? req.body.idnotif : '';
|
||||
SendNotif.setNotifAsRead(idapp, username, idnotif);
|
||||
}
|
||||
|
||||
let mytable = null;
|
||||
if (shared_consts.TABLES_ENABLE_GETREC_BYID.includes(table)) {
|
||||
@@ -51,11 +55,12 @@ router.post('/page', authenticate, function(req, res, next) {
|
||||
|
||||
// Se è un record singolo di tipo Reaction,
|
||||
// allora gli devo passare anche le liste degli utenti :
|
||||
/*if (globalTables.isTableReaction(table)) {
|
||||
if (globalTables.isTableReaction(table)) {
|
||||
// ...
|
||||
const myreaction = await Reaction.find({idapp, idrec: id}).lean();
|
||||
ris.myreaction = myreaction;
|
||||
};*/
|
||||
// const myreaction = await Reaction.find({idapp, idrec: id}).lean();
|
||||
// ris.myreaction = myreaction;
|
||||
|
||||
};
|
||||
|
||||
if (ris) {
|
||||
res.send(ris);
|
||||
@@ -69,7 +74,7 @@ router.post('/page', authenticate, function(req, res, next) {
|
||||
})
|
||||
|
||||
}
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('/page', e);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,14 @@ const _ = require('lodash');
|
||||
|
||||
const reg = require('../reg/registration');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
const { authenticate, authenticate_noerror } = require('../middleware/authenticate');
|
||||
|
||||
const TypedError = require('../modules/ErrorHandler');
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
|
||||
router.post('/cmd', authenticate, async (req, res) => {
|
||||
router.post('/cmd', authenticate_noerror, async (req, res) => {
|
||||
|
||||
const mydata = req.body.mydata;
|
||||
const idapp = req.body.idapp;
|
||||
@@ -43,18 +44,30 @@ router.post('/cmd', authenticate, async (req, res) => {
|
||||
|
||||
|
||||
try {
|
||||
const username = req.user.username;
|
||||
const table = tools.getTableByNumTab(tab);
|
||||
const mytable = globalTables.getTableByTableName(table);
|
||||
let username = '';
|
||||
if (req.user) {
|
||||
username = req.user.username;
|
||||
} else {
|
||||
return res.send({ state: 0, record: null });
|
||||
}
|
||||
|
||||
let ris = null;
|
||||
let record = null;
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
let objtoupdate = {};
|
||||
|
||||
if (cmd === shared_consts.CMD_REACTION.SET_FAVORITE) {
|
||||
if (tab) {
|
||||
if (value)
|
||||
if (value) {
|
||||
ris = await Reaction.addFavorite(req, idapp, username, id, tab);
|
||||
else
|
||||
} else {
|
||||
ris = await Reaction.removeFavorite(idapp, username, id, tab);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CMD_REACTION.SET_BOOKMARK) {
|
||||
if (tab) {
|
||||
@@ -62,6 +75,7 @@ router.post('/cmd', authenticate, async (req, res) => {
|
||||
ris = await Reaction.addBookmark(req, idapp, username, id, tab);
|
||||
else
|
||||
ris = await Reaction.removeBookmark(idapp, username, id, tab);
|
||||
|
||||
}
|
||||
} else if (cmd === shared_consts.CMD_REACTION.SET_ATTEND) {
|
||||
if (tab) {
|
||||
@@ -69,6 +83,7 @@ router.post('/cmd', authenticate, async (req, res) => {
|
||||
ris = await Reaction.addAttend(req, idapp, username, id, tab, num);
|
||||
else
|
||||
ris = await Reaction.removeAttend(idapp, username, id, tab);
|
||||
|
||||
}
|
||||
} else if (cmd === shared_consts.CMD_REACTION.SET_SEEN) {
|
||||
if (tab) {
|
||||
@@ -83,8 +98,21 @@ router.post('/cmd', authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let state = (value && ris && ris.ok === 1) ? 1 : ((!value && ris && ris.ok === 1) ? -1 : 0);
|
||||
|
||||
const risreac = await Reaction.calcReactions(idapp, id, tab);
|
||||
if (risreac) {
|
||||
delete risreac._id;
|
||||
objtoupdate = risreac;
|
||||
}
|
||||
|
||||
if (mytable) {
|
||||
ris = await mytable.updateOne({ _id: id }, {
|
||||
$set: objtoupdate,
|
||||
})
|
||||
}
|
||||
|
||||
return res.send({ state, record });
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -144,7 +144,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).then(async (arrnotif) => {
|
||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER).then(async (arrnotif) => {
|
||||
// const wait = new Promise((resolve, reject) => {
|
||||
// setTimeout(() => {
|
||||
|
||||
|
||||
@@ -705,6 +705,26 @@ router.post('/circuits', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/updatesaldo', authenticate, async (req, res) => {
|
||||
const username = req.user.username;
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
|
||||
try {
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, username);
|
||||
let ris = {
|
||||
userprofile
|
||||
}
|
||||
|
||||
return res.send({ris});
|
||||
|
||||
} catch (e) {
|
||||
tools.mylog('ERRORE IN updatesaldo: ' + e);
|
||||
res.status(400).send();
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
router.post('/friends/cmd', authenticate, async (req, res) => {
|
||||
const usernameLogged = req.user.username;
|
||||
const idapp = req.body.idapp;
|
||||
@@ -1166,6 +1186,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
console.log('e', e);
|
||||
}
|
||||
|
||||
} else if (mydata.dbop === 'removeRecordsFav') {
|
||||
// Passa le tabelle da users sulle nuove tabelle:
|
||||
await User.removerecordsFavorite();
|
||||
|
||||
} else if (mydata.dbop === 'newRecordsFav') {
|
||||
// Passa le tabelle da users sulle nuove tabelle:
|
||||
await User.moverecordsFavorite(1);
|
||||
|
||||
@@ -3090,6 +3090,7 @@ class Telegram {
|
||||
const rec = this.getRecInMem(msg);
|
||||
let testo = msg.text.toLowerCase().trim();
|
||||
|
||||
|
||||
status = this.getstatus(rec);
|
||||
if (testo === Menu.EXIT_TELEGRAM) {
|
||||
await this.menuExitToTelegram(msg);
|
||||
@@ -3263,7 +3264,7 @@ class Telegram {
|
||||
const id = this.getchatid(msg);
|
||||
let rec = null;
|
||||
try {
|
||||
const user = await User.UserByIdTelegram(this.idapp, id);
|
||||
let user = await User.UserByIdTelegram(this.idapp, id);
|
||||
let rec = this.getRecInMem(msg);
|
||||
if (user && !rec) {
|
||||
rec = this.addUser(msg);
|
||||
@@ -3584,6 +3585,7 @@ class Telegram {
|
||||
// text = text.replace(/<\/div>/g, '');
|
||||
text = text.replace(/ /g, ' ');
|
||||
|
||||
|
||||
if (!form) {
|
||||
form = {
|
||||
'parse_mode': 'HTML',
|
||||
|
||||
@@ -1520,6 +1520,40 @@ module.exports = {
|
||||
return msg;
|
||||
},
|
||||
|
||||
htmlToTelegramText(html) {
|
||||
|
||||
try {
|
||||
const withMarkdown = html
|
||||
.replace(/<strong>(.*?)<\/strong>/g, '*$1*')
|
||||
.replace(/<b>(.*?)<\/b>/g, '*$1*')
|
||||
.replace(/<em>(.*?)<\/em>/g, '_$1_')
|
||||
.replace(/<u>(.*?)<\/u>/g, '__$1__');
|
||||
|
||||
// Remove other HTML tags
|
||||
const plainText = withMarkdown.replace(/<[^>]*>/g, '');
|
||||
|
||||
// Replace HTML entities with their equivalent Markdown or plain text representations
|
||||
const replacements = [
|
||||
{ pattern: /&/g, replacement: '&' },
|
||||
{ pattern: /</g, replacement: '<' },
|
||||
{ pattern: />/g, replacement: '>' },
|
||||
{ pattern: /"/g, replacement: '"' },
|
||||
{ pattern: /'/g, replacement: "'" },
|
||||
];
|
||||
|
||||
let telegramText = plainText;
|
||||
replacements.forEach((replacement) => {
|
||||
telegramText = telegramText.replace(replacement.pattern, replacement.replacement);
|
||||
});
|
||||
|
||||
return telegramText;
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
convertTexttoHtml(myhtml) {
|
||||
// let msg = myhtml;
|
||||
// msg = msg.replace('\n', '<br>');
|
||||
@@ -2005,9 +2039,10 @@ module.exports = {
|
||||
|
||||
addNumFavoriteAndBookmarkToQuery(idapp, numtab) {
|
||||
|
||||
let query = {};
|
||||
let query = [];
|
||||
|
||||
try {
|
||||
/*
|
||||
query =
|
||||
[
|
||||
{
|
||||
@@ -2067,109 +2102,19 @@ module.exports = {
|
||||
},
|
||||
|
||||
{
|
||||
$unwind: '$myreact',
|
||||
},
|
||||
|
||||
/*{
|
||||
$lookup: {
|
||||
from: "reactions",
|
||||
let: {
|
||||
tab: 2,
|
||||
id: '$_id',
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$idrec', '$$id'] },
|
||||
{ $eq: ['$tab', 2] },
|
||||
{ $eq: ['$idapp', '13'] },
|
||||
],
|
||||
$unwind: {
|
||||
path: "$myreact",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
myid: '$_id',
|
||||
_id: 0,
|
||||
idapp: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
fav: 1,
|
||||
seen: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'items',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$items"
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
let: {
|
||||
itemId: { $toObjectId: "$items.userId" },
|
||||
items: "$items"
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: [
|
||||
"$_id",
|
||||
"$$itemId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
'profile.img': 1,
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
"$$items",
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
as: "myreact"
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$_id",
|
||||
userId: {
|
||||
$first: "$userId"
|
||||
},
|
||||
descr: {
|
||||
$first: "$descr"
|
||||
},
|
||||
myreact: {
|
||||
$push: {
|
||||
$first: "$myreact"
|
||||
},
|
||||
|
||||
},
|
||||
firstDoc: {
|
||||
$first: "$$ROOT"
|
||||
},
|
||||
}
|
||||
} */
|
||||
|
||||
];
|
||||
|
||||
if (true) {
|
||||
// RIMUOVI
|
||||
// query = {};
|
||||
}
|
||||
|
||||
if (Object.keys(query).length > 0) {
|
||||
const numtabbacheca = this.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
|
||||
if (numtab === numtabbacheca) {
|
||||
@@ -2177,8 +2122,13 @@ module.exports = {
|
||||
query = [...query, ...queryadd];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
proj = {
|
||||
numseen: 1,
|
||||
numfav: 1,
|
||||
numbook: 1,
|
||||
numattend: 1,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -2900,9 +2850,9 @@ module.exports = {
|
||||
|
||||
if (params.options && this.isBitActive(params.options,
|
||||
shared_consts.OPTIONS_ADD_COUNT_FAVORITE)) {
|
||||
objadd = this.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
if (Object.keys(objadd.query).length > 0)
|
||||
query = [...query, ...objadd.query];
|
||||
// objadd = this.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
// if (Object.keys(objadd.query).length > 0)
|
||||
// query = [...query, ...objadd.query];
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -2939,7 +2889,7 @@ module.exports = {
|
||||
);
|
||||
|
||||
if (this.testing()) {
|
||||
console.log('query', query);
|
||||
// console.log('query', query);
|
||||
}
|
||||
|
||||
return query;
|
||||
@@ -3300,6 +3250,19 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
getstrTime(mytimestamp) {
|
||||
// Create a Date object with your desired date
|
||||
const date = new Date(mytimestamp); // You can replace this with your specific date
|
||||
|
||||
// Get the hour and minute components from the date
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
// Format the hour and minute components as HH:MM
|
||||
const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
|
||||
return formattedTime
|
||||
},
|
||||
|
||||
getstrDateShort(mydate, lang) {
|
||||
if (mydate) {
|
||||
// console.log('getstrDate', mytimestamp)
|
||||
@@ -4206,4 +4169,86 @@ module.exports = {
|
||||
},
|
||||
|
||||
|
||||
firstchars(value, numchars) {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
try {
|
||||
let mycar = value.substring(0, numchars)
|
||||
if (value.length > numchars)
|
||||
mycar += '...'
|
||||
return mycar
|
||||
} catch (e) {
|
||||
return value
|
||||
}
|
||||
},
|
||||
|
||||
replaceStringAtEnd(inputString, searchString, replacement) {
|
||||
// Create a regular expression that matches the searchString at the end of the inputString
|
||||
const regex = new RegExp(searchString + '$');
|
||||
|
||||
// Use the replace method with the regular expression to replace the string
|
||||
const result = inputString.replace(regex, replacement);
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
getstrDateTimeEvent(myevent) {
|
||||
let mystr = '';
|
||||
|
||||
// is same day?
|
||||
if (this.getstrDateShort(myevent.dateTimeStart) === this.getstrDateShort(myevent.dateTimeEnd)) {
|
||||
mystr = i18n.__('DATEDAYONLY', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
|
||||
this.getstrTime(myevent.dateTimeEnd))
|
||||
} else {
|
||||
mystr = i18n.__('DATE_2DAYS', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
|
||||
this.getstrDateLong(myevent.dateTimeEnd), this.getstrTime(myevent.dateTimeEnd))
|
||||
}
|
||||
|
||||
return '🗓 ' + mystr;
|
||||
},
|
||||
|
||||
getDoveStrByEvent(myrec) {
|
||||
let dove = '🏠 ';
|
||||
if (myrec.mycities && myrec.mycities.length > 0) {
|
||||
dove += myrec.mycities[0].comune + ' (' + myrec.mycities[0].prov + ')'
|
||||
}
|
||||
return dove;
|
||||
},
|
||||
|
||||
async getDescrEstesaStrByEvent(myrec) {
|
||||
let mystr = '';
|
||||
|
||||
mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '</div>', ''), 400);
|
||||
if (mystr)
|
||||
mystr = 'ℹ️ ' + mystr
|
||||
return mystr;
|
||||
},
|
||||
|
||||
|
||||
async getEventForTelegram(myrec, mydescr, userorig) {
|
||||
try {
|
||||
let datastr = this.getstrDateTimeEvent(myrec);
|
||||
let dovestr = this.getDoveStrByEvent(myrec);
|
||||
let descrestesa = await this.getDescrEstesaStrByEvent(myrec);
|
||||
let organizedby = myrec.organisedBy;
|
||||
let contributo = myrec.contribstr;
|
||||
|
||||
let newdescr = i18n.__('NEW_EVENT', userorig, datastr, mydescr, dovestr);
|
||||
let newdescrtelegram = i18n.__('NEW_EVENT_TELEGRAM', datastr, mydescr, dovestr, descrestesa, userorig);
|
||||
if (organizedby) {
|
||||
newdescrtelegram += i18n.__('ORGANIZED_BY', organizedby);
|
||||
}
|
||||
if (contributo) {
|
||||
newdescrtelegram += i18n.__('CONTRIB', contributo);
|
||||
}
|
||||
newdescrtelegram += i18n.__('ADDED_FROM', userorig);
|
||||
|
||||
return { newdescr, newdescrtelegram }
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@@ -259,6 +259,7 @@ module.exports = {
|
||||
actions: recnotif.actions ? recnotif.actions : [],
|
||||
id: recnotif._id,
|
||||
textaddTelegram: recnotif.textaddTelegram ? recnotif.textaddTelegram : '',
|
||||
textcontent_Telegram: recnotif.textcontent_Telegram ? recnotif.textcontent_Telegram : '',
|
||||
linkaddTelegram: recnotif.linkaddTelegram ? recnotif.linkaddTelegram : '',
|
||||
};
|
||||
|
||||
@@ -386,7 +387,7 @@ module.exports = {
|
||||
for (const user of arrusers) {
|
||||
|
||||
const mytitle = await tools.convertSpecialTags(user, params.title);
|
||||
const mycontent = await tools.convertSpecialTags(user, params.content);
|
||||
const mycontent = await tools.convertSpecialTags(user, params.textcontent_Telegram ? params.textcontent_Telegram : params.content);
|
||||
|
||||
let usernotifprofile = null;
|
||||
if (user.profile.notifs)
|
||||
|
||||
@@ -3,6 +3,7 @@ module.exports = {
|
||||
CHECK_READ_GUIDELINES: 1,
|
||||
CHECK_SEE_VIDEO_PRINCIPI: 2,
|
||||
},
|
||||
LIMIT_NOTIF_FOR_USER: 200,
|
||||
|
||||
QUERYTYPE_MYGROUP: 1,
|
||||
QUERYTYPE_REFUSED_USER_GRP: 2,
|
||||
@@ -156,6 +157,14 @@ module.exports = {
|
||||
SET_ATTEND: 4,
|
||||
},
|
||||
|
||||
REACTIONS_FIELD:
|
||||
{
|
||||
numseen: 1,
|
||||
numbook: 1,
|
||||
numfav: 1,
|
||||
numattend: 1,
|
||||
},
|
||||
|
||||
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
|
||||
@@ -732,7 +741,9 @@ module.exports = {
|
||||
groupname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
myreact: 1,
|
||||
mycities: 1,
|
||||
lang: 1,
|
||||
'profile.img': 1,
|
||||
'profile.mygroups': 1,
|
||||
'profile.mycircuits': 1,
|
||||
@@ -753,6 +764,8 @@ module.exports = {
|
||||
if (proj_add)
|
||||
proj = Object.assign({}, proj, proj_add);
|
||||
|
||||
proj = {...proj, ...this.REACTIONS_FIELD};
|
||||
|
||||
if (table) {
|
||||
let proj_add3 = this.getProjectByTable(table);
|
||||
proj = Object.assign({}, proj, proj_add3);
|
||||
|
||||
Reference in New Issue
Block a user