Add Movement !
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
"formidable": "^1.2.2",
|
"formidable": "^1.2.2",
|
||||||
"i18n": "^0.13.3",
|
"i18n": "^0.13.3",
|
||||||
"image-downloader": "^4.1.0",
|
"image-downloader": "^4.1.0",
|
||||||
|
"internet-available": "^1.0.0",
|
||||||
"jade": "^1.11.0",
|
"jade": "^1.11.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|||||||
@@ -49,5 +49,6 @@
|
|||||||
"CIRCUIT_REMOVED": "❌ l'utente %s è stato rimosso del Circuito %s (da parte di %s)",
|
"CIRCUIT_REMOVED": "❌ l'utente %s è stato rimosso del Circuito %s (da parte di %s)",
|
||||||
"CIRCUIT_EXIT_USER": "❌ l'utente %s è uscito dal Circuito %s",
|
"CIRCUIT_EXIT_USER": "❌ l'utente %s è uscito dal Circuito %s",
|
||||||
"CIRCUIT_EXIT_USER_TO_ME": "❌ Sei uscito dal Circuito %s",
|
"CIRCUIT_EXIT_USER_TO_ME": "❌ Sei uscito dal Circuito %s",
|
||||||
"CIRCUIT_REMOVED_TO_ME": "❌ Sei stato rimosso dal Circuito %s (da parte di %s)"
|
"CIRCUIT_REMOVED_TO_ME": "❌ Sei stato rimosso dal Circuito %s (da parte di %s)",
|
||||||
|
"CIRCUIT_SENDCOINSREQ": "%s ti sta inviando %s %s."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,13 @@ const AccountSchema = new Schema({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
date_created: {
|
||||||
|
type: Date,
|
||||||
|
default: Date.now,
|
||||||
|
},
|
||||||
|
date_updated: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
AccountSchema.statics.findAllIdApp = async function(idapp) {
|
AccountSchema.statics.findAllIdApp = async function(idapp) {
|
||||||
@@ -86,6 +93,7 @@ AccountSchema.statics.executeQueryTable = function(idapp, params) {
|
|||||||
return tools.executeQueryTable(this, idapp, params);
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
AccountSchema.statics.getAccountsByUsername = async function(idapp, username) {
|
AccountSchema.statics.getAccountsByUsername = async function(idapp, username) {
|
||||||
const Account = this;
|
const Account = this;
|
||||||
|
|
||||||
@@ -100,6 +108,99 @@ AccountSchema.statics.getAccountsByUsername = async function(idapp, username) {
|
|||||||
return await Account.find(myquery).lean();
|
return await Account.find(myquery).lean();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
AccountSchema.statics.getUserAccounts = async function(idapp, username) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
let aggr1 = [
|
||||||
|
{
|
||||||
|
$match: {idapp, username},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'circuits',
|
||||||
|
localField: 'circuitId',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'circuit',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'$replaceRoot': {
|
||||||
|
'newRoot': {
|
||||||
|
'$mergeObjects': [
|
||||||
|
{
|
||||||
|
'$arrayElemAt': [
|
||||||
|
'$circuit',
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
'$$ROOT',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$project: {
|
||||||
|
"circuit.name": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
ris = await this.aggregate(aggr1);
|
||||||
|
|
||||||
|
return ris;
|
||||||
|
}catch (e) {
|
||||||
|
console.error('e', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
AccountSchema.statics.addtoSaldo = async function(id, amount) {
|
||||||
|
const Account = this;
|
||||||
|
|
||||||
|
if (!id)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const myaccount = await Account.findById(id);
|
||||||
|
if (myaccount) {
|
||||||
|
myaccount.saldo = myaccount.saldo + amount;
|
||||||
|
myaccount.date_updated = new Date();
|
||||||
|
return myaccount.save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, username, circuitId, createifnotexist) {
|
||||||
|
const Account = this;
|
||||||
|
|
||||||
|
if (username === undefined)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const myquery = {
|
||||||
|
'idapp': idapp,
|
||||||
|
'username': username,
|
||||||
|
circuitId,
|
||||||
|
};
|
||||||
|
|
||||||
|
let myaccount = await Account.findOne(myquery).lean();
|
||||||
|
|
||||||
|
if (!myaccount && createifnotexist) {
|
||||||
|
myaccount = new Account({
|
||||||
|
idapp,
|
||||||
|
username,
|
||||||
|
circuitId,
|
||||||
|
deperibile: false,
|
||||||
|
importo_iniziale: 0,
|
||||||
|
saldo: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
return myaccount.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return myaccount;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const Account = mongoose.model('Account', AccountSchema);
|
const Account = mongoose.model('Account', AccountSchema);
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ const BotSchema = new Schema({
|
|||||||
},
|
},
|
||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ mongoose.plugin(schema => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const CircuitSchema = new Schema({
|
const CircuitSchema = new Schema({
|
||||||
|
_id: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
Num: {
|
Num: {
|
||||||
type: Number,
|
type: Number,
|
||||||
unique: true,
|
unique: true,
|
||||||
@@ -60,11 +63,11 @@ const CircuitSchema = new Schema({
|
|||||||
},
|
},
|
||||||
symbol: {
|
symbol: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 3,
|
maxlength: 7,
|
||||||
},
|
},
|
||||||
abbrev: {
|
abbrev: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 3,
|
maxlength: 7,
|
||||||
},
|
},
|
||||||
compara_valuta: {
|
compara_valuta: {
|
||||||
type: Number,
|
type: Number,
|
||||||
@@ -142,11 +145,22 @@ const CircuitSchema = new Schema({
|
|||||||
}], // username
|
}], // username
|
||||||
deleted: {
|
deleted: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
},
|
},
|
||||||
});
|
}, );
|
||||||
|
|
||||||
CircuitSchema.pre('save', async function(next) {
|
CircuitSchema.pre('save', async function(next) {
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
|
const myrec = await Circuit.findOne().limit(1).sort({_id: -1});
|
||||||
|
if (!!myrec) {
|
||||||
|
if (myrec._doc.Num === 0)
|
||||||
|
this.Num = 1;
|
||||||
|
else
|
||||||
|
this.Num = myrec._doc.Num + 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.Num = 1;
|
||||||
|
}
|
||||||
|
|
||||||
this.date_created = new Date();
|
this.date_created = new Date();
|
||||||
}
|
}
|
||||||
@@ -158,9 +172,11 @@ CircuitSchema.pre('save', async function(next) {
|
|||||||
CircuitSchema.statics.findAllIdApp = async function(idapp) {
|
CircuitSchema.statics.findAllIdApp = async function(idapp) {
|
||||||
const Circuit = this;
|
const Circuit = this;
|
||||||
|
|
||||||
const myfind = {idapp};
|
const myfind = {idapp, deleted: false};
|
||||||
|
|
||||||
return await Circuit.find(myfind, (err, arrrec) => {
|
const whatToShow = this.getWhatToShow(idapp, '');
|
||||||
|
|
||||||
|
return await Circuit.find(myfind, whatToShow, (err, arrrec) => {
|
||||||
return arrrec;
|
return arrrec;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -347,11 +363,50 @@ CircuitSchema.statics.getInfoCircuitByName = async function(idapp, name) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CircuitSchema.statics.getCircuitByName = async function(idapp, name) {
|
||||||
|
|
||||||
|
const myfind = {
|
||||||
|
idapp,
|
||||||
|
name,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await Circuit.findOne(myfind).lean();
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
CircuitSchema.statics.deleteCircuit = async function(idapp, usernameOrig, name) {
|
CircuitSchema.statics.deleteCircuit = async function(idapp, usernameOrig, name) {
|
||||||
console.log('Circuito ' + name + ' rimosso da ' + usernameOrig);
|
console.log('Circuito ' + name + ' rimosso da ' + usernameOrig);
|
||||||
return Circuit.findOneAndRemove({idapp, name});
|
return Circuit.findOneAndRemove({idapp, name});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CircuitSchema.statics.sendCoins = async function(idapp, usernameOrig, extrarec) {
|
||||||
|
console.log('Aggiungi Monete');
|
||||||
|
|
||||||
|
const {Movement} = require('../models/movement');
|
||||||
|
const {Account} = require('../models/account');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const reccircuit = Circuit.getCircuitByName(extrarec.circuitname);
|
||||||
|
|
||||||
|
const myqty = extrarec.qty;
|
||||||
|
|
||||||
|
const accountdest = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, reccircuit._id, true);
|
||||||
|
const accountorig = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, reccircuit._id, true);
|
||||||
|
|
||||||
|
// Add a Transaction !
|
||||||
|
Movement.addMov(accountorig, accountdest, myqty, extrarec.causal);
|
||||||
|
|
||||||
|
}catch (e) {
|
||||||
|
console.error('Err sendCoins', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// Rimuovo la Richiesta del Circuito
|
// Rimuovo la Richiesta del Circuito
|
||||||
CircuitSchema.statics.removeReqCircuit = async function(idapp, username, name) {
|
CircuitSchema.statics.removeReqCircuit = async function(idapp, username, name) {
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,30 @@ MovementSchema.statics.executeQueryTable = function(idapp, params) {
|
|||||||
return tools.executeQueryTable(this, 0, params);
|
return tools.executeQueryTable(this, 0, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MovementSchema.statics.addMov = async function(accountFromId, accountToId, amount, causal) {
|
||||||
|
|
||||||
|
const {Account} = require('../models/account');
|
||||||
|
|
||||||
|
let mymov = Movement(
|
||||||
|
{
|
||||||
|
transactionDate: new Date(),
|
||||||
|
accountFromId,
|
||||||
|
accountToId,
|
||||||
|
amount,
|
||||||
|
causal,
|
||||||
|
residual: 0,
|
||||||
|
// expiringDate:
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update saldo dell'Account
|
||||||
|
Account.addtoSaldo(accountToId, amount);
|
||||||
|
|
||||||
|
Account.addtoSaldo(accountFromId, -amount);
|
||||||
|
|
||||||
|
return mymov.save();
|
||||||
|
};
|
||||||
|
|
||||||
const Movement = mongoose.model('Movement', MovementSchema);
|
const Movement = mongoose.model('Movement', MovementSchema);
|
||||||
|
|
||||||
module.exports = {Movement};
|
module.exports = {Movement};
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ const MyBachecaSchema = new Schema({
|
|||||||
},
|
},
|
||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ const MyGoodSchema = new Schema({
|
|||||||
},
|
},
|
||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ const MyHospSchema = new Schema({
|
|||||||
},
|
},
|
||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ const MySkillSchema = new Schema({
|
|||||||
},
|
},
|
||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ const sendNotifSchema = new Schema({
|
|||||||
extrafield: {
|
extrafield: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
extrarec: {
|
||||||
|
type: Object,
|
||||||
|
},
|
||||||
tag: {
|
tag: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -295,12 +298,16 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
|||||||
tag = 'addadmingrp';
|
tag = 'addadmingrp';
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN) {
|
||||||
if (userorig === recnotif.paramsObj.usernameDest) {
|
if (userorig === recnotif.paramsObj.usernameDest) {
|
||||||
newdescr = i18n.__('CIRCUITS_REMOVED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||||
} else {
|
} else {
|
||||||
newdescr = i18n.__('CIRCUITS_REMOVED_ADMIN', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||||
recnotif.openUrl = '/my/' + userorig;
|
recnotif.openUrl = '/my/' + userorig;
|
||||||
}
|
}
|
||||||
tag = 'removeadmincircuit';
|
tag = 'removeadmincircuit';
|
||||||
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ) {
|
||||||
|
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', recnotif.paramsObj.username_action, recnotif.paramsObj.extrarec.qty, recnotif.paramsObj.extrarec.symbol);
|
||||||
|
tag = 'sendcoin';
|
||||||
|
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,6 +550,7 @@ sendNotifSchema.statics.getExtraParam = function(myrecnotif, paramsObj) {
|
|||||||
out.paramsObj = paramsObj;
|
out.paramsObj = paramsObj;
|
||||||
out.options = paramsObj.options ? paramsObj.options : [];
|
out.options = paramsObj.options ? paramsObj.options : [];
|
||||||
out.typesend = paramsObj.typesend ? paramsObj.typesend : 0;
|
out.typesend = paramsObj.typesend ? paramsObj.typesend : 0;
|
||||||
|
out.extrarec = paramsObj.extrarec ? paramsObj.extrarec : {};
|
||||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||||
out.extrafield = paramsObj.circuitnameDest ? paramsObj.circuitnameDest : '';
|
out.extrafield = paramsObj.circuitnameDest ? paramsObj.circuitnameDest : '';
|
||||||
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||||
|
|||||||
@@ -1407,6 +1407,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
|||||||
verified_by_aportador: 1,
|
verified_by_aportador: 1,
|
||||||
'profile.nationality': 1,
|
'profile.nationality': 1,
|
||||||
'profile.mygroups': 1,
|
'profile.mygroups': 1,
|
||||||
|
'profile.mycircuits': 1,
|
||||||
'profile.qualifica': 1,
|
'profile.qualifica': 1,
|
||||||
'profile.biografia': 1,
|
'profile.biografia': 1,
|
||||||
'profile.teleg_id': 1,
|
'profile.teleg_id': 1,
|
||||||
@@ -1446,6 +1447,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
|||||||
notask_verif: 1,
|
notask_verif: 1,
|
||||||
'profile.nationality': 1,
|
'profile.nationality': 1,
|
||||||
'profile.mygroups': 1,
|
'profile.mygroups': 1,
|
||||||
|
'profile.mycircuits': 1,
|
||||||
'profile.qualifica': 1,
|
'profile.qualifica': 1,
|
||||||
'profile.biografia': 1,
|
'profile.biografia': 1,
|
||||||
'profile.teleg_id': 1,
|
'profile.teleg_id': 1,
|
||||||
@@ -1928,7 +1930,7 @@ UserSchema.statics.countUsersInCircuit = async function(idapp, circuitname) {
|
|||||||
return User.countDocuments({
|
return User.countDocuments({
|
||||||
idapp,
|
idapp,
|
||||||
'profile.mycircuits': {
|
'profile.mycircuits': {
|
||||||
$elemMatch: {circuitname: {$eq: name}},
|
$elemMatch: {circuitname: {$eq: circuitname}},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2077,7 +2079,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
|||||||
return ris;
|
return ris;
|
||||||
};
|
};
|
||||||
|
|
||||||
UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitname, cmd, value, username_action) {
|
UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitname, cmd, value, username_action, extrarec) {
|
||||||
|
|
||||||
let ris = null;
|
let ris = null;
|
||||||
let update = {};
|
let update = {};
|
||||||
@@ -2108,7 +2110,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
}
|
}
|
||||||
if (ris) {
|
if (ris) {
|
||||||
// Invia una notifica alla persona e agli Admin
|
// Invia una notifica alla persona e agli Admin
|
||||||
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action);
|
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
||||||
ris = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
ris = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||||
}
|
}
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||||
@@ -2135,14 +2137,14 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
}
|
}
|
||||||
if (ris) {
|
if (ris) {
|
||||||
// Invia una notifica alla persona
|
// Invia una notifica alla persona
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, true, true, username_action);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, true, true, username_action, extrarec);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (foundIfAlreadyAskCircuit) {
|
if (foundIfAlreadyAskCircuit) {
|
||||||
ris = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo il Gruppo da me
|
ris = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo il Gruppo da me
|
||||||
|
|
||||||
// Invia una notifica alla persona
|
// Invia una notifica alla persona
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2157,7 +2159,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
console.log('ris', ris);
|
console.log('ris', ris);
|
||||||
|
|
||||||
// Invia una notifica alla persona
|
// Invia una notifica alla persona
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.DELETE) {
|
} else if (cmd === shared_consts.CIRCUITCMD.DELETE) {
|
||||||
|
|
||||||
@@ -2165,7 +2167,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
|
|
||||||
if (ris) {
|
if (ris) {
|
||||||
// Invia una notifica alla persona e agli Admin
|
// Invia una notifica alla persona e agli Admin
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
}
|
}
|
||||||
ris = await Circuit.deleteCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
ris = await Circuit.deleteCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
@@ -2184,13 +2186,23 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
ris = await Circuit.addToAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
|
ris = await Circuit.addToAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
|
||||||
|
|
||||||
// Invia una notifica alla persona
|
// Invia una notifica alla persona
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||||
ris = await Circuit.removeAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
|
ris = await Circuit.removeAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
|
||||||
|
|
||||||
// Invia una notifica alla persona
|
// Invia una notifica alla persona
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||||
|
// Invia una notifica di moneta alla persona
|
||||||
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
||||||
|
ris = await Circuit.sendCoins(idapp, usernameOrig, extrarec);
|
||||||
|
|
||||||
|
// Invia una notifica di moneta alla persona
|
||||||
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -2216,6 +2228,7 @@ function getWhatToShow(idapp, username) {
|
|||||||
notask_verif: 1,
|
notask_verif: 1,
|
||||||
'profile.nationality': 1,
|
'profile.nationality': 1,
|
||||||
'profile.mygroups': 1,
|
'profile.mygroups': 1,
|
||||||
|
'profile.mycircuits': 1,
|
||||||
'profile.qualifica': 1,
|
'profile.qualifica': 1,
|
||||||
'profile.biografia': 1,
|
'profile.biografia': 1,
|
||||||
'profile.username_telegram': 1,
|
'profile.username_telegram': 1,
|
||||||
@@ -3739,11 +3752,13 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser, req) {
|
|||||||
? listManageGroups
|
? listManageGroups
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
// Circuit
|
// Circuit>
|
||||||
|
|
||||||
const circuitobj = await Circuit.getCircuitsByUsername(idapp, recUser.username, req);
|
const circuitobj = await Circuit.getCircuitsByUsername(idapp, recUser.username, req);
|
||||||
|
|
||||||
recUser._doc.profile = {...recUser._doc.profile, ...circuitobj};
|
const useraccounts = await Account.getUserAccounts(idapp, recUser.username);
|
||||||
|
|
||||||
|
recUser._doc.profile = {...recUser._doc.profile, ...circuitobj, useraccounts};
|
||||||
|
|
||||||
return recUser._doc;
|
return recUser._doc;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const {User} = require('../models/user');
|
const {User} = require('../models/user');
|
||||||
const {MyGroup} = require('../models/mygroup');
|
const {MyGroup} = require('../models/mygroup');
|
||||||
|
const {Circuit} = require('../models/circuit');
|
||||||
const {Booking} = require('../models/booking');
|
const {Booking} = require('../models/booking');
|
||||||
const {Operator} = require('../models/operator');
|
const {Operator} = require('../models/operator');
|
||||||
const {Where} = require('../models/where');
|
const {Where} = require('../models/where');
|
||||||
@@ -220,7 +221,12 @@ router.post('/testServer', authenticate_noerror, (req, res) => {
|
|||||||
router.post('/settable', authenticate, async (req, res) => {
|
router.post('/settable', authenticate, async (req, res) => {
|
||||||
const params = req.body;
|
const params = req.body;
|
||||||
const mytable = globalTables.getTableByTableName(params.table);
|
const mytable = globalTables.getTableByTableName(params.table);
|
||||||
const mydata = req.body.data;
|
let mydata = req.body.data;
|
||||||
|
let extrarec = {};
|
||||||
|
if (myapp.hasOwnProperty('extrarec')) {
|
||||||
|
extrarec = mydata['extrarec'];
|
||||||
|
delete mydata['extrarec'];
|
||||||
|
}
|
||||||
|
|
||||||
const fieldsvalue = {'ALL': 1};
|
const fieldsvalue = {'ALL': 1};
|
||||||
|
|
||||||
@@ -263,7 +269,6 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (params.table === shared_consts.TAB_MYGROUPS) {
|
if (params.table === shared_consts.TAB_MYGROUPS) {
|
||||||
if (shared_consts.MYGROUPS_KEY_TO_CRYPTED in mydata) {
|
if (shared_consts.MYGROUPS_KEY_TO_CRYPTED in mydata) {
|
||||||
if (mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]) {
|
if (mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]) {
|
||||||
@@ -301,10 +306,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shared_consts.TABLES_ID_NUMBER.includes(params.table)) {
|
if (shared_consts.TABLES_ID_NUMBER.includes(params.table)) {
|
||||||
|
|
||||||
} else if (params.table === 'hours') {
|
} else if (params.table === 'hours') {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (mydata['_id'] === undefined) {
|
if (mydata['_id'] === undefined || (mytablerec.isNew && mydata['_id'] === 0)) {
|
||||||
mydata._id = new ObjectID();
|
mydata._id = new ObjectID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,7 +368,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
||||||
typeid = (params.table === shared_consts.TABLES_MYGOODS)
|
typeid = (params.table === shared_consts.TABLES_MYGOODS)
|
||||||
? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
||||||
: shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE
|
: shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE;
|
||||||
setnotif = true;
|
setnotif = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,12 +408,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
// nuovo Record:
|
// nuovo Record:
|
||||||
// aggiungi il creatore al Circuito stesso
|
// aggiungi il creatore al Circuito stesso
|
||||||
return User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
|
return User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
|
||||||
shared_consts.CIRCUITCMD.SET, true, req.user.username).then((ris) => {
|
shared_consts.CIRCUITCMD.SET, true, req.user.username, extrarec).then((ris) => {
|
||||||
return res.send(myrec);
|
return res.send(myrec);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return res.send(myrec);
|
return res.send(myrec);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error('settable', e.message);
|
console.error('settable', e.message);
|
||||||
@@ -1202,6 +1207,7 @@ function load(req, res, version) {
|
|||||||
let catgrps = CatGrp.findAllIdApp(idapp);
|
let catgrps = CatGrp.findAllIdApp(idapp);
|
||||||
let site = Site.findAllIdApp(idapp);
|
let site = Site.findAllIdApp(idapp);
|
||||||
let mygroups = MyGroup.findAllGroups(idapp);
|
let mygroups = MyGroup.findAllGroups(idapp);
|
||||||
|
let listcircuits = Circuit.findAllIdApp(idapp);
|
||||||
// let cities = City.findAllIdApp(idapp);
|
// let cities = City.findAllIdApp(idapp);
|
||||||
let provinces = Province.findAllIdApp(idapp);
|
let provinces = Province.findAllIdApp(idapp);
|
||||||
let cart = null;
|
let cart = null;
|
||||||
@@ -1268,6 +1274,7 @@ function load(req, res, version) {
|
|||||||
goods,
|
goods,
|
||||||
site,
|
site,
|
||||||
mygroups,
|
mygroups,
|
||||||
|
listcircuits, // 37
|
||||||
]).then((arrdata) => {
|
]).then((arrdata) => {
|
||||||
// console.table(arrdata);
|
// console.table(arrdata);
|
||||||
let myuser = req.user;
|
let myuser = req.user;
|
||||||
@@ -1347,6 +1354,7 @@ function load(req, res, version) {
|
|||||||
goods: arrdata[34],
|
goods: arrdata[34],
|
||||||
site: arrdata[35],
|
site: arrdata[35],
|
||||||
mygroups: arrdata[36],
|
mygroups: arrdata[36],
|
||||||
|
listcircuits: arrdata[37],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -719,6 +719,7 @@ router.post('/circuits/cmd', authenticate, (req, res) => {
|
|||||||
const circuitname = req.body.circuitname;
|
const circuitname = req.body.circuitname;
|
||||||
const cmd = req.body.cmd;
|
const cmd = req.body.cmd;
|
||||||
const value = req.body.value;
|
const value = req.body.value;
|
||||||
|
const extrarec = req.body.extrarec;
|
||||||
|
|
||||||
/*if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
|
/*if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
|
||||||
// If without permissions, exit
|
// If without permissions, exit
|
||||||
@@ -728,7 +729,7 @@ router.post('/circuits/cmd', authenticate, (req, res) => {
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return User.setCircuitCmd(idapp, usernameOrig, circuitname, cmd, value, usernameLogged).
|
return User.setCircuitCmd(idapp, usernameOrig, circuitname, cmd, value, usernameLogged, extrarec).
|
||||||
then((ris) => {
|
then((ris) => {
|
||||||
res.send(ris);
|
res.send(ris);
|
||||||
}).
|
}).
|
||||||
|
|||||||
@@ -878,7 +878,7 @@ const MyTelegramBot = {
|
|||||||
]);
|
]);
|
||||||
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
||||||
|
|
||||||
domanda = i18n.__({phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest} , groupname) + '<br>' + struserinfomsg;
|
domanda = i18n.__({phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest}, groupname) + '<br>' + struserinfomsg;
|
||||||
|
|
||||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||||
{
|
{
|
||||||
@@ -926,7 +926,7 @@ const MyTelegramBot = {
|
|||||||
sendnotif = true;
|
sendnotif = true;
|
||||||
typedir = shared_consts.TypeNotifs.TYPEDIR_FRIENDS;
|
typedir = shared_consts.TypeNotifs.TYPEDIR_FRIENDS;
|
||||||
typeid = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
|
typeid = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
|
||||||
paramsObj = {usernameDest: userDest}
|
paramsObj = {usernameDest: userDest};
|
||||||
|
|
||||||
domanda = printf(tools.gettranslate('RICHIESTA_AMICIZIA', langdest), myuser.username) + '<br>' + struserinfomsg;
|
domanda = printf(tools.gettranslate('RICHIESTA_AMICIZIA', langdest), myuser.username) + '<br>' + struserinfomsg;
|
||||||
|
|
||||||
@@ -948,7 +948,6 @@ const MyTelegramBot = {
|
|||||||
await this.local_sendMsgTelegramByIdTelegram(idapp, teleg_id, domanda, undefined, undefined, true, keyb);
|
await this.local_sendMsgTelegramByIdTelegram(idapp, teleg_id, domanda, undefined, undefined, true, keyb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (sendnotif) {
|
if (sendnotif) {
|
||||||
const req = this.getReqByPar(idapp, username);
|
const req = this.getReqByPar(idapp, username);
|
||||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||||
@@ -1675,9 +1674,10 @@ class Telegram {
|
|||||||
noanswer = true;
|
noanswer = true;
|
||||||
let myfaq = this.geturlfaq();
|
let myfaq = this.geturlfaq();
|
||||||
risp = 'Ciao {username}, Io mi chiamo BOT e sono il tuo assistente Virtuale ' + emo.ROBOT_FACE + emo.JOY2 + '\n' +
|
risp = 'Ciao {username}, Io mi chiamo BOT e sono il tuo assistente Virtuale ' + emo.ROBOT_FACE + emo.JOY2 + '\n' +
|
||||||
'Usa il menu qui sotto per interagire col BOT\n' +
|
'Usa il menu qui sotto per interagire col BOT\n' +
|
||||||
'\nPer <strong>AIUTO</strong>, clicca qui:\n👉🏻👉🏻<a href="' + myfaq +
|
'\nPer <strong>AIUTO</strong>, clicca qui:\n👉🏻👉🏻<a href="' + myfaq +
|
||||||
'">FAQ di AIUTO</a> (risposte alle domande più frequenti)\n\nSe non trovi risposta allora contatta la <a href="' + tools.getTelegramSupportChat(this.idapp) + '">Chat di HELP</a>.\nGrazie';
|
'">FAQ di AIUTO</a> (risposte alle domande più frequenti)\n\nSe non trovi risposta allora contatta la <a href="' +
|
||||||
|
tools.getTelegramSupportChat(this.idapp) + '">Chat di HELP</a>.\nGrazie';
|
||||||
// risp += '\nClicca qui per entrare nella Chat - HELP di Supporto\n' + 'https://t.me/joinchat/AL2qKE80rxDkgbeMGO-0bw' + '\n\nI miei colleghi umani ti aiuteranno a risolvere !';
|
// risp += '\nClicca qui per entrare nella Chat - HELP di Supporto\n' + 'https://t.me/joinchat/AL2qKE80rxDkgbeMGO-0bw' + '\n\nI miei colleghi umani ti aiuteranno a risolvere !';
|
||||||
await local_sendMsgTelegramToTheManagers(this.idapp, testo, msg,
|
await local_sendMsgTelegramToTheManagers(this.idapp, testo, msg,
|
||||||
rec.username_bo);
|
rec.username_bo);
|
||||||
@@ -3735,284 +3735,291 @@ if (true) {
|
|||||||
else if (process.env.NODE_ENV === 'test')
|
else if (process.env.NODE_ENV === 'test')
|
||||||
arrTeleg = appTelegram_TEST;
|
arrTeleg = appTelegram_TEST;
|
||||||
|
|
||||||
console.log('TELEGRAM STARTING.... NODE_ENV:' + process.env.NODE_ENV);
|
var internetAvailable = require('internet-available');
|
||||||
|
|
||||||
|
internetAvailable().then(() => {
|
||||||
|
// ..
|
||||||
|
console.log('TELEGRAM STARTING.... NODE_ENV:' + process.env.NODE_ENV);
|
||||||
|
|
||||||
for (const idapp of arrTeleg) {
|
for (const idapp of arrTeleg) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token = tools.getTelegramKeyByIdApp(idapp);
|
const token = tools.getTelegramKeyByIdApp(idapp);
|
||||||
const nomebot = tools.getTelegramBotNameByIdApp(idapp);
|
const nomebot = tools.getTelegramBotNameByIdApp(idapp);
|
||||||
|
|
||||||
// console.log('idapp', idapp, 'token', token);
|
// console.log('idapp', idapp, 'token', token);
|
||||||
|
|
||||||
if (!!token) {
|
if (!!token) {
|
||||||
console.log('*** START BOT ' + nomebot);
|
console.log('*** START BOT ' + nomebot);
|
||||||
const bot = new TelegramBot(token, {polling: true});
|
const bot = new TelegramBot(token, {polling: true});
|
||||||
|
|
||||||
if (url === '0') {
|
if (url === '0') {
|
||||||
const ngrok = require('ngrok');
|
const ngrok = require('ngrok');
|
||||||
ngrok.connect(port, function onConnect(error, u) {
|
ngrok.connect(port, function onConnect(error, u) {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
url = u;
|
url = u;
|
||||||
console.log(`Game tunneled at ${url}`);
|
console.log(`Game tunneled at ${url}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
arrTelegram.push({idapp, cl: new Telegram(idapp, bot)});
|
arrTelegram.push({idapp, cl: new Telegram(idapp, bot)});
|
||||||
|
|
||||||
bot.onText(/\/start/, (msg) => {
|
bot.onText(/\/start/, (msg) => {
|
||||||
const myclTelegram = getclTelegBytoken(bot.token);
|
|
||||||
|
|
||||||
myclTelegram.start(msg);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Matches "/echo [whatever]"
|
|
||||||
bot.onText(/\/echo (.+)/, (msg, match) => {
|
|
||||||
// 'msg' is the received Message from Telegram
|
|
||||||
// 'match' is the result of executing the regexp above on the text content
|
|
||||||
// of the message
|
|
||||||
|
|
||||||
const chatId = msg.chat.id;
|
|
||||||
const resp = match[1]; // the captured "whatever"
|
|
||||||
|
|
||||||
// send back the matched "whatever" to the chat
|
|
||||||
bot.sendMessage(chatId, resp);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Listen for any kind of message. There are different kinds of
|
|
||||||
// messages.
|
|
||||||
bot.on('message', (msg) => {
|
|
||||||
|
|
||||||
const myclTelegram = getclTelegBytoken(bot.token);
|
|
||||||
|
|
||||||
// const chatId = msg.chat.id;
|
|
||||||
|
|
||||||
myclTelegram.receiveMsg(msg);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle callback queries
|
|
||||||
bot.on('callback_query', async (callbackQuery) => {
|
|
||||||
// console.log('callback_query', callbackQuery);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const myclTelegram = getclTelegBytoken(bot.token);
|
const myclTelegram = getclTelegBytoken(bot.token);
|
||||||
|
|
||||||
let dataarr = [];
|
myclTelegram.start(msg);
|
||||||
let data = {
|
|
||||||
action: '',
|
|
||||||
username: '',
|
|
||||||
userDest: '',
|
|
||||||
groupId: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const datastr = callbackQuery.data;
|
});
|
||||||
if (!!datastr) {
|
|
||||||
dataarr = datastr.split(tools.SEP);
|
// Matches "/echo [whatever]"
|
||||||
if (!!dataarr) {
|
bot.onText(/\/echo (.+)/, (msg, match) => {
|
||||||
data = {
|
// 'msg' is the received Message from Telegram
|
||||||
action: dataarr[0],
|
// 'match' is the result of executing the regexp above on the text content
|
||||||
username: dataarr[1] ? dataarr[1] : '',
|
// of the message
|
||||||
userDest: dataarr[2] ? dataarr[2] : '',
|
|
||||||
groupId: dataarr[3] ? parseInt(dataarr[3]) : '',
|
const chatId = msg.chat.id;
|
||||||
};
|
const resp = match[1]; // the captured "whatever"
|
||||||
|
|
||||||
|
// send back the matched "whatever" to the chat
|
||||||
|
bot.sendMessage(chatId, resp);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Listen for any kind of message. There are different kinds of
|
||||||
|
// messages.
|
||||||
|
bot.on('message', (msg) => {
|
||||||
|
|
||||||
|
const myclTelegram = getclTelegBytoken(bot.token);
|
||||||
|
|
||||||
|
// const chatId = msg.chat.id;
|
||||||
|
|
||||||
|
myclTelegram.receiveMsg(msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle callback queries
|
||||||
|
bot.on('callback_query', async (callbackQuery) => {
|
||||||
|
// console.log('callback_query', callbackQuery);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const myclTelegram = getclTelegBytoken(bot.token);
|
||||||
|
|
||||||
|
let dataarr = [];
|
||||||
|
let data = {
|
||||||
|
action: '',
|
||||||
|
username: '',
|
||||||
|
userDest: '',
|
||||||
|
groupId: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const datastr = callbackQuery.data;
|
||||||
|
if (!!datastr) {
|
||||||
|
dataarr = datastr.split(tools.SEP);
|
||||||
|
if (!!dataarr) {
|
||||||
|
data = {
|
||||||
|
action: dataarr[0],
|
||||||
|
username: dataarr[1] ? dataarr[1] : '',
|
||||||
|
userDest: dataarr[2] ? dataarr[2] : '',
|
||||||
|
groupId: dataarr[3] ? parseInt(dataarr[3]) : '',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
const msg = callbackQuery.message;
|
||||||
const msg = callbackQuery.message;
|
const opts = {
|
||||||
const opts = {
|
chat_id: msg.chat.id,
|
||||||
chat_id: msg.chat.id,
|
message_id: msg.message_id,
|
||||||
message_id: msg.message_id,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const status = await myclTelegram.setInit(msg);
|
const status = await myclTelegram.setInit(msg);
|
||||||
|
|
||||||
const rec = myclTelegram.getRecInMem(msg);
|
const rec = myclTelegram.getRecInMem(msg);
|
||||||
|
|
||||||
const username_action = rec.user ? rec.user.username : '';
|
const username_action = rec.user ? rec.user.username : '';
|
||||||
|
|
||||||
data.username = await User.getRealUsernameByUsername(idapp, data.username);
|
data.username = await User.getRealUsernameByUsername(idapp, data.username);
|
||||||
data.userDest = await User.getRealUsernameByUsername(idapp, data.userDest);
|
data.userDest = await User.getRealUsernameByUsername(idapp, data.userDest);
|
||||||
|
|
||||||
const user = await User.getUserShortDataByUsername(idapp, data.username);
|
const user = await User.getUserShortDataByUsername(idapp, data.username);
|
||||||
const userDest = data.userDest ? await User.getUserShortDataByUsername(idapp, data.userDest) : null;
|
const userDest = data.userDest ? await User.getUserShortDataByUsername(idapp, data.userDest) : null;
|
||||||
|
|
||||||
let group = null;
|
let group = null;
|
||||||
let circuit = null;
|
let circuit = null;
|
||||||
if (data.groupId) {
|
if (data.groupId) {
|
||||||
group = await MyGroup.findOne({idapp, _id: data.groupId}).lean();
|
group = await MyGroup.findOne({idapp, _id: data.groupId}).lean();
|
||||||
}
|
}
|
||||||
if (data.circuitId) {
|
if (data.circuitId) {
|
||||||
circuit = await Circuit.findOne({idapp, _id: data.circuitId}).lean();
|
circuit = await Circuit.findOne({idapp, _id: data.circuitId}).lean();
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmd = 0;
|
let cmd = 0;
|
||||||
|
|
||||||
if (!!rec) {
|
if (!!rec) {
|
||||||
if (!!user) {
|
if (!!user) {
|
||||||
if (data.action === InlineCmd.VOGLIO_IMBARCARMI) {
|
if (data.action === InlineCmd.VOGLIO_IMBARCARMI) {
|
||||||
// Controlla se è qualificato!
|
// Controlla se è qualificato!
|
||||||
const mydata = tools.AddDate(user.date_reg, 7);
|
const mydata = tools.AddDate(user.date_reg, 7);
|
||||||
|
|
||||||
// bot.editMessageText(tools.gettranslate('ADDED_TOLISTAINGRESSO', user.lang), opts);
|
// bot.editMessageText(tools.gettranslate('ADDED_TOLISTAINGRESSO', user.lang), opts);
|
||||||
|
|
||||||
} else if (data.action === InlineCmd.NON_VOGLIO_IMBARCARMI) {
|
} else if (data.action === InlineCmd.NON_VOGLIO_IMBARCARMI) {
|
||||||
await User.NonVoglioImbarcarmi(user.idapp, user.username);
|
await User.NonVoglioImbarcarmi(user.idapp, user.username);
|
||||||
|
|
||||||
const msgadd = '[' + user.username + '] ' + user.name + ' ' +
|
const msgadd = '[' + user.username + '] ' + user.name + ' ' +
|
||||||
user.surname + ' ha risposto che NON VUOLE IMBARCARSI !';
|
user.surname + ' ha risposto che NON VUOLE IMBARCARSI !';
|
||||||
|
|
||||||
await local_sendMsgTelegramToTheManagers(user.idapp, msgadd,
|
await local_sendMsgTelegramToTheManagers(user.idapp, msgadd,
|
||||||
msg, false); // Anche a STAFF
|
msg, false); // Anche a STAFF
|
||||||
} else if (data.action ===
|
} else if (data.action ===
|
||||||
InlineZoomConferma.CONFERMA_ZOOM_PRESENZA) {
|
InlineZoomConferma.CONFERMA_ZOOM_PRESENZA) {
|
||||||
|
|
||||||
await User.setZoomPresenza(user.idapp, user._id, true);
|
await User.setZoomPresenza(user.idapp, user._id, true);
|
||||||
|
|
||||||
} else if (data.action ===
|
} else if (data.action ===
|
||||||
InlineZoomConferma.NON_CONFERMA_ZOOM_PRESENZA) {
|
InlineZoomConferma.NON_CONFERMA_ZOOM_PRESENZA) {
|
||||||
|
|
||||||
await User.setZoomPresenza(user.idapp, user._id, false);
|
await User.setZoomPresenza(user.idapp, user._id, false);
|
||||||
|
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.REGISTRATION) {
|
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.REGISTRATION) {
|
||||||
const changed = await myclTelegram.setCmdToUsername(rec,
|
const changed = await myclTelegram.setCmdToUsername(rec,
|
||||||
data.username,
|
data.username,
|
||||||
Cmd.VALIDATE_REGISTRATION, true);
|
Cmd.VALIDATE_REGISTRATION, true);
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
const req = tools.getReqByPar(user.idapp, username_action);
|
|
||||||
await User.setFriendsCmd(req, user.idapp, data.username, userDest.username, shared_consts.FRIENDSCMD.SETFRIEND);
|
|
||||||
|
|
||||||
await User.setaportador_solidario(user.idapp, data.username, userDest.username);
|
|
||||||
|
|
||||||
const msgOrig = printf(getstr(userDest.lang, 'MSG_APORTADOR_DEST_CONFIRMED'), `${userDest.username}`,
|
|
||||||
tools.getHostByIdApp(user.idapp));
|
|
||||||
const msgDest = printf(getstr(user.lang, 'MSG_APORTADOR_CONFIRMED'), `${user.username}`, `${userDest.username}`);
|
|
||||||
|
|
||||||
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
|
||||||
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.REGISTRATION) {
|
|
||||||
if (userDest.username === user.aportador_solidario) {
|
|
||||||
const changed = await myclTelegram.setCmdToUsername(rec, data.username,
|
|
||||||
Cmd.VALIDATE_REGISTRATION, false);
|
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
const nomeDest = tools.getNomeCognomeEUserNameByUser(userDest);
|
const req = tools.getReqByPar(user.idapp, username_action);
|
||||||
const nomestr = tools.getNomeCognomeEUserNameByUser(user);
|
await User.setFriendsCmd(req, user.idapp, data.username, userDest.username, shared_consts.FRIENDSCMD.SETFRIEND);
|
||||||
|
|
||||||
const msgOrig = printf(getstr(userDest.lang, 'MSG_APORTADOR_DEST_NOT_CONFIRMED', nomeDest));
|
await User.setaportador_solidario(user.idapp, data.username, userDest.username);
|
||||||
const msgDest = printf(getstr(user.lang, 'MSG_APORTADOR_NOT_CONFIRMED'), nomestr);
|
|
||||||
|
const msgOrig = printf(getstr(userDest.lang, 'MSG_APORTADOR_DEST_CONFIRMED'), `${userDest.username}`,
|
||||||
|
tools.getHostByIdApp(user.idapp));
|
||||||
|
const msgDest = printf(getstr(user.lang, 'MSG_APORTADOR_CONFIRMED'), `${user.username}`, `${userDest.username}`);
|
||||||
|
|
||||||
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
||||||
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
|
||||||
|
|
||||||
if (group) {
|
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.REGISTRATION) {
|
||||||
cmd = shared_consts.GROUPSCMD.SETGROUP;
|
if (userDest.username === user.aportador_solidario) {
|
||||||
const foundIfAlreadyGroup = await User.ifAlreadyInGroup(user.idapp, data.username, group.groupname);
|
const changed = await myclTelegram.setCmdToUsername(rec, data.username,
|
||||||
|
Cmd.VALIDATE_REGISTRATION, false);
|
||||||
|
|
||||||
if (!foundIfAlreadyGroup) {
|
if (changed) {
|
||||||
// Aggiungilo nel Gruppo
|
const nomeDest = tools.getNomeCognomeEUserNameByUser(userDest);
|
||||||
await User.setGroupsCmd(user.idapp, data.username, group.groupname, cmd, 0, username_action);
|
const nomestr = tools.getNomeCognomeEUserNameByUser(user);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
const msgOrig = printf(getstr(userDest.lang, 'MSG_APORTADOR_DEST_NOT_CONFIRMED', nomeDest));
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
const msgDest = printf(getstr(user.lang, 'MSG_APORTADOR_NOT_CONFIRMED'), nomestr);
|
||||||
|
|
||||||
if (group) {
|
|
||||||
cmd = shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUP;
|
|
||||||
const foundIfAlreadyGroup = await User.ifAlreadyInGroup(user.idapp, data.username, group.groupname);
|
|
||||||
|
|
||||||
if (foundIfAlreadyGroup) {
|
|
||||||
// Rimuovilo nel Gruppo
|
|
||||||
await User.setGroupsCmd(user.idapp, data.username, group.groupname, cmd, 0, username_action);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
|
||||||
|
|
||||||
if (circuit) {
|
|
||||||
cmd = shared_consts.CIRCUITCMD.SET;
|
|
||||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
|
||||||
|
|
||||||
if (!foundIfAlreadyCircuit) {
|
|
||||||
// Aggiungilo nel Gruppo
|
|
||||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
|
||||||
|
|
||||||
if (circuit) {
|
|
||||||
cmd = shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST;
|
|
||||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
|
||||||
|
|
||||||
if (foundIfAlreadyCircuit) {
|
|
||||||
// Rimuovilo nel Circuito
|
|
||||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_AMICIZIA) {
|
|
||||||
|
|
||||||
if (userDest) {
|
|
||||||
cmd = shared_consts.FRIENDSCMD.SETFRIEND;
|
|
||||||
const foundIfAlreadyFriend = await User.isMyFriend(user.idapp, data.username, data.userDest);
|
|
||||||
|
|
||||||
if (!foundIfAlreadyFriend) {
|
|
||||||
// Aggiungilo nelle Amicizie
|
|
||||||
const req = tools.getReqByPar(user.idapp, username_action);
|
|
||||||
const ris = await User.setFriendsCmd(req, user.idapp, data.username, data.userDest, cmd);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_AMICIZIA) {
|
|
||||||
|
|
||||||
if (userDest) {
|
|
||||||
cmd = shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS;
|
|
||||||
const foundIfAlreadyFriend = await User.isMyFriend(user.idapp, data.username, data.userDest);
|
|
||||||
|
|
||||||
if (foundIfAlreadyFriend) {
|
|
||||||
// Aggiungilo nelle Amicizie
|
|
||||||
const ris = await User.setFriendsCmd(req, user.idapp, data.username, data.userDest, cmd);
|
|
||||||
if (ris) {
|
|
||||||
const msgDest = printf(getstr(user.lang, 'MSG_FRIENDS_NOT_ACCEPTED_CONFIRMED'), data.username);
|
|
||||||
|
|
||||||
|
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
||||||
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
||||||
|
|
||||||
|
if (group) {
|
||||||
|
cmd = shared_consts.GROUPSCMD.SETGROUP;
|
||||||
|
const foundIfAlreadyGroup = await User.ifAlreadyInGroup(user.idapp, data.username, group.groupname);
|
||||||
|
|
||||||
|
if (!foundIfAlreadyGroup) {
|
||||||
|
// Aggiungilo nel Gruppo
|
||||||
|
await User.setGroupsCmd(user.idapp, data.username, group.groupname, cmd, 0, username_action);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
||||||
|
|
||||||
|
if (group) {
|
||||||
|
cmd = shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUP;
|
||||||
|
const foundIfAlreadyGroup = await User.ifAlreadyInGroup(user.idapp, data.username, group.groupname);
|
||||||
|
|
||||||
|
if (foundIfAlreadyGroup) {
|
||||||
|
// Rimuovilo nel Gruppo
|
||||||
|
await User.setGroupsCmd(user.idapp, data.username, group.groupname, cmd, 0, username_action);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
||||||
|
|
||||||
|
if (circuit) {
|
||||||
|
cmd = shared_consts.CIRCUITCMD.SET;
|
||||||
|
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||||
|
|
||||||
|
if (!foundIfAlreadyCircuit) {
|
||||||
|
// Aggiungilo nel Gruppo
|
||||||
|
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
||||||
|
|
||||||
|
if (circuit) {
|
||||||
|
cmd = shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST;
|
||||||
|
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||||
|
|
||||||
|
if (foundIfAlreadyCircuit) {
|
||||||
|
// Rimuovilo nel Circuito
|
||||||
|
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_AMICIZIA) {
|
||||||
|
|
||||||
|
if (userDest) {
|
||||||
|
cmd = shared_consts.FRIENDSCMD.SETFRIEND;
|
||||||
|
const foundIfAlreadyFriend = await User.isMyFriend(user.idapp, data.username, data.userDest);
|
||||||
|
|
||||||
|
if (!foundIfAlreadyFriend) {
|
||||||
|
// Aggiungilo nelle Amicizie
|
||||||
|
const req = tools.getReqByPar(user.idapp, username_action);
|
||||||
|
const ris = await User.setFriendsCmd(req, user.idapp, data.username, data.userDest, cmd);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_AMICIZIA) {
|
||||||
|
|
||||||
|
if (userDest) {
|
||||||
|
cmd = shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS;
|
||||||
|
const foundIfAlreadyFriend = await User.isMyFriend(user.idapp, data.username, data.userDest);
|
||||||
|
|
||||||
|
if (foundIfAlreadyFriend) {
|
||||||
|
// Aggiungilo nelle Amicizie
|
||||||
|
const ris = await User.setFriendsCmd(req, user.idapp, data.username, data.userDest, cmd);
|
||||||
|
if (ris) {
|
||||||
|
const msgDest = printf(getstr(user.lang, 'MSG_FRIENDS_NOT_ACCEPTED_CONFIRMED'), data.username);
|
||||||
|
|
||||||
|
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error BOT callback_query', e);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.error('Error BOT callback_query', e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
let text;
|
let text;
|
||||||
|
|
||||||
if (action === 'edit') {
|
if (action === 'edit') {
|
||||||
text = 'Edited Text';
|
text = 'Edited Text';
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.editMessageText(text, opts);
|
bot.editMessageText(text, opts);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// bot.answerCallbackQuery(callbackQuery.id, { url });
|
// bot.answerCallbackQuery(callbackQuery.id, { url });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error Telegram LOOP : ' + e.message);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.error('Error Telegram LOOP : ' + e.message);
|
|
||||||
}
|
}
|
||||||
}
|
}).catch(() => {
|
||||||
|
arrTeleg = [];
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MyTelegramBot;
|
module.exports = MyTelegramBot;
|
||||||
|
|||||||
@@ -965,7 +965,7 @@ module.exports = {
|
|||||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
let typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
||||||
let typeid = 0;
|
let typeid = 0;
|
||||||
let onlysave = false;
|
let onlysave = false;
|
||||||
let name = await User.countUsersInGroup(idapp, groupname);
|
let numuseringroup = await User.countUsersInGroup(idapp, groupname);
|
||||||
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||||
@@ -1006,7 +1006,8 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
sendNotifCircuitByUsername: async function(
|
sendNotifCircuitByUsername: async function(
|
||||||
cmd, idapp, usernameOrig, usernameDest, username_action, circuitname, path, myreccircuit, isAdmin, username_worked) {
|
cmd, idapp, usernameOrig, usernameDest, username_action,
|
||||||
|
circuitname, path, myreccircuit, isAdmin, username_worked, extrarec) {
|
||||||
|
|
||||||
const {SendNotif} = require('../models/sendnotif');
|
const {SendNotif} = require('../models/sendnotif');
|
||||||
const {User} = require('../models/user');
|
const {User} = require('../models/user');
|
||||||
@@ -1016,57 +1017,65 @@ module.exports = {
|
|||||||
|
|
||||||
const user = await User.findOne({idapp, username: usernameDest},
|
const user = await User.findOne({idapp, username: usernameDest},
|
||||||
{_id: 1, lang: 1});
|
{_id: 1, lang: 1});
|
||||||
if (user) {
|
|
||||||
|
|
||||||
let lang = user.lang;
|
try {
|
||||||
let paramsObj = {
|
if (user) {
|
||||||
usernameDest,
|
|
||||||
circuitnameDest: circuitname,
|
|
||||||
path,
|
|
||||||
username_action: username_action,
|
|
||||||
singleadmin_username: usernameDest,
|
|
||||||
options: 0,
|
|
||||||
lang,
|
|
||||||
isAdmin,
|
|
||||||
username_worked,
|
|
||||||
};
|
|
||||||
|
|
||||||
let sendnotif = true;
|
let lang = user.lang;
|
||||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
|
let paramsObj = {
|
||||||
let typeid = 0;
|
usernameDest,
|
||||||
let onlysave = false;
|
circuitnameDest: circuitname,
|
||||||
let numuserincircuit = await User.countUsersInCircuit(idapp, circuitname);
|
path,
|
||||||
|
username_action: username_action,
|
||||||
|
singleadmin_username: usernameDest,
|
||||||
|
extrarec,
|
||||||
|
options: 0,
|
||||||
|
lang,
|
||||||
|
isAdmin,
|
||||||
|
username_worked,
|
||||||
|
};
|
||||||
|
|
||||||
if (cmd) {
|
let sendnotif = true;
|
||||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
let typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
|
||||||
if (myreccircuit && myreccircuit.createdBy === usernameDest && numuserincircuit <= 1) {
|
let typeid = 0;
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
let onlysave = false;
|
||||||
} else {
|
let numuserincircuit = await User.countUsersInCircuit(idapp, circuitname);
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED;
|
|
||||||
|
if (cmd) {
|
||||||
|
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||||
|
if (myreccircuit && myreccircuit.createdBy === usernameDest && numuserincircuit <= 1) {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
||||||
|
} else {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED;
|
||||||
|
}
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED;
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED;
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
||||||
|
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||||
|
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||||
|
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
||||||
|
myreccircuit._id);
|
||||||
|
onlysave = false;
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN;
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN;
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ;
|
||||||
}
|
}
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED;
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED;
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
|
||||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
|
||||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
|
||||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
|
||||||
myreccircuit._id);
|
|
||||||
onlysave = false;
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN_OFMYGROUP;
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN_OFMYGROUP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sendnotif && typeid > 0) {
|
||||||
|
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||||
|
await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
if (sendnotif && typeid > 0) {
|
console.log(e.message);
|
||||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
|
||||||
await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -1108,7 +1117,7 @@ module.exports = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
sendNotificationByCircuit: async function(idapp, usernameOrig, circuitname, cmd, value, telegram, username_action) {
|
sendNotificationByCircuit: async function(idapp, usernameOrig, circuitname, cmd, value, telegram, username_action, extrarec) {
|
||||||
|
|
||||||
const {Circuit} = require('../models/circuit');
|
const {Circuit} = require('../models/circuit');
|
||||||
const {User} = require('../models/user');
|
const {User} = require('../models/user');
|
||||||
@@ -1121,25 +1130,35 @@ module.exports = {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// SEND TO THE ADMINS THE NOTIFICATIONS
|
// SEND TO THE ADMINS THE NOTIFICATIONS
|
||||||
for (const singleadmin of circuit.admins) {
|
|
||||||
try {
|
|
||||||
if (singleadmin.username) {
|
|
||||||
if (usernameOrig === singleadmin.username)
|
|
||||||
giainviato = true;
|
|
||||||
|
|
||||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, singleadmin.username, username_action, circuitname,
|
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||||
circuit.path, circuit, true);
|
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, extrarec.dest, username_action, circuitname, circuit.path, null,
|
||||||
|
false, '', extrarec);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
for (const singleadmin of circuit.admins) {
|
||||||
|
try {
|
||||||
|
if (singleadmin.username) {
|
||||||
|
if (usernameOrig === singleadmin.username)
|
||||||
|
giainviato = true;
|
||||||
|
|
||||||
|
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, singleadmin.username, username_action, circuitname,
|
||||||
|
circuit.path, circuit, true, '', extrarec);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('sendNotificationByCircuit', e);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
}
|
||||||
console.error('sendNotificationByCircuit', e);
|
|
||||||
|
if (!giainviato && cmd !== shared_consts.CIRCUITCMD.REQ) {
|
||||||
|
// SEND TO THE USER DEST THE NOTIFICATION
|
||||||
|
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, circuitname, circuit.path, null,
|
||||||
|
false, '', extrarec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!giainviato && (cmd !== shared_consts.CIRCUITCMD.REQ)) {
|
|
||||||
// SEND TO THE USER THE NOTIFICATION
|
|
||||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, circuitname, circuit.path, null,
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('sendNotificationByCircuit: ', e);
|
console.error('sendNotificationByCircuit: ', e);
|
||||||
@@ -1550,6 +1569,14 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
} else if (shared_consts.TABLES_NUM_AS_ID_NUMBER.includes(params.table)) {
|
||||||
|
myquery = {
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$eq: ['$Num', params.myid],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
myquery = {
|
myquery = {
|
||||||
$match: {
|
$match: {
|
||||||
@@ -1557,7 +1584,7 @@ module.exports = {
|
|||||||
$eq: ['$_id', mongoose.Types.ObjectId(params.myid)],
|
$eq: ['$_id', mongoose.Types.ObjectId(params.myid)],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ module.exports = {
|
|||||||
DELETE: 2170,
|
DELETE: 2170,
|
||||||
ADDADMIN: 2180,
|
ADDADMIN: 2180,
|
||||||
REMOVEADMIN: 2185,
|
REMOVEADMIN: 2185,
|
||||||
|
SENDCOINS_REQ: 2200,
|
||||||
|
SENDCOINS_ACCEPT: 2210,
|
||||||
|
SENDCOINS_REFUSE: 2220,
|
||||||
},
|
},
|
||||||
|
|
||||||
REPORT_FILT_RESP: 1,
|
REPORT_FILT_RESP: 1,
|
||||||
@@ -132,6 +135,8 @@ module.exports = {
|
|||||||
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
|
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
|
||||||
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
|
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
|
||||||
|
|
||||||
|
TABLES_NUM_AS_ID_NUMBER: [ 'circuits' ],
|
||||||
|
|
||||||
TABLES_ID_NUMBER: [
|
TABLES_ID_NUMBER: [
|
||||||
'permissions',
|
'permissions',
|
||||||
'levels',
|
'levels',
|
||||||
@@ -379,6 +384,7 @@ module.exports = {
|
|||||||
ID_CIRCUIT_REMOVED: 64,
|
ID_CIRCUIT_REMOVED: 64,
|
||||||
ID_CIRCUIT_ADDED_ADMIN: 128,
|
ID_CIRCUIT_ADDED_ADMIN: 128,
|
||||||
ID_CIRCUIT_REMOVED_ADMIN: 256,
|
ID_CIRCUIT_REMOVED_ADMIN: 256,
|
||||||
|
ID_CIRCUIT_SENDCOINSREQ: 512,
|
||||||
|
|
||||||
TYPEDIR_BOOKING: 6,
|
TYPEDIR_BOOKING: 6,
|
||||||
|
|
||||||
|
|||||||
27
yarn.lock
27
yarn.lock
@@ -3000,6 +3000,21 @@ dlv@^1.1.3:
|
|||||||
resolved "https://registry.yarnpkg.com/dlv/-/dlv-1.1.3.tgz#5c198a8a11453596e751494d49874bc7732f2e79"
|
resolved "https://registry.yarnpkg.com/dlv/-/dlv-1.1.3.tgz#5c198a8a11453596e751494d49874bc7732f2e79"
|
||||||
integrity sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==
|
integrity sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==
|
||||||
|
|
||||||
|
dns-packet@^1.1.0:
|
||||||
|
version "1.3.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-1.3.4.tgz#e3455065824a2507ba886c55a89963bb107dec6f"
|
||||||
|
integrity sha512-BQ6F4vycLXBvdrJZ6S3gZewt6rcrks9KBgM9vrhW+knGRqc8uEdT7fuCwloc7nny5xNoMJ17HGH0R/6fpo8ECA==
|
||||||
|
dependencies:
|
||||||
|
ip "^1.1.0"
|
||||||
|
safe-buffer "^5.0.1"
|
||||||
|
|
||||||
|
dns-socket@^1.6.1:
|
||||||
|
version "1.6.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/dns-socket/-/dns-socket-1.6.3.tgz#5268724fad4aa46ad9c5ca4ffcd16e1de5342aab"
|
||||||
|
integrity sha512-/mUy3VGqIP69dAZjh2xxHXcpK9wk2Len1Dxz8mWAdrIgFC8tnR/aQAyU4a+UTXzOcTvEvGBdp1zFiwnpWKaXng==
|
||||||
|
dependencies:
|
||||||
|
dns-packet "^1.1.0"
|
||||||
|
|
||||||
doctypes@^1.1.0:
|
doctypes@^1.1.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/doctypes/-/doctypes-1.1.0.tgz#ea80b106a87538774e8a3a4a5afe293de489e0a9"
|
resolved "https://registry.yarnpkg.com/doctypes/-/doctypes-1.1.0.tgz#ea80b106a87538774e8a3a4a5afe293de489e0a9"
|
||||||
@@ -4742,6 +4757,13 @@ inline-css@^3.0.0:
|
|||||||
slick "^1.12.2"
|
slick "^1.12.2"
|
||||||
specificity "^0.4.1"
|
specificity "^0.4.1"
|
||||||
|
|
||||||
|
internet-available@^1.0.0:
|
||||||
|
version "1.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/internet-available/-/internet-available-1.0.0.tgz#6b83ed3ef7a053fd24c6dd3dcd153e8557e197c2"
|
||||||
|
integrity sha512-jjQa6/nRKU01TlMDL4Ksxtp409PHhnTMByz8/9leJLh1xxO2Dpi6gRNH5UrDi7nW2oaluJWN7VX2IXcxsoER6A==
|
||||||
|
dependencies:
|
||||||
|
dns-socket "^1.6.1"
|
||||||
|
|
||||||
interpret@^1.1.0:
|
interpret@^1.1.0:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.2.0.tgz#d5061a6224be58e8083985f5014d844359576296"
|
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.2.0.tgz#d5061a6224be58e8083985f5014d844359576296"
|
||||||
@@ -4757,6 +4779,11 @@ ip-regex@^1.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-1.0.3.tgz#dc589076f659f419c222039a33316f1c7387effd"
|
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-1.0.3.tgz#dc589076f659f419c222039a33316f1c7387effd"
|
||||||
integrity sha1-3FiQdvZZ9BnCIgOaMzFvHHOH7/0=
|
integrity sha1-3FiQdvZZ9BnCIgOaMzFvHHOH7/0=
|
||||||
|
|
||||||
|
ip@^1.1.0:
|
||||||
|
version "1.1.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.8.tgz#ae05948f6b075435ed3307acce04629da8cdbf48"
|
||||||
|
integrity sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==
|
||||||
|
|
||||||
ip@^1.1.5:
|
ip@^1.1.5:
|
||||||
version "1.1.5"
|
version "1.1.5"
|
||||||
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
|
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
|
||||||
|
|||||||
Reference in New Issue
Block a user