ver 0.5.51
This commit is contained in:
@@ -34,7 +34,9 @@
|
|||||||
"FRIEND_UNBLOCKED": "E' stato riattivato %s da %s.",
|
"FRIEND_UNBLOCKED": "E' stato riattivato %s da %s.",
|
||||||
"FRIEND_UNBLOCKED_YOU": "Hai riattivato %s.",
|
"FRIEND_UNBLOCKED_YOU": "Hai riattivato %s.",
|
||||||
"CIRCUIT_ACCEPT_NEWENTRY": "❇️👥 🧍♂️ Accetta Ingresso nel Circuito %s:",
|
"CIRCUIT_ACCEPT_NEWENTRY": "❇️👥 🧍♂️ Accetta Ingresso nel Circuito %s:",
|
||||||
|
"CIRCUIT_ACCEPT_NEWENTRY_BYGROUP": "❇️👥 🧍♂️ Accetta Ingresso nel Circuito il gruppo %s:",
|
||||||
"CIRCUIT_REQUEST_TO_ENTER": "%s ha chiesto di entrare nel circuito %s",
|
"CIRCUIT_REQUEST_TO_ENTER": "%s ha chiesto di entrare nel circuito %s",
|
||||||
|
"CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP": "il gruppo %s ha chiesto di entrare nel circuito %s",
|
||||||
"CIRCUIT_CREATED": "✅ %s ha creato un nuovo Circuito chiamato %s",
|
"CIRCUIT_CREATED": "✅ %s ha creato un nuovo Circuito chiamato %s",
|
||||||
"CIRCUIT_REQUEST": "Richiesta di entrare nel Circuito %s da parte di %s",
|
"CIRCUIT_REQUEST": "Richiesta di entrare nel Circuito %s da parte di %s",
|
||||||
"CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore del circuito %s da parte di %s",
|
"CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore del circuito %s da parte di %s",
|
||||||
@@ -44,6 +46,7 @@
|
|||||||
"RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il Circuito %s da parte di %s",
|
"RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il Circuito %s da parte di %s",
|
||||||
"CIRCUIT_ELIMINATO": "Il circuito %s è stato eliminato da parte di %s",
|
"CIRCUIT_ELIMINATO": "Il circuito %s è stato eliminato da parte di %s",
|
||||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT": "✅ l'utente %s è stato accettato a far parte del Circuito %s (da parte di %s)",
|
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT": "✅ l'utente %s è stato accettato a far parte del Circuito %s (da parte di %s)",
|
||||||
|
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP": "✅ il gruppo %s è stato accettato a far parte del Circuito %s (da parte di %s)",
|
||||||
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Circuito %s.\nApri la APP e clicca in alto a destra sull'icona delle monete, oppure clicca qui: %s",
|
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Circuito %s.\nApri la APP e clicca in alto a destra sull'icona delle monete, oppure clicca qui: %s",
|
||||||
"CIRCUIT_ACCEPTED_YOU": "✅ Hai accettato %s a far parte del Circuito %s",
|
"CIRCUIT_ACCEPTED_YOU": "✅ Hai accettato %s a far parte del Circuito %s",
|
||||||
"CIRCUIT_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del Circuito %s. Se pensi sia un'errore, contatta l'amministratore del Circuito.",
|
"CIRCUIT_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del Circuito %s. Se pensi sia un'errore, contatta l'amministratore del Circuito.",
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ const AccountSchema = new Schema({
|
|||||||
username: {
|
username: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
groupname: { // For the Groups
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
circuitId: { // ----- REF TO Circuit
|
circuitId: { // ----- REF TO Circuit
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -192,7 +195,7 @@ AccountSchema.pre('save', async function (next) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist) {
|
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, groupname = '') {
|
||||||
const Account = this;
|
const Account = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -203,11 +206,16 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
let myquery = {
|
let myquery = {
|
||||||
'idapp': idapp,
|
idapp,
|
||||||
'username': username,
|
|
||||||
circuitId,
|
circuitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (groupname) {
|
||||||
|
myquery.groupname = groupname;
|
||||||
|
} else {
|
||||||
|
myquery.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
let mycircuit = await Circuit.getCircuitById(circuitId);
|
let mycircuit = await Circuit.getCircuitById(circuitId);
|
||||||
|
|
||||||
if (mycircuit) {
|
if (mycircuit) {
|
||||||
@@ -218,14 +226,28 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
|||||||
_id: new ObjectID().toString(),
|
_id: new ObjectID().toString(),
|
||||||
idapp,
|
idapp,
|
||||||
username,
|
username,
|
||||||
|
groupname,
|
||||||
circuitId: mycircuit._id,
|
circuitId: mycircuit._id,
|
||||||
deperibile: false,
|
deperibile: false,
|
||||||
fidoConcesso: mycircuit.fido_scoperto_default,
|
|
||||||
qta_maxConcessa: mycircuit.qta_max_default,
|
|
||||||
importo_iniziale: 0,
|
importo_iniziale: 0,
|
||||||
saldo: 0,
|
saldo: 0,
|
||||||
|
fidoConcesso: 0,
|
||||||
|
qta_maxConcessa: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!mycircuit.fido_scoperto_default_grp)
|
||||||
|
mycircuit.fido_scoperto_default_grp = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_GRP;
|
||||||
|
if (!mycircuit.qta_max_default_grp)
|
||||||
|
mycircuit.qta_max_default_grp = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MAX_GRP;
|
||||||
|
|
||||||
|
if (groupname) {
|
||||||
|
myaccount.fidoConcesso = mycircuit.fido_scoperto_default_grp;
|
||||||
|
myaccount.qta_maxConcessa = mycircuit.qta_max_default_grp;
|
||||||
|
} else {
|
||||||
|
myaccount.fidoConcesso = mycircuit.fido_scoperto_default;
|
||||||
|
myaccount.qta_maxConcessa = mycircuit.qta_max_default;
|
||||||
|
}
|
||||||
|
|
||||||
return await myaccount.save();
|
return await myaccount.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,14 +261,14 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName) {
|
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, groupname = '') {
|
||||||
|
|
||||||
const { Circuit } = require('../models/circuit');
|
const { Circuit } = require('../models/circuit');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mycircuit = await Circuit.findOne({ name: circuitName }, {_id: 1});
|
mycircuit = await Circuit.findOne({ name: circuitName }, {_id: 1});
|
||||||
if (mycircuit) {
|
if (mycircuit) {
|
||||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true);
|
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, groupname);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -323,6 +345,97 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
let aggr1 = [
|
||||||
|
{
|
||||||
|
$match: { idapp, groupname },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'circuits',
|
||||||
|
localField: 'circuitId',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'circuit',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $unwind: '$circuit' },
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'sendnotifs',
|
||||||
|
as: 'notifspending',
|
||||||
|
let: {
|
||||||
|
circuitname: '$circuit.name',
|
||||||
|
groupname: '$groupname',
|
||||||
|
idapp: '$idapp',
|
||||||
|
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
||||||
|
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
||||||
|
},
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$and: [
|
||||||
|
{ $eq: ['$typedir', '$$typedir'] },
|
||||||
|
{ $eq: ['$typeid', '$$typeid'] },
|
||||||
|
{ $eq: ['$status', 0] },
|
||||||
|
{ $eq: ['$sender', '$$username'] },
|
||||||
|
{ $eq: ['$idapp', '$$idapp'] },
|
||||||
|
{ $eq: ['$extrarec.circuitname', '$$circuitname'] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
ris = await this.aggregate(aggr1);
|
||||||
|
|
||||||
|
const { SendNotif } = require('../models/sendnotif');
|
||||||
|
|
||||||
|
if (ris) {
|
||||||
|
for (const account of ris) {
|
||||||
|
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, '', account.circuit.name, groupname);
|
||||||
|
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||||
|
account.saldo -= saldopending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ris;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('e', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Aggiungi agli Admin del Account
|
||||||
|
AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||||
|
|
||||||
|
return await Account.updateOne({ idapp, username, circuitId },
|
||||||
|
{
|
||||||
|
$push:
|
||||||
|
{
|
||||||
|
people: {
|
||||||
|
username: person_username,
|
||||||
|
perm,
|
||||||
|
date: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Rimuovi dagli Admin del Account
|
||||||
|
AccountSchema.statics.removeAdminOfAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||||
|
|
||||||
|
return await Circuit.updateOne({ idapp, username, circuitId },
|
||||||
|
{ $pull: { people: { username: { $in: [person_username] } } } });
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const Account = mongoose.model('Account', AccountSchema);
|
const Account = mongoose.model('Account', AccountSchema);
|
||||||
|
|
||||||
module.exports = { Account };
|
module.exports = { Account };
|
||||||
|
|||||||
@@ -106,6 +106,12 @@ const CircuitSchema = new Schema({
|
|||||||
qta_max_default: {
|
qta_max_default: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
fido_scoperto_default_grp: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
|
qta_max_default_grp: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
data_costituz: {
|
data_costituz: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
@@ -173,6 +179,18 @@ const CircuitSchema = new Schema({
|
|||||||
username: { type: String },
|
username: { type: String },
|
||||||
date: { type: Date },
|
date: { type: Date },
|
||||||
}], // username
|
}], // username
|
||||||
|
req_groups: [
|
||||||
|
{
|
||||||
|
_id: false,
|
||||||
|
groupname: { type: String },
|
||||||
|
date: { type: Date },
|
||||||
|
}], // username
|
||||||
|
refused_groups: [
|
||||||
|
{
|
||||||
|
_id: false,
|
||||||
|
groupname: { type: String },
|
||||||
|
date: { type: Date },
|
||||||
|
}], // username
|
||||||
deleted: {
|
deleted: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
@@ -245,10 +263,12 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
|||||||
date_updated: 1,
|
date_updated: 1,
|
||||||
nome_valuta: 1,
|
nome_valuta: 1,
|
||||||
fido_scoperto_default: 1,
|
fido_scoperto_default: 1,
|
||||||
|
qta_max_default: 1,
|
||||||
|
fido_scoperto_default_grp: 1,
|
||||||
|
qta_max_default_grp: 1,
|
||||||
deperimento: 1,
|
deperimento: 1,
|
||||||
transactionsEnabled: 1,
|
transactionsEnabled: 1,
|
||||||
status: 1,
|
status: 1,
|
||||||
qta_max_default: 1,
|
|
||||||
valuta_per_euro: 1,
|
valuta_per_euro: 1,
|
||||||
symbol: 1,
|
symbol: 1,
|
||||||
idCity: 1,
|
idCity: 1,
|
||||||
@@ -261,6 +281,8 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
|||||||
admins: 1,
|
admins: 1,
|
||||||
req_users: 1,
|
req_users: 1,
|
||||||
refused_users: 1,
|
refused_users: 1,
|
||||||
|
req_groups: 1,
|
||||||
|
refused_groups: 1,
|
||||||
'mycities': 1,
|
'mycities': 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -304,6 +326,8 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
|||||||
totCircolante: 1,
|
totCircolante: 1,
|
||||||
totTransato: 1,
|
totTransato: 1,
|
||||||
fido_scoperto_default: 1,
|
fido_scoperto_default: 1,
|
||||||
|
fido_scoperto_default_grp: 1,
|
||||||
|
qta_max_default_grp: 1,
|
||||||
qta_max_default: 1,
|
qta_max_default: 1,
|
||||||
valuta_per_euro: 1,
|
valuta_per_euro: 1,
|
||||||
symbol: 1,
|
symbol: 1,
|
||||||
@@ -320,6 +344,8 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
|||||||
date_updated: 1,
|
date_updated: 1,
|
||||||
req_users: 1,
|
req_users: 1,
|
||||||
refused_users: 1,
|
refused_users: 1,
|
||||||
|
req_groups: 1,
|
||||||
|
refused_groups: 1,
|
||||||
transactionsEnabled: 1,
|
transactionsEnabled: 1,
|
||||||
status: 1,
|
status: 1,
|
||||||
'mycities': 1,
|
'mycities': 1,
|
||||||
@@ -620,8 +646,8 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
|||||||
if (circuittable) {
|
if (circuittable) {
|
||||||
const myqty = Math.abs(extrarec.qty);
|
const myqty = Math.abs(extrarec.qty);
|
||||||
|
|
||||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true);
|
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true, extrarec.groupdest);
|
||||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true);
|
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true, extrarec.grouporig);
|
||||||
|
|
||||||
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
||||||
|
|
||||||
@@ -658,7 +684,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
|||||||
await Circuit.updateOne({ _id: circuittable }, { $set: paramstoupdate });
|
await Circuit.updateOne({ _id: circuittable }, { $set: paramstoupdate });
|
||||||
|
|
||||||
ris.result = true;
|
ris.result = true;
|
||||||
console.log('Inviate Monete da', usernameOrig, extrarec.dest, myqty, extrarec.causal);
|
console.log('Inviate Monete da', usernameOrig, extrarec.grouporig, extrarec.dest, extrarec.groupdest, myqty, extrarec.causal);
|
||||||
|
|
||||||
ris.useraccounts = await Account.getUserAccounts(idapp, usernameOrig);
|
ris.useraccounts = await Account.getUserAccounts(idapp, usernameOrig);
|
||||||
|
|
||||||
@@ -666,7 +692,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
|||||||
extrarec.saldoDest = accountdestTable.saldo;
|
extrarec.saldoDest = accountdestTable.saldo;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log('NON Inviate Monete da', usernameOrig, extrarec.dest, myqty, extrarec.causal);
|
console.log('NON Inviate Monete da', usernameOrig, extrarec.grouporig, extrarec.dest, extrarec.groupdest, myqty, extrarec.causal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -688,6 +714,13 @@ CircuitSchema.statics.removeReqCircuit = async function (idapp, username, name)
|
|||||||
{ $pull: { req_users: { username: { $in: [username] } } } });
|
{ $pull: { req_users: { username: { $in: [username] } } } });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Rimuovo la Richiesta del Gruppo sul Circuito
|
||||||
|
CircuitSchema.statics.removeReqGroupCircuit = async function (idapp, groupname, name) {
|
||||||
|
|
||||||
|
return await Circuit.updateOne({ idapp, name },
|
||||||
|
{ $pull: { req_groups: { groupname: { $in: [groupname] } } } });
|
||||||
|
};
|
||||||
|
|
||||||
// Aggiungi agli utenti Rifiutati del Circuito
|
// Aggiungi agli utenti Rifiutati del Circuito
|
||||||
|
|
||||||
CircuitSchema.statics.refuseReqCircuit = async function (idapp, username, name) {
|
CircuitSchema.statics.refuseReqCircuit = async function (idapp, username, name) {
|
||||||
@@ -705,6 +738,21 @@ CircuitSchema.statics.refuseReqCircuit = async function (idapp, username, name)
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CircuitSchema.statics.refuseReqGroupCircuit = async function (idapp, groupname, name) {
|
||||||
|
|
||||||
|
return await Circuit.updateOne({ idapp, name },
|
||||||
|
{
|
||||||
|
$push:
|
||||||
|
{
|
||||||
|
refused_groups: {
|
||||||
|
groupname,
|
||||||
|
date: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
CircuitSchema.statics.updateData = async function (idapp, circuitname) {
|
CircuitSchema.statics.updateData = async function (idapp, circuitname) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ const MyGroupSchema = new Schema({
|
|||||||
admins: [
|
admins: [
|
||||||
{
|
{
|
||||||
username: { type: String },
|
username: { type: String },
|
||||||
|
perm: { type: Number },
|
||||||
date: { type: Date },
|
date: { type: Date },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -110,10 +111,11 @@ const MyGroupSchema = new Schema({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
circuits_list: [
|
mycircuits: [
|
||||||
{
|
{
|
||||||
Num: { type: Number },
|
_id: false,
|
||||||
inscription_date: {type: Date},
|
circuitname: { type: String },
|
||||||
|
date: { type: Date },
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -220,6 +222,20 @@ MyGroupSchema.statics.removeAdminOfMyGroup = async function(idapp, username, gro
|
|||||||
{ $pull: { admins: { username: { $in: [username] } } } });
|
{ $pull: { admins: { username: { $in: [username] } } } });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.getListAdminsByGroupName = async function (idapp, groupname) {
|
||||||
|
|
||||||
|
let arr = await MyGroup.findOne({
|
||||||
|
idapp,
|
||||||
|
groupname,
|
||||||
|
$or: [
|
||||||
|
{ deleted: { $exists: false } },
|
||||||
|
{ deleted: { $exists: true, $eq: false } }],
|
||||||
|
}, {admins: 1}).lean();
|
||||||
|
|
||||||
|
return arr && arr.admins ? arr.admins : [];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
|
MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
|
||||||
// FOR ME, PERMIT ALL
|
// FOR ME, PERMIT ALL
|
||||||
return {
|
return {
|
||||||
@@ -242,7 +258,7 @@ MyGroupSchema.statics.getWhatToShow = function(idapp, username) {
|
|||||||
createdBy: 1,
|
createdBy: 1,
|
||||||
date_created: 1,
|
date_created: 1,
|
||||||
date_updated: 1,
|
date_updated: 1,
|
||||||
circuits_list: 1,
|
mycircuits: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -259,7 +275,7 @@ MyGroupSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
|||||||
note: 1,
|
note: 1,
|
||||||
date_created: 1,
|
date_created: 1,
|
||||||
date_updated: 1,
|
date_updated: 1,
|
||||||
circuits_list: 1,
|
mycircuits: 1,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -295,12 +311,12 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
|
|||||||
|
|
||||||
const query = [
|
const query = [
|
||||||
{ $match: myfind },
|
{ $match: myfind },
|
||||||
{ $unwind: '$circuits_list' },
|
{ $unwind: '$mycircuits' },
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'circuits',
|
from: 'circuits',
|
||||||
localField: 'circuits_list.Num',
|
localField: 'mycircuits.circuitname',
|
||||||
foreignField: 'Num',
|
foreignField: 'name',
|
||||||
as: 'mycircuits',
|
as: 'mycircuits',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -465,6 +481,35 @@ MyGroupSchema.statics.extractCitiesName = async function(idapp, id) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.ifCircuitAlreadyInGroup = async function (idapp, groupname, circuitname) {
|
||||||
|
|
||||||
|
// Controllo se è stato già inserito il circuito sul gruppo
|
||||||
|
return await this.findOne({
|
||||||
|
idapp,
|
||||||
|
groupname,
|
||||||
|
'mycircuits': {
|
||||||
|
$elemMatch: { circuitname: { $eq: circuitname } },
|
||||||
|
},
|
||||||
|
}).lean();
|
||||||
|
};
|
||||||
|
|
||||||
|
// aggiungo il Circuito all'interno del Gruppo
|
||||||
|
MyGroupSchema.statics.addCircuitFromGroup = async function (idapp, groupname, circuitname) {
|
||||||
|
return await this.updateOne({ idapp, groupname },
|
||||||
|
{ $push: { 'mycircuits': {
|
||||||
|
circuitname,
|
||||||
|
date: new Date(),
|
||||||
|
} } });
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Rimuovo il Circuito all'interno del Gruppo
|
||||||
|
MyGroupSchema.statics.removeCircuitFromGroup = async function (idapp, groupname, circuitname) {
|
||||||
|
return await this.updateOne({ idapp, groupname },
|
||||||
|
{ $pull: { 'mycircuits': { circuitname: { $in: [circuitname] } } } });
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const MyGroup = mongoose.model('MyGroup', MyGroupSchema);
|
const MyGroup = mongoose.model('MyGroup', MyGroupSchema);
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ const sendNotifSchema = new Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
sendergroup: { // mittente
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
destgroup: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -275,8 +283,14 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
|||||||
newdescr = i18n.__('CIRCUIT_CREATED', userorig, recnotif.paramsObj.circuitnameDest);
|
newdescr = i18n.__('CIRCUIT_CREATED', userorig, recnotif.paramsObj.circuitnameDest);
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||||
if (recnotif.paramsObj.isAdmin) {
|
if (recnotif.paramsObj.isAdmin) {
|
||||||
|
if (recnotif.extrarec.groupname) {
|
||||||
|
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP', recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||||
|
recnotif.paramsObj.username_action);
|
||||||
|
} else {
|
||||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest,
|
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest,
|
||||||
recnotif.paramsObj.username_action);
|
recnotif.paramsObj.username_action);
|
||||||
|
}
|
||||||
|
|
||||||
recnotif.openUrl = '/my/' + userorig;
|
recnotif.openUrl = '/my/' + userorig;
|
||||||
} else {
|
} else {
|
||||||
if (userorig === recnotif.paramsObj.usernameDest) {
|
if (userorig === recnotif.paramsObj.usernameDest) {
|
||||||
@@ -307,8 +321,13 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
|||||||
}
|
}
|
||||||
tag = 'refcircuit';
|
tag = 'refcircuit';
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
|
||||||
|
if (recnotif.extrarec.groupname) {
|
||||||
|
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP', recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||||
|
recnotif.paramsObj.singleadmin_username);
|
||||||
|
} else {
|
||||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest,
|
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest,
|
||||||
recnotif.paramsObj.singleadmin_username);
|
recnotif.paramsObj.singleadmin_username);
|
||||||
|
}
|
||||||
tag = 'reqcircuits';
|
tag = 'reqcircuits';
|
||||||
|
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
|
||||||
@@ -336,8 +355,10 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
|||||||
tag = 'sendcoin';
|
tag = 'sendcoin';
|
||||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT) {
|
||||||
|
let mydest = recnotif.paramsObj.extrarec.groupdest ? recnotif.paramsObj.extrarec.groupdest : recnotif.paramsObj.extrarec.dest;
|
||||||
|
|
||||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_ME', recnotif.paramsObj.extrarec.qty.toString(),
|
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_ME', recnotif.paramsObj.extrarec.qty.toString(),
|
||||||
recnotif.paramsObj.extrarec.symbol, recnotif.paramsObj.extrarec.dest);
|
recnotif.paramsObj.extrarec.symbol, mydest);
|
||||||
tag = 'sendcoin';
|
tag = 'sendcoin';
|
||||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
|
||||||
@@ -425,7 +446,9 @@ sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res,
|
|||||||
const SendNotif = this;
|
const SendNotif = this;
|
||||||
|
|
||||||
let idapp = req.body.idapp;
|
let idapp = req.body.idapp;
|
||||||
const check = tools.checkUserOk(myrecnotif.sender, user ? myrecnotif.sender : req.user.username, res);
|
let check = tools.checkUserOk(myrecnotif.sender, user ? myrecnotif.sender : req.user.username, res);
|
||||||
|
if (!check)
|
||||||
|
check = tools.checkUserOk(myrecnotif.sendergroup, user ? myrecnotif.sendergroup : req.user.username, res);
|
||||||
if (check.exit) return check.ret;
|
if (check.exit) return check.ret;
|
||||||
|
|
||||||
const { myrecout, save } = await SendNotif.updateStatusAndDescr(myrecnotif, false);
|
const { myrecout, save } = await SendNotif.updateStatusAndDescr(myrecnotif, false);
|
||||||
@@ -474,6 +497,8 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
|||||||
|
|
||||||
let sender = myrecnotif.sender;
|
let sender = myrecnotif.sender;
|
||||||
let newdest = myrecnotif.dest;
|
let newdest = myrecnotif.dest;
|
||||||
|
let sendergroup = myrecnotif.sendergroup;
|
||||||
|
let newdestgroup = myrecnotif.destgroup;
|
||||||
|
|
||||||
// Controllare se devo modificare un Notif già esistente !
|
// Controllare se devo modificare un Notif già esistente !
|
||||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||||
@@ -550,6 +575,8 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
|||||||
datenotif: new Date(),
|
datenotif: new Date(),
|
||||||
sender,
|
sender,
|
||||||
dest: newdest,
|
dest: newdest,
|
||||||
|
sendergroup,
|
||||||
|
destgroup: newdestgroup,
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = {
|
let query = {
|
||||||
@@ -651,7 +678,9 @@ sendNotifSchema.statics.getDefaultRec = function(req) {
|
|||||||
typedir: '',
|
typedir: '',
|
||||||
typeid: '',
|
typeid: '',
|
||||||
sender: req.user ? req.user.username : '',
|
sender: req.user ? req.user.username : '',
|
||||||
|
sendergroup: '',
|
||||||
dest: '',
|
dest: '',
|
||||||
|
destgroup: '',
|
||||||
descr: '',
|
descr: '',
|
||||||
openUrl: '',
|
openUrl: '',
|
||||||
datenotif: new Date(),
|
datenotif: new Date(),
|
||||||
@@ -859,13 +888,14 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sendNotifSchema.statics.getSumPendingTransactions = async function(idapp, username, circuitname) {
|
sendNotifSchema.statics.getSumPendingTransactions = async function (idapp, username, circuitname, groupname) {
|
||||||
const SendNotif = this;
|
const SendNotif = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const query = {
|
const query = {
|
||||||
idapp,
|
idapp,
|
||||||
sender: username,
|
sender: username,
|
||||||
|
sendergroup: groupname,
|
||||||
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
||||||
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
||||||
status: 0,
|
status: 0,
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const UserSchema = new mongoose.Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
trim: true,
|
trim: true,
|
||||||
minlength: 6,
|
minlength: 3,
|
||||||
unique: false,
|
unique: false,
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
@@ -421,8 +421,7 @@ const UserSchema = new mongoose.Schema({
|
|||||||
type: Number,
|
type: Number,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
;
|
|
||||||
|
|
||||||
UserSchema.methods.toJSON = function () {
|
UserSchema.methods.toJSON = function () {
|
||||||
const user = this;
|
const user = this;
|
||||||
@@ -2270,8 +2269,40 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
result: false,
|
result: false,
|
||||||
};
|
};
|
||||||
let update = {};
|
let update = {};
|
||||||
|
|
||||||
|
let groupname = extrarec && extrarec.groupname ? extrarec.groupname : '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||||
|
if (groupname) {
|
||||||
|
const foundIfCircuitInGroup = await MyGroup.ifCircuitAlreadyInGroup(idapp, groupname, circuitname);
|
||||||
|
|
||||||
|
if (!foundIfCircuitInGroup) {
|
||||||
|
ris = await MyGroup.addCircuitFromGroup(idapp, groupname, circuitname);
|
||||||
|
|
||||||
|
// Elimina la richiesta:
|
||||||
|
update = { $pull: { req_groups: { groupname: { $in: [groupname] } } } };
|
||||||
|
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||||
|
|
||||||
|
// Elimina eventualmente se era bloccato:
|
||||||
|
update = { $pull: { refused_groups: { groupname: { $in: [groupname] } } } };
|
||||||
|
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||||
|
|
||||||
|
await Account.createAccount(idapp, '', circuitname, groupname);
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ris = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Circuit.updateData(idapp, circuitname)
|
||||||
|
if (ris) {
|
||||||
|
// Invia una notifica alla persona e agli Admin
|
||||||
|
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
||||||
|
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
||||||
|
|
||||||
if (!foundIfAlreadyCircuit) {
|
if (!foundIfAlreadyCircuit) {
|
||||||
@@ -2306,7 +2337,46 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
||||||
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||||
|
|
||||||
|
if (groupname) {
|
||||||
|
// Aggiungo la richiesta di Gruppo a me
|
||||||
|
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||||
|
idapp,
|
||||||
|
name: circuitname,
|
||||||
|
'req_groups': {
|
||||||
|
$elemMatch: { groupname: { $eq: groupname } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
if (!foundIfAlreadyAskCircuit) {
|
||||||
|
update = {
|
||||||
|
$push: {
|
||||||
|
'req_groups': {
|
||||||
|
groupname,
|
||||||
|
date: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ris = await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (ris) {
|
||||||
|
// Invia una notifica alla persona
|
||||||
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, true, true, username_action, extrarec);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (foundIfAlreadyAskCircuit) {
|
||||||
|
outres.result = await MyGroup.removeCircuitFromGroup(idapp, groupname, circuitname); // Rimuovo il Circuito dal gruppo
|
||||||
|
|
||||||
|
// Invia una notifica alla persona
|
||||||
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
// Aggiungo la richiesta di Gruppo a me
|
// Aggiungo la richiesta di Gruppo a me
|
||||||
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||||
idapp,
|
idapp,
|
||||||
@@ -2342,6 +2412,9 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||||
|
|
||||||
// Remove if is also an Admin
|
// Remove if is also an Admin
|
||||||
@@ -2368,16 +2441,24 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.CANCEL_REQ) {
|
} else if (cmd === shared_consts.CIRCUITCMD.CANCEL_REQ) {
|
||||||
|
|
||||||
|
if (groupname)
|
||||||
|
outres.result = await Circuit.removeReqGroupCircuit(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
else
|
||||||
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
await Circuit.updateData(idapp, circuitname)
|
await Circuit.updateData(idapp, circuitname)
|
||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||||
|
|
||||||
|
if (groupname) {
|
||||||
|
outres.result = await MyGroup.removeCircuitFromGroup(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
outres.result = await Circuit.removeReqGroupCircuit(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
outres.result = await Circuit.refuseReqGroupCircuit(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
} else {
|
||||||
outres.result = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
outres.result = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
outres.result = await Circuit.refuseReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
outres.result = await Circuit.refuseReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
}
|
||||||
|
|
||||||
// Invia una notifica alla persona
|
// Invia una notifica alla persona
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
@@ -2438,6 +2519,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT && outcheck.cansend) {
|
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT && outcheck.cansend) {
|
||||||
if (!await Movement.checkIfCoinsAlreadySent(extrarec.notifId)) {
|
if (!await Movement.checkIfCoinsAlreadySent(extrarec.notifId)) {
|
||||||
outres = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
|
outres = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
outcheck.cansend = false; //GIA INVIATO
|
outcheck.cansend = false; //GIA INVIATO
|
||||||
}
|
}
|
||||||
@@ -2446,6 +2528,10 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
if (outcheck.cansend) {
|
if (outcheck.cansend) {
|
||||||
// Invia una notifica di moneta (accettata o rifiutata) alla persona
|
// Invia una notifica di moneta (accettata o rifiutata) alla persona
|
||||||
const out = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
const out = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
|
if (outres && extrarec.groupname) {
|
||||||
|
// Setta agli altri admin,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
|
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
|
||||||
@@ -2466,6 +2552,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
outres.userprofile = userprofile;
|
outres.userprofile = userprofile;
|
||||||
}
|
}
|
||||||
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
||||||
|
outres.mygroups = await MyGroup.findAllGroups(idapp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (circuitname)
|
if (circuitname)
|
||||||
|
|||||||
@@ -821,7 +821,7 @@ const MyTelegramBot = {
|
|||||||
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
|
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
|
||||||
},
|
},
|
||||||
|
|
||||||
askConfirmationUser: async function(idapp, myfunc, myuser, userDest = '', groupname = '', groupid = '', regexpire = '') {
|
askConfirmationUser: async function (idapp, myfunc, myuser, userDest = '', name = '', groupid = '', regexpire = '', groupname = '') {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cl = getclTelegByidapp(idapp);
|
const cl = getclTelegByidapp(idapp);
|
||||||
@@ -878,7 +878,7 @@ const MyTelegramBot = {
|
|||||||
}
|
}
|
||||||
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
||||||
|
|
||||||
domanda = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), groupname) + '<br>' + struserinfomsg;
|
domanda = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), name) + '<br>' + struserinfomsg;
|
||||||
|
|
||||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||||
{
|
{
|
||||||
@@ -892,7 +892,23 @@ 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;
|
if (groupname) {
|
||||||
|
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY_BYGROUP', locale: langdest }, groupname) + '<br>' + struserinfomsg;
|
||||||
|
|
||||||
|
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||||
|
{
|
||||||
|
text: '✅ Accetta ' + groupname,
|
||||||
|
callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||||
|
groupid + tools.SEP + groupname,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '🚫 Rifiuta ' + groupname,
|
||||||
|
callback_data: InlineConferma.RISPOSTA_NO + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||||
|
groupid + tools.SEP + groupname,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest }, name) + '<br>' + struserinfomsg;
|
||||||
|
|
||||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||||
{
|
{
|
||||||
@@ -907,6 +923,7 @@ const MyTelegramBot = {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Invia Msg
|
// Invia Msg
|
||||||
if (domanda) {
|
if (domanda) {
|
||||||
@@ -3889,6 +3906,7 @@ if (true) {
|
|||||||
userDest: '',
|
userDest: '',
|
||||||
groupId: 0,
|
groupId: 0,
|
||||||
circuitId: '',
|
circuitId: '',
|
||||||
|
groupname: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const datastr = callbackQuery.data;
|
const datastr = callbackQuery.data;
|
||||||
@@ -3901,6 +3919,7 @@ if (true) {
|
|||||||
userDest: dataarr[2] ? dataarr[2] : '',
|
userDest: dataarr[2] ? dataarr[2] : '',
|
||||||
groupId: dataarr[3] ? parseInt(dataarr[3]) : '',
|
groupId: dataarr[3] ? parseInt(dataarr[3]) : '',
|
||||||
circuitId: dataarr[4] ? dataarr[4] : '',
|
circuitId: dataarr[4] ? dataarr[4] : '',
|
||||||
|
groupname: dataarr[5] ? dataarr[5] : '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4022,23 +4041,31 @@ if (true) {
|
|||||||
|
|
||||||
if (circuit) {
|
if (circuit) {
|
||||||
cmd = shared_consts.CIRCUITCMD.SET;
|
cmd = shared_consts.CIRCUITCMD.SET;
|
||||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
let foundIfAlreadyCircuit = false;
|
||||||
|
if (data.groupname) {
|
||||||
|
foundIfAlreadyCircuit = await MyGroup.ifCircuitAlreadyInGroup(user.idapp, data.groupname, circuit.name);
|
||||||
|
} else {
|
||||||
|
foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||||
|
}
|
||||||
if (!foundIfAlreadyCircuit) {
|
if (!foundIfAlreadyCircuit) {
|
||||||
// Aggiungilo nel Circuito
|
// Aggiungilo nel Circuito
|
||||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action, {groupname: data.groupname});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
||||||
|
|
||||||
if (circuit) {
|
if (circuit) {
|
||||||
cmd = shared_consts.CIRCUITCMD.REFUSE_REQ;
|
cmd = shared_consts.CIRCUITCMD.REFUSE_REQ;
|
||||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
let foundIfAlreadyCircuit = false;
|
||||||
|
if (data.groupname) {
|
||||||
|
foundIfAlreadyCircuit = await MyGroup.ifCircuitAlreadyInGroup(user.idapp, data.groupname, circuit.name);
|
||||||
|
} else {
|
||||||
|
foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||||
|
}
|
||||||
|
|
||||||
if (foundIfAlreadyCircuit) {
|
if (foundIfAlreadyCircuit) {
|
||||||
// Rimuovilo nel Circuito
|
// Rimuovilo nel Circuito
|
||||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action, {groupname: data.groupname});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const CryptoJS = require('crypto-js');
|
|||||||
|
|
||||||
const Url = require('url-parse');
|
const Url = require('url-parse');
|
||||||
|
|
||||||
const { ObjectID } = require('mongodb');
|
const { ObjectID, ObjectId } = require('mongodb');
|
||||||
|
|
||||||
const shared_consts = require('./shared_nodejs');
|
const shared_consts = require('./shared_nodejs');
|
||||||
|
|
||||||
@@ -836,8 +836,10 @@ module.exports = {
|
|||||||
}).catch(async (err) => {
|
}).catch(async (err) => {
|
||||||
console.error('err Push', err.body);
|
console.error('err Push', err.body);
|
||||||
|
|
||||||
|
if (err.body) {
|
||||||
// Cancella dal DB la notifica Push, visto che da errore! (sarà scaduto)
|
// Cancella dal DB la notifica Push, visto che da errore! (sarà scaduto)
|
||||||
const ris = await Subscription.deleteOne({ _id: subscription._id });
|
const ris = await Subscription.deleteOne({ _id: subscription._id });
|
||||||
|
}
|
||||||
|
|
||||||
reject({
|
reject({
|
||||||
status: false,
|
status: false,
|
||||||
@@ -1020,6 +1022,7 @@ module.exports = {
|
|||||||
const { SendNotif } = require('../models/sendnotif');
|
const { SendNotif } = require('../models/sendnotif');
|
||||||
const { User } = require('../models/user');
|
const { User } = require('../models/user');
|
||||||
const telegrambot = require('../telegram/telegrambot');
|
const telegrambot = require('../telegram/telegrambot');
|
||||||
|
const { MyGroup } = require('../models/mygroup');
|
||||||
|
|
||||||
const req = this.getReqByPar(idapp, usernameOrig);
|
const req = this.getReqByPar(idapp, usernameOrig);
|
||||||
|
|
||||||
@@ -1065,7 +1068,7 @@ module.exports = {
|
|||||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
||||||
myreccircuit._id);
|
myreccircuit._id, '', extrarec.groupname);
|
||||||
onlysave = false;
|
onlysave = false;
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN;
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN;
|
||||||
@@ -1074,6 +1077,8 @@ module.exports = {
|
|||||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ;
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ;
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ_SENT) {
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ_SENT) {
|
||||||
|
// Crea l'ID di Transazione
|
||||||
|
paramsObj.idTransaction = new ObjectId();
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT;
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT;
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
||||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED;
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED;
|
||||||
@@ -1088,10 +1093,27 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sendnotif && typeid > 0) {
|
if (sendnotif && typeid > 0) {
|
||||||
|
// Check if is group:
|
||||||
|
if (extrarec.groupdest) {
|
||||||
|
|
||||||
|
let arrusers = await MyGroup.getListAdminsByGroupName(idapp, extrarec.groupdest);
|
||||||
|
|
||||||
|
let ris = null;
|
||||||
|
|
||||||
|
for (let i = 0; i < arrusers.length; i++) {
|
||||||
|
paramsObj.usernameDest = arrusers[i].username;
|
||||||
|
ris = await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||||
|
if (!ris) {
|
||||||
|
console.error('Errore createNewNotifToSingleUser! ', paramsObj.usernameDest, "dest ->", extrarec.groupdest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||||
return await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
return await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
}
|
}
|
||||||
@@ -1297,7 +1319,7 @@ module.exports = {
|
|||||||
this.mylog('checkUserOk', userpassed, userauth);
|
this.mylog('checkUserOk', userpassed, userauth);
|
||||||
if (String(userpassed) !== String(userauth)) {
|
if (String(userpassed) !== String(userauth)) {
|
||||||
// I'm trying to write something not mine!
|
// I'm trying to write something not mine!
|
||||||
this.mylog('userId = ', userpassed, 'req.user._id', userauth);
|
this.mylog('I\'m trying to write something not mine!: userId = ', userpassed, 'req.user._id', userauth);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return {
|
return {
|
||||||
exit: true,
|
exit: true,
|
||||||
|
|||||||
@@ -440,6 +440,10 @@ module.exports = {
|
|||||||
|
|
||||||
replaceUsername: async function (idapp, search_username, replace_username) {
|
replaceUsername: async function (idapp, search_username, replace_username) {
|
||||||
|
|
||||||
|
if (!search_username || !replace_username) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let ris = null;
|
let ris = null;
|
||||||
console.log('replaceUsername = ', search_username, replace_username);
|
console.log('replaceUsername = ', search_username, replace_username);
|
||||||
@@ -447,6 +451,10 @@ module.exports = {
|
|||||||
ris = await User.findOneAndUpdate({ idapp, username: search_username }, { $set: { username: replace_username } });
|
ris = await User.findOneAndUpdate({ idapp, username: search_username }, { $set: { username: replace_username } });
|
||||||
console.log('username result = ', ris);
|
console.log('username result = ', ris);
|
||||||
|
|
||||||
|
tools.move(server_constants.DIR_UPLOAD + 'profile/' + search_username, server_constants.DIR_UPLOAD + 'profile/' + replace_username, function callback() {
|
||||||
|
console.log(' ... moved dir', server_constants.DIR_UPLOAD + 'profile/' + search_username, server_constants.DIR_UPLOAD + 'profile/' + replace_username);
|
||||||
|
});
|
||||||
|
|
||||||
ris = await User.findOneAndUpdate({ idapp, 'profile.username_telegram': search_username }, { $set: { 'profile.username_telegram': replace_username } });
|
ris = await User.findOneAndUpdate({ idapp, 'profile.username_telegram': search_username }, { $set: { 'profile.username_telegram': replace_username } });
|
||||||
console.log('profile.username_telegram result = ', ris);
|
console.log('profile.username_telegram result = ', ris);
|
||||||
|
|
||||||
|
|||||||
@@ -501,4 +501,9 @@ module.exports = {
|
|||||||
FASE3_MONETA_ABILITATA: 3,
|
FASE3_MONETA_ABILITATA: 3,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
CIRCUIT_PARAMS: {
|
||||||
|
SCOPERTO_MIN_GRP: 200,
|
||||||
|
SCOPERTO_MAX_GRP: 500,
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user