- L'utente entra direttamente sul circuito, con fido a zero.
++Abilitazione Fido utente (per admin).
This commit is contained in:
@@ -56,12 +56,15 @@ const AccountSchema = new Schema({
|
||||
},
|
||||
importo_iniziale: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
saldo: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
totTransato: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
regulation_ok: {
|
||||
type: Boolean,
|
||||
@@ -202,7 +205,7 @@ AccountSchema.pre('save', async function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, groupname = '', contocom = "") {
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, confido, groupname = '', contocom = "") {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
@@ -263,6 +266,9 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
}
|
||||
}
|
||||
|
||||
if (!confido) {
|
||||
myaccount.fidoConcesso = 0;
|
||||
}
|
||||
|
||||
return await myaccount.save();
|
||||
}
|
||||
@@ -277,14 +283,52 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, 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;
|
||||
|
||||
let myquery = {
|
||||
idapp,
|
||||
circuitId,
|
||||
};
|
||||
|
||||
if (groupname) {
|
||||
myquery.groupname = groupname;
|
||||
} else if (contocom) {
|
||||
myquery.contocom = contocom;
|
||||
} else {
|
||||
myquery.username = username;
|
||||
}
|
||||
|
||||
let mycircuit = await Circuit.getCircuitById(circuitId);
|
||||
|
||||
if (mycircuit) {
|
||||
let myaccount = await Account.findOne(myquery);
|
||||
return !!myaccount
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
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, groupname, contocom);
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, confido, groupname, contocom);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -337,6 +381,11 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
},
|
||||
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -349,8 +398,9 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
if (ris) {
|
||||
for (const account of ris) {
|
||||
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.result.extrarec.qty, 0);
|
||||
account.saldo -= saldopending;
|
||||
account.totTransato = account.totTransato || 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,6 +453,10 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -415,7 +469,7 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
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);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.result.extrarec.qty, 0);
|
||||
account.saldo -= saldopending;
|
||||
}
|
||||
}
|
||||
@@ -472,6 +526,16 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateFido = async function (idapp, username, circuitId, fido) {
|
||||
|
||||
let paramstoupdate = {
|
||||
fidoConcesso: fido,
|
||||
};
|
||||
const risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
|
||||
return risult;
|
||||
};
|
||||
|
||||
AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
|
||||
return await Account.updateOne({ idapp, username, circuitId },
|
||||
|
||||
Reference in New Issue
Block a user