other fixes
Arcadei
This commit is contained in:
@@ -21,9 +21,9 @@ mongoose.plugin(schema => {
|
||||
const CircuitSchema = new Schema({
|
||||
_id: {
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString()
|
||||
}
|
||||
default: function() {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -181,6 +181,10 @@ const CircuitSchema = new Schema({
|
||||
transactionsEnabled: {
|
||||
type: Boolean,
|
||||
},
|
||||
numMembers: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
status: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -232,6 +236,7 @@ CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
subname: 1,
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
numMembers: 1,
|
||||
totCircolante: 1,
|
||||
totTransato: 1,
|
||||
systemUserId: 1,
|
||||
@@ -292,6 +297,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||
subname: 1,
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
numMembers: 1,
|
||||
systemUserId: 1,
|
||||
founderUserId: 1,
|
||||
nome_valuta: 1,
|
||||
@@ -449,7 +455,8 @@ CircuitSchema.statics.getUserCircuits = async function(idapp, username) {
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {idapp, username,
|
||||
$match: {
|
||||
idapp, username,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
@@ -510,7 +517,6 @@ CircuitSchema.statics.getCircolanteSingolaTransaz = function(accountorigTable, a
|
||||
|
||||
CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig, extrarec) {
|
||||
|
||||
|
||||
let ris = {
|
||||
result: false,
|
||||
cansend: true,
|
||||
@@ -529,8 +535,8 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
if (circuittable) {
|
||||
const myqty = Math.abs(extrarec.qty);
|
||||
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, { circuitId: circuittable._id }, true);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, { circuitId: circuittable._id }, true);
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, {circuitId: circuittable._id}, true);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, {circuitId: circuittable._id}, true);
|
||||
|
||||
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
||||
|
||||
@@ -564,7 +570,7 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
totTransato: circuittable.totTransato,
|
||||
totCircolante: circuittable.totCircolante,
|
||||
};
|
||||
await Circuit.updateOne({_id: circuittable}, { $set: paramstoupdate } );
|
||||
await Circuit.updateOne({_id: circuittable}, {$set: paramstoupdate});
|
||||
|
||||
ris.result = true;
|
||||
console.log('Inviate Monete da', usernameOrig, extrarec.dest, myqty, extrarec.causal);
|
||||
@@ -579,7 +585,6 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ris;
|
||||
|
||||
}
|
||||
@@ -599,6 +604,7 @@ CircuitSchema.statics.removeReqCircuit = async function(idapp, username, name) {
|
||||
};
|
||||
|
||||
// Aggiungi agli utenti Rifiutati del Circuito
|
||||
|
||||
CircuitSchema.statics.refuseReqCircuit = async function(idapp, username, name) {
|
||||
|
||||
return await Circuit.updateOne({idapp, name},
|
||||
@@ -614,6 +620,41 @@ CircuitSchema.statics.refuseReqCircuit = async function(idapp, username, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.updateData = async function(idapp, circuitname) {
|
||||
|
||||
try {
|
||||
|
||||
const {User} = require('./user');
|
||||
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
'profile.mycircuits': {
|
||||
$elemMatch: {circuitname: {$eq: circuitname}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{$group: {_id: null, count: {$sum: 1}}},
|
||||
];
|
||||
|
||||
const ris = await User.aggregate(aggr1);
|
||||
|
||||
let numMembers = ris ? ris[0].count : 0;
|
||||
|
||||
let paramstoupdate = {
|
||||
numMembers: numMembers,
|
||||
};
|
||||
const risult = await this.updateOne({idapp, name: circuitname}, {$set: paramstoupdate});
|
||||
|
||||
console.log('risult', risult)
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||
|
||||
module.exports = {Circuit};
|
||||
|
||||
@@ -113,7 +113,7 @@ MovementSchema.statics.addMov = async function(idapp, accountFromIdTable, accoun
|
||||
// Update saldo dell'Account
|
||||
await Account.addtoSaldo(accountToIdTable, amount);
|
||||
|
||||
await Account.addtoSaldo(accountFromIdTable, amount);
|
||||
await Account.addtoSaldo(accountFromIdTable, -amount);
|
||||
|
||||
return mymov;
|
||||
}
|
||||
|
||||
@@ -2166,9 +2166,12 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
||||
|
||||
await Account.createAccount(idapp, usernameOrig, circuitname);
|
||||
|
||||
|
||||
} 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);
|
||||
@@ -2218,6 +2221,8 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
||||
outres.result = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
console.log('ris', ris);
|
||||
|
||||
await Circuit.updateData(idapp, circuitname);
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
|
||||
@@ -2235,6 +2240,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.CANCEL_REQ) {
|
||||
|
||||
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
await Circuit.updateData(idapp, circuitname)
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ const tools = require('../tools/general');
|
||||
|
||||
const appTelegram = [tools.FREEPLANET, tools.RISO];
|
||||
|
||||
const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM, tools.RISO];
|
||||
const appTelegram_TEST = [tools.FREEPLANET, tools.ARCADEI, tools.RISO];
|
||||
const appTelegram_DEVELOP = [tools.RISO];
|
||||
|
||||
const appTelegramFinti = ['2', tools.CNM];
|
||||
|
||||
@@ -412,7 +412,7 @@ module.exports = {
|
||||
FREEPLANET: '1',
|
||||
AYNI: '7',
|
||||
CNM: '10',
|
||||
PDNM: '12',
|
||||
ARCADEI: '14',
|
||||
RISO: '13',
|
||||
|
||||
HELP_CHAT: '',
|
||||
|
||||
@@ -495,8 +495,10 @@ module.exports = {
|
||||
],
|
||||
|
||||
CIRCUIT_STATUS: {
|
||||
FASE1_CREAZIONE_GRUPPO: 0,
|
||||
FASE2_MONETA_ABILITATA: 1,
|
||||
FASE0: 0,
|
||||
FASE1_CREAZIONE_GRUPPO: 1,
|
||||
FASE2_ORGANIZZAZIONE: 2,
|
||||
FASE3_MONETA_ABILITATA: 3,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user