Send Coins
This commit is contained in:
@@ -47,9 +47,12 @@
|
|||||||
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Circuito %s (da parte di %s)",
|
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Circuito %s (da parte di %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.",
|
||||||
"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_REFUSED_TO_ME": "All'utente %s gli è stato rifiutato l'accesso a far parte 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.",
|
"CIRCUIT_SENDCOINSREQ": "%s ti sta inviando %s %s.",
|
||||||
"ID_CIRCUIT_COINS_ACCEPTED": "%s %s accettati da %s."
|
"ID_CIRCUIT_COINS_ACCEPTED": "%s %s accettati da %s.",
|
||||||
|
"CIRCUIT_AMOUNT_EXCEED_FIDO": "L'importo supera la quantità massima concessa",
|
||||||
|
"CIRCUIT_AMOUNT_EXCEED_QTAMAX": "L'importo supera la quantità massima che il destinatario può accumulare"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ 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;
|
||||||
|
|
||||||
@@ -114,6 +113,78 @@ AccountSchema.statics.getAccountsByUsername = async function(idapp, username) {
|
|||||||
return await Account.find(myquery).lean();
|
return await Account.find(myquery).lean();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 await myaccount.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, username, {circuitId, circuitName}, createifnotexist) {
|
||||||
|
const Account = this;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const {Circuit} = require('../models/circuit');
|
||||||
|
|
||||||
|
if (username === undefined)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let myquery = {
|
||||||
|
'idapp': idapp,
|
||||||
|
'username': username,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (circuitId) {
|
||||||
|
myquery.circuitId = circuitId;
|
||||||
|
}
|
||||||
|
if (circuitName) {
|
||||||
|
myquery.circuitName = circuitName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mycircuit = await Circuit.getCircuitById(circuitId);
|
||||||
|
|
||||||
|
let myaccount = await Account.findOne(myquery).lean();
|
||||||
|
|
||||||
|
if (!myaccount && createifnotexist) {
|
||||||
|
myaccount = new Account({
|
||||||
|
idapp,
|
||||||
|
username,
|
||||||
|
circuitId: mycircuit._id,
|
||||||
|
deperibile: false,
|
||||||
|
fidoConcesso: mycircuit.fido_scoperto_default,
|
||||||
|
qta_maxConcessa: mycircuit.qta_max_default,
|
||||||
|
importo_iniziale: 0,
|
||||||
|
saldo: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
return await myaccount.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return myaccount;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('error', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
AccountSchema.statics.createAccount = async function(idapp, username, circuitName) {
|
||||||
|
|
||||||
|
return await Account.getAccountByUsernameAndCircuitId(idapp, username, {circuitName}, true);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
AccountSchema.statics.getUserAccounts = async function(idapp, username) {
|
AccountSchema.statics.getUserAccounts = async function(idapp, username) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -129,29 +200,7 @@ AccountSchema.statics.getUserAccounts = async function(idapp, username) {
|
|||||||
as: 'circuit',
|
as: 'circuit',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{$unwind: '$circuit'},
|
||||||
'$replaceRoot': {
|
|
||||||
'newRoot': {
|
|
||||||
'$mergeObjects': [
|
|
||||||
{
|
|
||||||
'$arrayElemAt': [
|
|
||||||
'$circuit',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'$$ROOT',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
$project: {
|
|
||||||
"circuit.name": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
*/
|
|
||||||
];
|
];
|
||||||
|
|
||||||
ris = await this.aggregate(aggr1);
|
ris = await this.aggregate(aggr1);
|
||||||
@@ -163,61 +212,6 @@ AccountSchema.statics.getUserAccounts = async function(idapp, username) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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 await myaccount.save();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, username, circuitId, createifnotexist) {
|
|
||||||
const Account = this;
|
|
||||||
|
|
||||||
const {Circuit} = require('../models/circuit');
|
|
||||||
|
|
||||||
if (username === undefined)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const myquery = {
|
|
||||||
'idapp': idapp,
|
|
||||||
'username': username,
|
|
||||||
circuitId,
|
|
||||||
};
|
|
||||||
|
|
||||||
const mycircuit = await Circuit.getCircuitById(circuitId);
|
|
||||||
|
|
||||||
let myaccount = await Account.findOne(myquery).lean();
|
|
||||||
|
|
||||||
if (!myaccount && createifnotexist) {
|
|
||||||
myaccount = new Account({
|
|
||||||
idapp,
|
|
||||||
username,
|
|
||||||
circuitId,
|
|
||||||
deperibile: false,
|
|
||||||
fidoConcesso: mycircuit.fido_scoperto_default,
|
|
||||||
qta_maxConcessa: mycircuit.qta_max_default,
|
|
||||||
importo_iniziale: 0,
|
|
||||||
saldo: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
return await myaccount.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return myaccount;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const Account = mongoose.model('Account', AccountSchema);
|
const Account = mongoose.model('Account', AccountSchema);
|
||||||
|
|
||||||
module.exports = {Account};
|
module.exports = {Account};
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ const tools = require('../tools/general');
|
|||||||
|
|
||||||
const {ObjectID} = require('mongodb');
|
const {ObjectID} = require('mongodb');
|
||||||
|
|
||||||
|
const i18n = require('i18n');
|
||||||
|
|
||||||
// Resolving error Unknown modifier: $pushAll
|
// Resolving error Unknown modifier: $pushAll
|
||||||
mongoose.plugin(schema => {
|
mongoose.plugin(schema => {
|
||||||
schema.options.usePushEach = true;
|
schema.options.usePushEach = true;
|
||||||
@@ -60,6 +62,10 @@ const CircuitSchema = new Schema({
|
|||||||
symbol: {
|
symbol: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 7,
|
maxlength: 7,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: String,
|
||||||
},
|
},
|
||||||
abbrev: {
|
abbrev: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -204,7 +210,6 @@ CircuitSchema.statics.executeQueryTable = function(idapp, params) {
|
|||||||
CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
||||||
// FOR ME, PERMIT ALL
|
// FOR ME, PERMIT ALL
|
||||||
return {
|
return {
|
||||||
Num: 1,
|
|
||||||
circuitId: 1,
|
circuitId: 1,
|
||||||
groupnameId: 1,
|
groupnameId: 1,
|
||||||
path: 1,
|
path: 1,
|
||||||
@@ -217,7 +222,10 @@ CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
|||||||
date_created: 1,
|
date_created: 1,
|
||||||
date_updated: 1,
|
date_updated: 1,
|
||||||
nome_valuta: 1,
|
nome_valuta: 1,
|
||||||
|
fido_scoperto_default: 1,
|
||||||
|
qta_max_default: 1,
|
||||||
symbol: 1,
|
symbol: 1,
|
||||||
|
color: 1,
|
||||||
abbrev: 1,
|
abbrev: 1,
|
||||||
data_costituz: 1,
|
data_costituz: 1,
|
||||||
photos: 1,
|
photos: 1,
|
||||||
@@ -237,7 +245,6 @@ CircuitSchema.statics.removeAdminOfMyCircuit = async function(idapp, username, n
|
|||||||
|
|
||||||
CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||||
return {
|
return {
|
||||||
Num: 1,
|
|
||||||
circuitId: 1,
|
circuitId: 1,
|
||||||
groupnameId: 1,
|
groupnameId: 1,
|
||||||
path: 1,
|
path: 1,
|
||||||
@@ -248,7 +255,10 @@ CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
|||||||
systemUserId: 1,
|
systemUserId: 1,
|
||||||
founderUserId: 1,
|
founderUserId: 1,
|
||||||
nome_valuta: 1,
|
nome_valuta: 1,
|
||||||
|
fido_scoperto_default: 1,
|
||||||
|
qta_max_default: 1,
|
||||||
symbol: 1,
|
symbol: 1,
|
||||||
|
color: 1,
|
||||||
abbrev: 1,
|
abbrev: 1,
|
||||||
data_costituz: 1,
|
data_costituz: 1,
|
||||||
photos: 1,
|
photos: 1,
|
||||||
@@ -371,7 +381,7 @@ CircuitSchema.statics.getCircuitByName = async function(idapp, name) {
|
|||||||
CircuitSchema.statics.getCircuitById = async function(circuitId) {
|
CircuitSchema.statics.getCircuitById = async function(circuitId) {
|
||||||
|
|
||||||
const myfind = {
|
const myfind = {
|
||||||
circuitId
|
circuitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -388,23 +398,100 @@ CircuitSchema.statics.deleteCircuit = async function(idapp, usernameOrig, name)
|
|||||||
return await Circuit.findOneAndRemove({idapp, name});
|
return await Circuit.findOneAndRemove({idapp, name});
|
||||||
};
|
};
|
||||||
|
|
||||||
CircuitSchema.statics.sendCoins = async function(idapp, usernameOrig, extrarec) {
|
CircuitSchema.statics.getUserCircuits = async function(idapp, username) {
|
||||||
console.log('Aggiungi Monete');
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig, extrarec) {
|
||||||
|
|
||||||
const {Movement} = require('../models/movement');
|
const {Movement} = require('../models/movement');
|
||||||
const {Account} = require('../models/account');
|
const {Account} = require('../models/account');
|
||||||
|
|
||||||
|
let ris = {
|
||||||
|
cansend: true,
|
||||||
|
errormsg: '',
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const reccircuit = await Circuit.getCircuitByName(idapp, extrarec.circuitname);
|
let reccircuit = null;
|
||||||
|
if (extrarec.circuitname)
|
||||||
|
reccircuit = await Circuit.getCircuitByName(idapp, extrarec.circuitname);
|
||||||
|
if (extrarec.circuitId)
|
||||||
|
reccircuit = await Circuit.getCircuitById(idapp, extrarec.circuitId);
|
||||||
|
|
||||||
if (reccircuit) {
|
if (reccircuit) {
|
||||||
const myqty = extrarec.qty;
|
const myqty = extrarec.qty;
|
||||||
|
|
||||||
const accountdest = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, reccircuit._id, true);
|
const accountdest = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, { circuitId: reccircuit._id }, true);
|
||||||
const accountorig = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, reccircuit._id, true);
|
const accountorig = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, { circuitId: reccircuit._id }, true);
|
||||||
|
|
||||||
|
// Check if Sender has enough money
|
||||||
|
if (accountorig.saldo - myqty < accountorig.fidoConcesso) {
|
||||||
|
ris.cansend = false;
|
||||||
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO');
|
||||||
|
}
|
||||||
|
if (accountdest.saldo + myqty > accountorig.qta_maxConcessa) {
|
||||||
|
ris.cansend = false;
|
||||||
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!onlycheck) {
|
||||||
// Add a Transaction !
|
// Add a Transaction !
|
||||||
return await Movement.addMov(idapp, accountorig, accountdest, myqty, extrarec.causal);
|
ris.cansend = await Movement.addMov(idapp, accountorig, accountdest, myqty, extrarec.causal);
|
||||||
|
|
||||||
|
if (ris.cansend) {
|
||||||
|
console.log('Invia Monete da', usernameOrig, extrarec.dest, extrarec.qty, extrarec.causal);
|
||||||
|
} else {
|
||||||
|
console.log('NON Inviate Monete da', usernameOrig, extrarec.dest, extrarec.qty, extrarec.causal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ris;
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -118,11 +118,14 @@ MovementSchema.statics.addMov = async function(idapp, accountFromId, accountToId
|
|||||||
|
|
||||||
MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username, circuitId) {
|
MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username, circuitId) {
|
||||||
|
|
||||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false);
|
try {
|
||||||
|
if (!circuitId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, {circuitId}, false);
|
||||||
|
|
||||||
if (myaccount) {
|
if (myaccount) {
|
||||||
|
|
||||||
try {
|
|
||||||
let aggr1 = [
|
let aggr1 = [
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
@@ -173,6 +176,28 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username,
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{$unwind: '$accto'},
|
{$unwind: '$accto'},
|
||||||
|
{
|
||||||
|
"$lookup": {
|
||||||
|
"from": "circuits",
|
||||||
|
"localField": "accfrom.circuitId",
|
||||||
|
"foreignField": "_id",
|
||||||
|
"as": "circuitfrom"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$unwind": "$circuitfrom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$lookup": {
|
||||||
|
"from": "circuits",
|
||||||
|
"localField": "accto.circuitId",
|
||||||
|
"foreignField": "_id",
|
||||||
|
"as": "circuitto"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$unwind": "$circuitto"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'users',
|
from: 'users',
|
||||||
@@ -202,6 +227,8 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username,
|
|||||||
transactionDate: 1,
|
transactionDate: 1,
|
||||||
amount: 1,
|
amount: 1,
|
||||||
causal: 1,
|
causal: 1,
|
||||||
|
'circuitfrom.symbol': 1,
|
||||||
|
'circuitto.symbol': 1,
|
||||||
'userfrom.username': 1,
|
'userfrom.username': 1,
|
||||||
'userfrom.profile.img': 1,
|
'userfrom.profile.img': 1,
|
||||||
'userto.username': 1,
|
'userto.username': 1,
|
||||||
@@ -212,10 +239,10 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username,
|
|||||||
];
|
];
|
||||||
|
|
||||||
return aggr1;
|
return aggr1;
|
||||||
} catch (e) {
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
@@ -226,7 +253,7 @@ MovementSchema.statics.getMovsByCircuitId = async function(idapp, username, circ
|
|||||||
|
|
||||||
const myquery = await MyMovement.getQueryMovsByCircuitId(idapp, username, circuitId);
|
const myquery = await MyMovement.getQueryMovsByCircuitId(idapp, username, circuitId);
|
||||||
|
|
||||||
if (myquery) {
|
if (myquery && myquery.length > 0) {
|
||||||
ris = await MyMovement.aggregate(myquery);
|
ris = await MyMovement.aggregate(myquery);
|
||||||
|
|
||||||
return ris;
|
return ris;
|
||||||
|
|||||||
@@ -279,7 +279,11 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
|||||||
|
|
||||||
tag = 'remcircuit';
|
tag = 'remcircuit';
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED) {
|
||||||
newdescr = i18n.__('CIRCUIT_REFUSED', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
if (recnotif.paramsObj.isAdmin) {
|
||||||
|
newdescr = i18n.__('CIRCUIT_REFUSED_TO_ME', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||||
|
} else {
|
||||||
|
newdescr = i18n.__('CIRCUIT_REFUSED', recnotif.paramsObj.username_action, recnotif.paramsObj.circuitnameDest);
|
||||||
|
}
|
||||||
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) {
|
||||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.singleadmin_username);
|
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.singleadmin_username);
|
||||||
|
|||||||
@@ -2134,6 +2134,8 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
ris = await Circuit.updateOne({idapp, name: circuitname}, update);
|
ris = await Circuit.updateOne({idapp, name: circuitname}, update);
|
||||||
|
|
||||||
|
await Account.createAccount(idapp, usernameOrig, circuitname);
|
||||||
}
|
}
|
||||||
if (ris) {
|
if (ris) {
|
||||||
// Invia una notifica alla persona
|
// Invia una notifica alla persona
|
||||||
@@ -2178,10 +2180,15 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||||
|
|
||||||
|
ris = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
ris = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
ris = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
ris = await Circuit.refuseReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
ris = await Circuit.refuseReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
|
// Invia una notifica alla persona
|
||||||
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||||
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
|
||||||
|
|
||||||
@@ -2195,14 +2202,22 @@ w
|
|||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
|
||||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||||
// Invia una notifica di moneta alla persona
|
|
||||||
ris = 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);
|
|
||||||
|
|
||||||
|
let ris = await Circuit.sendCoins(true, idapp, usernameOrig, extrarec);
|
||||||
|
if (ris.cansend) {
|
||||||
// Invia una notifica di moneta alla persona
|
// Invia una notifica di moneta 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);
|
||||||
|
} else {
|
||||||
|
ris.cansend = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
||||||
|
ris = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
|
||||||
|
|
||||||
|
if (ris.cansend) {
|
||||||
|
// Invia una notifica di moneta alla persona
|
||||||
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ router.post('/load', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
data = await getCircuitRecAdminsInfo(idapp, data);
|
data = await getCircuitRecAdminsInfo(idapp, data);
|
||||||
|
|
||||||
|
if (data) {
|
||||||
data.movements = await Movement.getMovsByCircuitId(idapp, usernameOrig, data._id);
|
data.movements = await Movement.getMovsByCircuitId(idapp, usernameOrig, data._id);
|
||||||
|
}
|
||||||
|
|
||||||
res.send({circuit: data, users_in_circuit});
|
res.send({circuit: data, users_in_circuit});
|
||||||
|
|
||||||
|
|||||||
@@ -337,6 +337,10 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
if (alreadyexist) {
|
if (alreadyexist) {
|
||||||
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME});
|
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME});
|
||||||
}
|
}
|
||||||
|
alreadyexist = await Circuit.findOne({idapp, symbol: mydata.symbol});
|
||||||
|
if (alreadyexist) {
|
||||||
|
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_SYMBOL});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(params.table)) {
|
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(params.table)) {
|
||||||
|
|||||||
@@ -3929,7 +3929,7 @@ if (true) {
|
|||||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
||||||
|
|
||||||
if (group) {
|
if (group) {
|
||||||
cmd = shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUP;
|
cmd = shared_consts.GROUPSCMD.REFUSE_REQ_GROUP;
|
||||||
const foundIfAlreadyGroup = await User.ifAlreadyInGroup(user.idapp, data.username, group.groupname);
|
const foundIfAlreadyGroup = await User.ifAlreadyInGroup(user.idapp, data.username, group.groupname);
|
||||||
|
|
||||||
if (foundIfAlreadyGroup) {
|
if (foundIfAlreadyGroup) {
|
||||||
@@ -3953,7 +3953,7 @@ if (true) {
|
|||||||
} 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.REMOVE_FROM_MYLIST;
|
cmd = shared_consts.CIRCUITCMD.REFUSE_REQ;
|
||||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||||
|
|
||||||
if (foundIfAlreadyCircuit) {
|
if (foundIfAlreadyCircuit) {
|
||||||
|
|||||||
@@ -1911,6 +1911,19 @@ module.exports = {
|
|||||||
|
|
||||||
query.push(...myquery);
|
query.push(...myquery);
|
||||||
|
|
||||||
|
/*} else if (params.table === 'circuits') {
|
||||||
|
const qacirc = this.getLookup(
|
||||||
|
{
|
||||||
|
lk_tab: 'accounts',
|
||||||
|
lk_LF: 'circuitId',
|
||||||
|
lk_FF: '_id',
|
||||||
|
lk_as: 'account',
|
||||||
|
}, 0, {
|
||||||
|
'acc': 1,
|
||||||
|
});
|
||||||
|
if (qacirc) query = [...query, ...qacirc];
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newvers) {
|
if (newvers) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module.exports = Object.freeze({
|
|||||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||||
RIS_CODE_EMAIL_VERIFIED: 1,
|
RIS_CODE_EMAIL_VERIFIED: 1,
|
||||||
|
|
||||||
|
RIS_CODE_REC_ALREADY_EXIST_SYMBOL: -102,
|
||||||
RIS_CODE_REC_ALREADY_EXIST_CODE: -101,
|
RIS_CODE_REC_ALREADY_EXIST_CODE: -101,
|
||||||
RIS_CODE_REC_ALREADY_EXIST_NAME: -100,
|
RIS_CODE_REC_ALREADY_EXIST_NAME: -100,
|
||||||
RIS_CODE_USER_APORTADOR_NOT_VALID: -75,
|
RIS_CODE_USER_APORTADOR_NOT_VALID: -75,
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ 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_NUM_AS_ID_NUMBER: [ ],
|
||||||
|
|
||||||
TABLES_ID_NUMBER: [
|
TABLES_ID_NUMBER: [
|
||||||
'permissions',
|
'permissions',
|
||||||
@@ -156,6 +156,7 @@ module.exports = {
|
|||||||
'myhosps',
|
'myhosps',
|
||||||
'mygoods',
|
'mygoods',
|
||||||
'mygroups',
|
'mygroups',
|
||||||
|
'circuits',
|
||||||
'movements'],
|
'movements'],
|
||||||
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||||
TABLES_CREATEDBY: ['mygroups', 'circuits'],
|
TABLES_CREATEDBY: ['mygroups', 'circuits'],
|
||||||
|
|||||||
Reference in New Issue
Block a user