go on Conto Comunitario
This commit is contained in:
@@ -195,7 +195,7 @@ AccountSchema.pre('save', async function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, groupname = '') {
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, groupname = '', iscontocom = false) {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
@@ -235,6 +235,10 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
qta_maxConcessa: 0,
|
||||
});
|
||||
|
||||
if (iscontocom) {
|
||||
myaccount.fidoConcesso = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_CONTO_COMUNITARIO;
|
||||
myaccount.qta_maxConcessa = 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;
|
||||
if (!mycircuit.qta_max_default_grp)
|
||||
@@ -247,6 +251,8 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
myaccount.fidoConcesso = mycircuit.fido_scoperto_default;
|
||||
myaccount.qta_maxConcessa = mycircuit.qta_max_default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return await myaccount.save();
|
||||
}
|
||||
@@ -268,7 +274,7 @@ AccountSchema.statics.createAccount = async function (idapp, username, circuitNa
|
||||
try {
|
||||
mycircuit = await Circuit.findOne({ name: circuitName }, { _id: 1 });
|
||||
if (mycircuit) {
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, groupname);
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, groupname, circuitName === groupname);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2348,7 +2348,14 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
let groupname = extrarec && extrarec.groupname ? extrarec.groupname : '';
|
||||
|
||||
try {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.CREATE) {
|
||||
const mycirc = await Circuit.findOne({ idapp, name: circuitname });
|
||||
if (mycirc) {
|
||||
// Il Conto Comunitario prende il nome del circuito !
|
||||
await Account.createAccount(idapp, '', circuitname, mycirc.path);
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
if (groupname) {
|
||||
const foundIfCircuitInGroup = await MyGroup.ifCircuitAlreadyInGroup(idapp, groupname, circuitname);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ const mongoose = require('mongoose').set('debug', false);
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { Circuit } = require('../models/circuit');
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
@@ -70,6 +71,10 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
data.movements = await Movement.getMovsByCircuitId(idapp, usernameOrig, data._id);
|
||||
}
|
||||
|
||||
if (data) {
|
||||
data.account = await Account.getAccountByUsernameAndCircuitId(idapp, '', data._id, false, data.path);
|
||||
}
|
||||
|
||||
res.send({ circuit: data, users_in_circuit });
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -469,7 +469,12 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
return res.send({ rec: myrec, ris });
|
||||
});
|
||||
} else if (params.table === shared_consts.TAB_MYCIRCUITS && isnewrec) {
|
||||
// nuovo Record:
|
||||
// nuovo Circuito:
|
||||
await User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
|
||||
shared_consts.CIRCUITCMD.CREATE, true, req.user.username, extrarec).then((ris) => {
|
||||
return res.send({ rec: myrec, ris });
|
||||
});
|
||||
|
||||
// aggiungi il creatore al Circuito stesso
|
||||
return await User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
|
||||
shared_consts.CIRCUITCMD.SET, true, req.user.username, extrarec).then((ris) => {
|
||||
|
||||
@@ -38,6 +38,7 @@ const TypedError = require('../modules/ErrorHandler');
|
||||
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
const { Circuit } = require('../models/circuit');
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
|
||||
@@ -1090,6 +1091,16 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
|
||||
ris = populate.rewriteTable('contribtypes');
|
||||
|
||||
} else if (mydata.dbop === 'CreateAccountCircuits') {
|
||||
|
||||
const allcirc = await Circuit.find({ idapp });
|
||||
|
||||
for (const mycirc of allcirc) {
|
||||
// Il Conto Comunitario prende il nome del circuito !
|
||||
await Account.createAccount(idapp, '', mycirc.name, mycirc.path);
|
||||
|
||||
}
|
||||
|
||||
} else if (mydata.dbop === 'ReplaceUsername') {
|
||||
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
|
||||
@@ -72,6 +72,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
CIRCUITCMD: {
|
||||
CREATE: 1001,
|
||||
REQ: 2000,
|
||||
SET: 2001,
|
||||
REMOVE_FROM_MYLIST: 2144,
|
||||
@@ -513,6 +514,8 @@ module.exports = {
|
||||
CIRCUIT_PARAMS: {
|
||||
SCOPERTO_MIN_GRP: 200,
|
||||
SCOPERTO_MAX_GRP: 500,
|
||||
SCOPERTO_MIN_CONTO_COMUNITARIO: 1000,
|
||||
SCOPERTO_MAX_CONTO_COMUNITARIO: 1000,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user