- Il circuito viene creato in automatico, quando scegli una provincia.
This commit is contained in:
@@ -11,6 +11,9 @@ const { ObjectID } = require('mongodb');
|
||||
const { Movement } = require('../models/movement');
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
const { Province } = require('../models/province');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const i18n = require('i18n');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
@@ -48,9 +51,9 @@ const CircuitSchema = new Schema({
|
||||
type: Number,
|
||||
}],
|
||||
strProv:
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
@@ -461,6 +464,22 @@ CircuitSchema.statics.getCircuitByName = async function (idapp, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitByProvince = async function (idapp, strProv) {
|
||||
|
||||
const myfind = {
|
||||
idapp,
|
||||
strProv,
|
||||
};
|
||||
|
||||
try {
|
||||
return await Circuit.findOne(myfind);
|
||||
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitById = async function (circuitId) {
|
||||
|
||||
const myfind = {
|
||||
@@ -894,6 +913,66 @@ CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, val
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, province) {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
let myrec = null;
|
||||
try {
|
||||
const circuit = await this.getCircuitByProvince(idapp, province);
|
||||
|
||||
const nomeprovincia = await Province.getStrProvinceByProv(province);
|
||||
|
||||
if (!circuit && nomeprovincia) {
|
||||
const circ = new Circuit({
|
||||
idapp,
|
||||
name: 'RIS ' + nomeprovincia,
|
||||
path: 'ris' + tools.convertSpaces_ToUScore(nomeprovincia.toLowerCase()),
|
||||
strProv: province,
|
||||
photos: [],
|
||||
admins: [],
|
||||
color: '#ff5500',
|
||||
deperimento: false,
|
||||
transactionsEnabled: false,
|
||||
status: shared_consts.CIRCUIT_STATUS.FASE1_CREAZIONE_GRUPPO,
|
||||
symbol: 'RIS',
|
||||
fido_scoperto_default: 100,
|
||||
qta_max_default: 200,
|
||||
fido_scoperto_default_grp: shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_GRP,
|
||||
qta_max_default_grp: shared_consts.CIRCUIT_PARAMS.SCOPERTO_MAX_GRP,
|
||||
valuta_per_euro: 1,
|
||||
totTransato: 0,
|
||||
totCircolante: 0,
|
||||
date_created: new Date(),
|
||||
});
|
||||
|
||||
myrec = await circ.save();
|
||||
|
||||
if (myrec) {
|
||||
|
||||
// nuovo Circuito:
|
||||
await User.setCircuitCmd(idapp, tools.USER_ADMIN_CIRCUITS, myrec.name,
|
||||
shared_consts.CIRCUITCMD.CREATE, true, tools.USER_ADMIN_CIRCUITS, myrec).then((ris) => {
|
||||
|
||||
});
|
||||
|
||||
// aggiungi il creatore al Circuito stesso
|
||||
await User.setCircuitCmd(idapp, tools.USER_ADMIN_CIRCUITS, myrec.name,
|
||||
shared_consts.CIRCUITCMD.SET, true, tools.USER_ADMIN_CIRCUITS, myrec).then((ris) => {
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
msg = 'Nuovo Circuito Creato in Automatico: ' + myrec.name + ' (da ' + req.user.username + ')';
|
||||
tools.sendMsgTelegramToAdmin(idapp, msg);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
|
||||
return myrec;
|
||||
|
||||
};
|
||||
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
|
||||
Reference in New Issue
Block a user