- Sistemato problema del Circuito ITALIA, quando veniva fatta la richiesta di entrare, ancora non si era entrati nel circuito territoriale.
- Ora pertanto viene inviata la richiesta agli admin solo dopo che l'utente viene abilitato al Circuito provinciale.
This commit is contained in:
@@ -12,11 +12,10 @@ const tools = require('../tools/general');
|
||||
|
||||
const { ObjectId } = require('mongodb');
|
||||
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
mongoose.plugin((schema) => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
@@ -36,13 +35,16 @@ const AccountSchema = new Schema({
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
groupname: { // For the Groups
|
||||
groupname: {
|
||||
// For the Groups
|
||||
type: String,
|
||||
},
|
||||
contocom: { // For the Conto Comunitario dei Circuiti
|
||||
contocom: {
|
||||
// For the Conto Comunitario dei Circuiti
|
||||
type: String,
|
||||
},
|
||||
circuitId: { // ----- REF TO Circuit
|
||||
circuitId: {
|
||||
// ----- REF TO Circuit
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
@@ -116,7 +118,6 @@ AccountSchema.statics.getFieldsForSearch = function () {
|
||||
{ field: 'groupname', type: tools.FieldType.string },
|
||||
{ field: 'contocom', type: tools.FieldType.string },
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
@@ -127,16 +128,14 @@ AccountSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
AccountSchema.statics.getAccountsByUsername = async function (idapp, username) {
|
||||
const Account = this;
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
if (username === undefined) return false;
|
||||
|
||||
const myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
idapp: idapp,
|
||||
username: username,
|
||||
};
|
||||
|
||||
return await Account.find(myquery).lean();
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.calcTotCircolante = async function (idapp, circuitId) {
|
||||
@@ -147,17 +146,15 @@ AccountSchema.statics.calcTotCircolante = async function (idapp, circuitId) {
|
||||
{
|
||||
$match: { idapp, circuitId, saldo: { $gt: 0 } },
|
||||
},
|
||||
{ $group: { _id: null, count: { $sum: '$saldo' } } }
|
||||
{ $group: { _id: null, count: { $sum: '$saldo' } } },
|
||||
];
|
||||
|
||||
const ris = await Account.aggregate(aggr1);
|
||||
|
||||
return ris ? ris[0].count : 0;
|
||||
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
|
||||
};
|
||||
AccountSchema.methods.calcPending = async function (mittente) {
|
||||
try {
|
||||
@@ -175,7 +172,12 @@ AccountSchema.methods.calcPending = async function (mittente) {
|
||||
let transatopending = 0;
|
||||
|
||||
if (mittente) {
|
||||
let pendingtransactionsMittente = await SendNotif.getSumPendingTransactionsMittente(account.idapp, account.username, circuit.name, account.groupname);
|
||||
let pendingtransactionsMittente = await SendNotif.getSumPendingTransactionsMittente(
|
||||
account.idapp,
|
||||
account.username,
|
||||
circuit.name,
|
||||
account.groupname
|
||||
);
|
||||
let saldopendingMitt = pendingtransactionsMittente.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
transatopending = pendingtransactionsMittente.reduce((sum, rec) => sum + Math.abs(rec.extrarec.qty), 0);
|
||||
|
||||
@@ -192,34 +194,29 @@ AccountSchema.methods.calcPending = async function (mittente) {
|
||||
account.totTransato_pend = account.totTransato + transatopending;
|
||||
|
||||
if (prec_saldo_pend !== account.saldo_pend || prec_totTransato_pend !== account.totTransato_pend) {
|
||||
|
||||
const myaccountupdate = {
|
||||
saldo_pend: account.saldo_pend,
|
||||
totTransato_pend: account.totTransato_pend,
|
||||
};
|
||||
|
||||
// Update Record
|
||||
return await Account.findByIdAndUpdate(account.id,
|
||||
{
|
||||
$set: myaccountupdate
|
||||
}).then((ris) => {
|
||||
return await Account.findByIdAndUpdate(account.id, {
|
||||
$set: myaccountupdate,
|
||||
})
|
||||
.then((ris) => {
|
||||
console.log('calcPending', ris);
|
||||
}).catch((err) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('calcPending', err);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
|
||||
const Account = this;
|
||||
@@ -234,8 +231,7 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
|
||||
}
|
||||
myaccount.totTransato += Math.abs(amount);
|
||||
|
||||
if (!myaccount.numtransactions)
|
||||
myaccount.numtransactions = 0;
|
||||
if (!myaccount.numtransactions) myaccount.numtransactions = 0;
|
||||
myaccount.numtransactions++;
|
||||
|
||||
myaccount.date_updated = new Date();
|
||||
@@ -245,10 +241,12 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
|
||||
myaccountupdate.numtransactions = myaccount.numtransactions;
|
||||
myaccountupdate.date_updated = myaccount.date_updated;
|
||||
|
||||
const ris = await Account.updateOne({ _id: myaccount.id },
|
||||
const ris = await Account.updateOne(
|
||||
{ _id: myaccount.id },
|
||||
{
|
||||
$set: myaccountupdate
|
||||
});
|
||||
$set: myaccountupdate,
|
||||
}
|
||||
);
|
||||
|
||||
// Calcola Saldo Pendente !
|
||||
await myaccount.calcPending(true);
|
||||
@@ -256,7 +254,6 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
|
||||
const recupdated = await Account.findOne({ _id: myaccount.id });
|
||||
|
||||
return recupdated;
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
@@ -267,18 +264,24 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
|
||||
|
||||
AccountSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created) this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, confido, groupname = '', contocom = "") {
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (
|
||||
idapp,
|
||||
username,
|
||||
circuitId,
|
||||
createifnotexist,
|
||||
confido,
|
||||
groupname = '',
|
||||
contocom = ''
|
||||
) {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
// if (username === undefined)
|
||||
@@ -306,7 +309,7 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
myaccount = new Account({
|
||||
_id: new ObjectId().toString(),
|
||||
idapp,
|
||||
username: (!groupname && !contocom) ? username : '',
|
||||
username: !groupname && !contocom ? username : '',
|
||||
groupname,
|
||||
contocom,
|
||||
circuitId: mycircuit._id,
|
||||
@@ -322,9 +325,10 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
});
|
||||
|
||||
if (contocom) {
|
||||
myaccount.fidoConcesso = mycircuit.fido_scoperto_default_contocom || shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_CONTO_COMUNITARIO;
|
||||
myaccount.qta_maxConcessa = mycircuit.qta_max_default_contocom || shared_consts.CIRCUIT_PARAMS.SCOPERTO_MAX_CONTO_COMUNITARIO;
|
||||
|
||||
myaccount.fidoConcesso =
|
||||
mycircuit.fido_scoperto_default_contocom || shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_CONTO_COMUNITARIO;
|
||||
myaccount.qta_maxConcessa =
|
||||
mycircuit.qta_max_default_contocom || shared_consts.CIRCUIT_PARAMS.SCOPERTO_MAX_CONTO_COMUNITARIO;
|
||||
} else {
|
||||
if (!mycircuit.fido_scoperto_default_grp)
|
||||
mycircuit.fido_scoperto_default_grp = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_GRP;
|
||||
@@ -356,22 +360,24 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
return myaccount;
|
||||
}
|
||||
return null;
|
||||
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.isExistAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, groupname = '', contocom = "") {
|
||||
AccountSchema.statics.isExistAccountByUsernameAndCircuitId = async function (
|
||||
idapp,
|
||||
username,
|
||||
circuitId,
|
||||
groupname = '',
|
||||
contocom = ''
|
||||
) {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
if (username === undefined) return false;
|
||||
|
||||
let myquery = {
|
||||
idapp,
|
||||
@@ -390,25 +396,37 @@ AccountSchema.statics.isExistAccountByUsernameAndCircuitId = async function (ida
|
||||
|
||||
if (mycircuit) {
|
||||
let myaccount = await Account.findOne(myquery);
|
||||
return !!myaccount
|
||||
return !!myaccount;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, confido, groupname = '', contocom = '') {
|
||||
|
||||
AccountSchema.statics.createAccount = async function (
|
||||
idapp,
|
||||
username,
|
||||
circuitName,
|
||||
confido,
|
||||
groupname = '',
|
||||
contocom = ''
|
||||
) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
mycircuit = await Circuit.findOne({ name: circuitName }, { _id: 1 });
|
||||
if (mycircuit) {
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, confido, groupname, contocom);
|
||||
return await Account.getAccountByUsernameAndCircuitId(
|
||||
idapp,
|
||||
username,
|
||||
mycircuit._id,
|
||||
true,
|
||||
confido,
|
||||
groupname,
|
||||
contocom
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -416,7 +434,6 @@ AccountSchema.statics.createAccount = async function (idapp, username, circuitNa
|
||||
console.error('error', e);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
@@ -463,10 +480,8 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
$group: { _id: '$extrarec.notifIdToUpdate', result: { $first: '$$ROOT' } },
|
||||
},
|
||||
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -502,11 +517,9 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
} catch (e) {
|
||||
console.error('getUserAccounts', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
|
||||
if (!groupname) {
|
||||
return [];
|
||||
}
|
||||
@@ -551,8 +564,7 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
$group: { _id: '$extrarec.notifIdToUpdate', result: { $first: '$$ROOT' } },
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -565,37 +577,36 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
AccountSchema.statics.SetMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||
const Account = this;
|
||||
|
||||
const ris = await Account.updateMany({ idapp, groupname: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany(
|
||||
{ idapp, groupname: { $nin: [null, ''] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
$set: {
|
||||
fidoConcesso: valmin,
|
||||
qta_maxConcessa: valmax,
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Comunitari, i seguenti minimi e massimi
|
||||
AccountSchema.statics.SetMinMaxComunitari = async function (idapp, valmin, valmax) {
|
||||
const Account = this;
|
||||
|
||||
const ris = await Account.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany(
|
||||
{ idapp, contocom: { $nin: [null, ''] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
$set: {
|
||||
fidoConcesso: valmin,
|
||||
qta_maxConcessa: valmax,
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Personali, i seguenti minimi e massimi
|
||||
@@ -603,76 +614,88 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, fidoConcesso,
|
||||
const Account = this;
|
||||
|
||||
if (circuitId) {
|
||||
const ris = await Account.updateMany({ idapp, circuitId, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany(
|
||||
{ idapp, circuitId, fidoConcesso: { $gt: 0 }, username: { $nin: [null, ''] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
$set: {
|
||||
fidoConcesso,
|
||||
qta_maxConcessa,
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const circuit = await Circuit.findOne({ _id: circuitId });
|
||||
|
||||
if (!circuit.circuitoIndipendente) {
|
||||
// Se aggiorno questi dati, e non è un Circuito Indipendente, allora devo aggiornare anche gli account del RIS Nazionale
|
||||
await Account.updateAccountCircuitoNazionaleByLimiti(idapp, circuitId, fidoConcesso, qta_maxConcessa);
|
||||
await Account.updateAccountCircuitoItaliaByLimiti(idapp, circuitId, fidoConcesso, qta_maxConcessa);
|
||||
}
|
||||
|
||||
} else {
|
||||
const ris = await Account.updateMany({ idapp, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany(
|
||||
{ idapp, fidoConcesso: { $gt: 0 }, username: { $nin: [null, ''] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
$set: {
|
||||
fidoConcesso,
|
||||
qta_maxConcessa,
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateFido = async function (idapp, username, groupname, circuitId, fido) {
|
||||
|
||||
let paramstoupdate = {
|
||||
fidoConcesso: fido,
|
||||
};
|
||||
let risult = null;
|
||||
if (groupname)
|
||||
risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
|
||||
else
|
||||
risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
if (groupname) risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
|
||||
else risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
|
||||
return risult;
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateQtaMax = async function (idapp, username, groupname, circuitId, qtamax) {
|
||||
|
||||
let paramstoupdate = {
|
||||
qta_maxConcessa: qtamax,
|
||||
};
|
||||
let risult = null;
|
||||
if (groupname)
|
||||
risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
|
||||
else
|
||||
risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
if (groupname) risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
|
||||
else risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
|
||||
return risult && risult.modifiedCount > 0;
|
||||
};
|
||||
|
||||
AccountSchema.statics.getAccountsCircuitiNazionali = async function (idapp) {
|
||||
AccountSchema.statics.getAccountsCircuitiExtraProvinciali = async function (idapp) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const circuit = await Circuit.find({ idapp, showAlways: true });
|
||||
const circuits = await Circuit.getCircuitiExtraProvinciali(idapp);
|
||||
|
||||
return Account.find({ idapp, circuitId: circuit.id });
|
||||
if (circuits.length > 0) {
|
||||
const circuitIds = circuits.map((circuit) => circuit._id);
|
||||
return Account.find({ idapp, circuitId: { $in: circuitIds } });
|
||||
}
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateAccountCircuitoNazionaleByLimiti = async function (idapp, circuitId, fidoConcesso, qta_maxConcessa) {
|
||||
AccountSchema.statics.getAccountsCircuitoItalia = async function (idapp) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const circuit = await Circuit.getCircuitoItalia(idapp);
|
||||
|
||||
if (circuit) {
|
||||
return Account.find({ idapp, circuitId: circuit._id });
|
||||
}
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateAccountCircuitoItaliaByLimiti = async function (
|
||||
idapp,
|
||||
circuitId,
|
||||
fidoConcesso,
|
||||
qta_maxConcessa
|
||||
) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
const accounts = await this.getAccountsCircuitiNazionali(idapp);
|
||||
const accounts = await this.getAccountsCircuitoItalia(idapp);
|
||||
|
||||
for (const account of accounts) {
|
||||
const circuitId = account.circuitId;
|
||||
@@ -699,11 +722,10 @@ AccountSchema.statics.updateAccountCircuitoNazionaleByLimiti = async function (i
|
||||
}
|
||||
return risult;
|
||||
} catch (e) {
|
||||
console.error('updateAccountCircuitoNazionaleByLimiti', e);
|
||||
console.error('updateAccountCircuitoItaliaByLimiti', e);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.canEditAccountAdmins = async function (username, id) {
|
||||
@@ -721,49 +743,49 @@ AccountSchema.statics.canEditAccountAdmins = async function (username, id) {
|
||||
};
|
||||
|
||||
AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
|
||||
return await Account.updateOne({ idapp, username, circuitId },
|
||||
return await Account.updateOne(
|
||||
{ idapp, username, circuitId },
|
||||
{
|
||||
$push:
|
||||
{
|
||||
$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) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
return await Circuit.updateOne({ idapp, username, circuitId },
|
||||
{ $pull: { people: { username: { $in: [person_username] } } } });
|
||||
return await Circuit.updateOne(
|
||||
{ idapp, username, circuitId },
|
||||
{ $pull: { people: { username: { $in: [person_username] } } } }
|
||||
);
|
||||
};
|
||||
|
||||
// Rimuovi l'account
|
||||
AccountSchema.statics.removeAccount = async function (accountId) {
|
||||
|
||||
return await Account.deleteOne({ _id: accountId });
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateSaldoAndTransato_AllAccounts = async function (idapp) {
|
||||
|
||||
const recaccounts = await Account.find({ idapp });
|
||||
|
||||
for (const account of recaccounts) {
|
||||
await account.calcPending();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const Account = mongoose.model('Account', AccountSchema);
|
||||
|
||||
Account.createIndexes()
|
||||
.then(() => { })
|
||||
.catch((err) => { throw err; });
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
module.exports = { Account };
|
||||
|
||||
Reference in New Issue
Block a user