- 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 { Movement } = require('../models/movement');
|
||||||
const { Account } = require('../models/account');
|
const { Account } = require('../models/account');
|
||||||
|
|
||||||
|
const { Province } = require('../models/province');
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
const i18n = require('i18n');
|
const i18n = require('i18n');
|
||||||
|
|
||||||
// Resolving error Unknown modifier: $pushAll
|
// Resolving error Unknown modifier: $pushAll
|
||||||
@@ -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) {
|
CircuitSchema.statics.getCircuitById = async function (circuitId) {
|
||||||
|
|
||||||
const myfind = {
|
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
|
// 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) {
|
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||||
|
|
||||||
ris = await Circuit.updateMany({ idapp },
|
ris = await Circuit.updateMany({ idapp },
|
||||||
|
|||||||
@@ -46,7 +46,14 @@ ProvinceSchema.statics.getRegionByStrProvince = async function(strprovince) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProvinceSchema.statics.getStrProvinceByProv = async function(prov) {
|
||||||
|
const myrec = await Province.findOne({prov}).lean();
|
||||||
|
if (myrec) {
|
||||||
|
return myrec.descr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
ProvinceSchema.statics.getFieldsForSearch = function() {
|
ProvinceSchema.statics.getFieldsForSearch = function() {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -2357,6 +2357,26 @@ UserSchema.statics.setGroupsCmd = async function (idapp, usernameOrig, groupname
|
|||||||
return ris;
|
return ris;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.updateMyData = async function (outres, idapp, username) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||||
|
const userprofile = await User.getExtraInfoByUsername(idapp, username);
|
||||||
|
if (userprofile) {
|
||||||
|
outres.userprofile = userprofile;
|
||||||
|
}
|
||||||
|
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
||||||
|
outres.mygroups = await MyGroup.findAllGroups(idapp);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('ERR', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return outres;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitname, cmd, value, username_action, extrarec) {
|
UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitname, cmd, value, username_action, extrarec) {
|
||||||
|
|
||||||
// console.log('setCircuitCmd', cmd);
|
// console.log('setCircuitCmd', cmd);
|
||||||
@@ -2657,14 +2677,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ris && username_action) {
|
if (ris && username_action) {
|
||||||
|
outres = await this.updateMyData(outres, idapp, username_action);
|
||||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
|
||||||
const userprofile = await User.getExtraInfoByUsername(idapp, username_action);
|
|
||||||
if (userprofile) {
|
|
||||||
outres.userprofile = userprofile;
|
|
||||||
}
|
|
||||||
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
|
||||||
outres.mygroups = await MyGroup.findAllGroups(idapp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (circuitname)
|
if (circuitname)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ module.exports = {
|
|||||||
{_id: 46, idSector: [7], descr: 'Idraulico'},
|
{_id: 46, idSector: [7], descr: 'Idraulico'},
|
||||||
{_id: 47, idSector: [7], descr: 'Giardiniere'},
|
{_id: 47, idSector: [7], descr: 'Giardiniere'},
|
||||||
{_id: 48, idSector: [7], descr: 'Canne fumarie e camini e stufe'},
|
{_id: 48, idSector: [7], descr: 'Canne fumarie e camini e stufe'},
|
||||||
{_id: 49, idSector: [7], descr: 'Pannelli solari e pompe calore'},
|
{_id: 49, idSector: [7], descr: 'Pannelli solari'},
|
||||||
{_id: 50, idSector: [7], descr: 'Riparazioni varie'},
|
{_id: 50, idSector: [7], descr: 'Riparazioni varie'},
|
||||||
{_id: 51, idSector: [7], descr: 'Tuttofare'},
|
{_id: 51, idSector: [7], descr: 'Tuttofare'},
|
||||||
{_id: 52, idSector: [7], descr: 'Traslochi'},
|
{_id: 52, idSector: [7], descr: 'Traslochi'},
|
||||||
@@ -122,5 +122,7 @@ module.exports = {
|
|||||||
{_id: 127, idSector: [1], descr: 'Stanza in affitto'},
|
{_id: 127, idSector: [1], descr: 'Stanza in affitto'},
|
||||||
{_id: 128, idSector: [1], descr: 'Stanza in condivisione'},
|
{_id: 128, idSector: [1], descr: 'Stanza in condivisione'},
|
||||||
{_id: 129, idSector: [3], descr: 'Home Restaurant'},
|
{_id: 129, idSector: [3], descr: 'Home Restaurant'},
|
||||||
|
{_id: 130, idSector: [7], descr: 'Pompe di calore'},
|
||||||
|
{_id: 131, idSector: [7], descr: 'Impianti Fotovoltaici'},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -919,6 +919,12 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
|
|
||||||
if (mydata.table === 'users') {
|
if (mydata.table === 'users') {
|
||||||
|
|
||||||
|
if ('profile.resid_province' in fieldsvalue) {
|
||||||
|
// Controlla se esiste il Circuito di questa provincia, se non esiste lo crea!
|
||||||
|
await Circuit.createCircuitIfNotExist(req, idapp, fieldsvalue['profile.resid_province']);
|
||||||
|
}
|
||||||
|
|
||||||
if (camporequisiti) {
|
if (camporequisiti) {
|
||||||
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1122,40 +1122,6 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
|
|
||||||
ris = populate.rewriteTable('contribtypes');
|
ris = populate.rewriteTable('contribtypes');
|
||||||
|
|
||||||
} else if (mydata.dbop === 'ImpostaMinMaxPersonali') {
|
|
||||||
|
|
||||||
await Account.SetMinMaxPersonali(idapp, mydata.valmin, mydata.valmax);
|
|
||||||
|
|
||||||
} else if (mydata.dbop === 'ImpostaMinMaxComunitari') {
|
|
||||||
|
|
||||||
await Account.SetMinMaxComunitari(idapp, mydata.valmin, mydata.valmax);
|
|
||||||
|
|
||||||
} else if (mydata.dbop === 'ImpostaMinMaxCollettivi') {
|
|
||||||
|
|
||||||
await Account.SetMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax);
|
|
||||||
|
|
||||||
} else if (mydata.dbop === 'ImpostaDefMinMaxPersonali') {
|
|
||||||
|
|
||||||
await Circuit.SetDefMinMaxPersonali(idapp, mydata.valmin, mydata.valmax);
|
|
||||||
|
|
||||||
} else if (mydata.dbop === 'ImpostaDefMinMaxCollettivi') {
|
|
||||||
|
|
||||||
await Circuit.SetDefMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax);
|
|
||||||
|
|
||||||
} else if (mydata.dbop === 'setstrProvByIdCityCircuits') {
|
|
||||||
|
|
||||||
await Circuit.setstrProvByIdCityCircuits(idapp);
|
|
||||||
|
|
||||||
} 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') {
|
} else if (mydata.dbop === 'ReplaceUsername') {
|
||||||
|
|
||||||
if (User.isAdmin(req.user.perm)) {
|
if (User.isAdmin(req.user.perm)) {
|
||||||
@@ -1240,15 +1206,6 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
|
|
||||||
ris = await populate.popolaTabelleNuove();
|
ris = await populate.popolaTabelleNuove();
|
||||||
|
|
||||||
} else if (mydata.dbop === 'saveStepTut') {
|
|
||||||
await User.findOneAndUpdate({ _id: mydata._id },
|
|
||||||
{ $set: { 'profile.stepTutorial': mydata.value } });
|
|
||||||
} else if (mydata.dbop === 'noNameSurname') {
|
|
||||||
await User.findOneAndUpdate({ _id: mydata._id },
|
|
||||||
{ $set: { 'profile.noNameSurname': mydata.value } });
|
|
||||||
} else if (mydata.dbop === 'noFoto') {
|
|
||||||
await User.findOneAndUpdate({ _id: mydata._id },
|
|
||||||
{ $set: { 'profile.noFoto': mydata.value } });
|
|
||||||
} else if (mydata.dbop === 'ricreaTabCitiesProvinces') {
|
} else if (mydata.dbop === 'ricreaTabCitiesProvinces') {
|
||||||
|
|
||||||
// Svuota e Ricrea
|
// Svuota e Ricrea
|
||||||
@@ -1284,6 +1241,30 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
await City.remove({});
|
await City.remove({});
|
||||||
await Province.remove({});
|
await Province.remove({});
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'ImpostaMinMaxPersonali') {
|
||||||
|
|
||||||
|
await Account.SetMinMaxPersonali(idapp, mydata.valmin, mydata.valmax);
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'ImpostaMinMaxComunitari') {
|
||||||
|
|
||||||
|
await Account.SetMinMaxComunitari(idapp, mydata.valmin, mydata.valmax);
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'ImpostaMinMaxCollettivi') {
|
||||||
|
|
||||||
|
await Account.SetMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax);
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'ImpostaDefMinMaxPersonali') {
|
||||||
|
|
||||||
|
await Circuit.SetDefMinMaxPersonali(idapp, mydata.valmin, mydata.valmax);
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'ImpostaDefMinMaxCollettivi') {
|
||||||
|
|
||||||
|
await Circuit.SetDefMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax);
|
||||||
|
|
||||||
|
} else if (mydata.dbop === 'setstrProvByIdCityCircuits') {
|
||||||
|
|
||||||
|
await Circuit.setstrProvByIdCityCircuits(idapp);
|
||||||
|
|
||||||
/*} else if (mydata.dbop === 'visuNave') {
|
/*} else if (mydata.dbop === 'visuNave') {
|
||||||
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
||||||
|
|
||||||
@@ -1318,8 +1299,47 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||||
|
|
||||||
|
let ris = await User.DbOp(idapp, mydata);
|
||||||
|
|
||||||
|
const populate = require('../populate/populate');
|
||||||
|
|
||||||
|
const globalTables = require('../tools/globalTables');
|
||||||
|
|
||||||
|
let mystr = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
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 === 'saveStepTut') {
|
||||||
|
await User.findOneAndUpdate({ _id: mydata._id },
|
||||||
|
{ $set: { 'profile.stepTutorial': mydata.value } });
|
||||||
|
} else if (mydata.dbop === 'noNameSurname') {
|
||||||
|
await User.findOneAndUpdate({ _id: mydata._id },
|
||||||
|
{ $set: { 'profile.noNameSurname': mydata.value } });
|
||||||
|
} else if (mydata.dbop === 'noFoto') {
|
||||||
|
await User.findOneAndUpdate({ _id: mydata._id },
|
||||||
|
{ $set: { 'profile.noFoto': mydata.value } });
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
router.post('/dbop', authenticate, async (req, res) => {
|
router.post('/dbop', authenticate, async (req, res) => {
|
||||||
|
|
||||||
const mydata = req.body.mydata;
|
const mydata = req.body.mydata;
|
||||||
@@ -1333,9 +1353,40 @@ router.post('/dbop', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ris = await eseguiDbOp(idapp, mydata, locale, req, res);
|
let ris = await eseguiDbOp(idapp, mydata, locale, req, res);
|
||||||
|
|
||||||
res.send(ris);
|
if (!ris) {
|
||||||
|
ris = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ris = await User.updateMyData(ris, idapp, req.user.username);
|
||||||
|
|
||||||
|
res.send({ code: server_constants.RIS_CODE_OK, data: ris.data });
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
|
||||||
|
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/dbopuser', authenticate, async (req, res) => {
|
||||||
|
|
||||||
|
const mydata = req.body.mydata;
|
||||||
|
idapp = req.body.idapp;
|
||||||
|
locale = req.body.locale;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let ris = await eseguiDbOpUser(idapp, mydata, locale, req, res);
|
||||||
|
|
||||||
|
if (!ris) {
|
||||||
|
ris = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ris = await User.updateMyData(ris, idapp, req.user.username);
|
||||||
|
|
||||||
|
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
|
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ const webpush = require('web-push');
|
|||||||
|
|
||||||
const i18n = require('i18n');
|
const i18n = require('i18n');
|
||||||
|
|
||||||
|
|
||||||
const FILELOG = 'filelog.txt';
|
const FILELOG = 'filelog.txt';
|
||||||
const FILEEVENTS = 'logevents.txt';
|
const FILEEVENTS = 'logevents.txt';
|
||||||
const FILEMANAGERS = 'logmanagers.txt';
|
const FILEMANAGERS = 'logmanagers.txt';
|
||||||
@@ -425,6 +426,8 @@ module.exports = {
|
|||||||
|
|
||||||
SEP: '|',
|
SEP: '|',
|
||||||
|
|
||||||
|
USER_ADMIN_CIRCUITS: 'paoloar77',
|
||||||
|
|
||||||
TYPE_PROJECT: 1,
|
TYPE_PROJECT: 1,
|
||||||
TYPE_TODO: 2,
|
TYPE_TODO: 2,
|
||||||
|
|
||||||
@@ -1482,6 +1485,12 @@ module.exports = {
|
|||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
convertSpaces_ToUScore(mystr) {
|
||||||
|
if (mystr)
|
||||||
|
return mystr.replace(/\s+/g, '_');
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
|
||||||
convertHTMLtoText(myhtml) {
|
convertHTMLtoText(myhtml) {
|
||||||
let msg = myhtml;
|
let msg = myhtml;
|
||||||
if (msg) {
|
if (msg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user