- AbitaregliIblei.it

- Server aggiornamenti agli script.
- Editor HTML corretto un po'.
- Record Mysql per server (appena iniziato)
This commit is contained in:
Surya Paolo
2024-09-06 19:57:09 +02:00
parent 45f601bd26
commit fe4a67c9f1
28 changed files with 638 additions and 567 deletions

View File

@@ -0,0 +1,87 @@
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const SectorActivitiesSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
idSectorActivities: {
type: Number
},
icon: {
type: String,
},
img: {
type: String,
},
color: {
type: String,
},
theme: {
type: String,
},
});
SectorActivitiesSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await SectorActivities.findOne().limit(1).sort({ _id: -1 });
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
}
next();
});
SectorActivitiesSchema.statics.findAllIdApp = async function (idapp) {
const SectorActivities = this;
const query = [
{ $sort: { descr: 1 } }
];
return await SectorActivities
.aggregate(query)
.then((arrrec) => {
return arrrec
})
};
SectorActivitiesSchema.statics.getFieldsForSearch = function () {
return [{ field: 'descr', type: tools.FieldType.string }]
};
SectorActivitiesSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const SectorActivities = mongoose.model('SectorActivities', SectorActivitiesSchema);
SectorActivities.createIndexes((err) => {
if (err) throw err;
});
module.exports = { SectorActivities };

View File

@@ -672,6 +672,16 @@ UserSchema.statics.isManagerById = async function (id) {
}
};
UserSchema.statics.isAdminById = async function (id) {
try {
const ris = await User.findOne({ _id: id }, { perm: 1 }).lean();
return ((ris.perm & shared_consts.Permissions.Admin) ===
shared_consts.Permissions.Admin);
} catch (e) {
return false;
}
};
UserSchema.statics.isEditor = function (perm) {
try {
return ((perm & shared_consts.Permissions.Editor) ===
@@ -3237,7 +3247,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
}
ris = true;
// } else if ((cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) || (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REFUSE)) {
// } else if ((cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) || (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REFUSE)) {
// Before to accept, I see if it's already set !
/*outres = {
@@ -5742,10 +5752,10 @@ UserSchema.statics.tooManyLoginWrong = async function (idapp, username, set) {
await User.findOneAndUpdate({ _id: user._id }, { $set: { retry_pwd: user.retry_pwd } });
}
return {troppilogin: user.retry_pwd > maxnum, retry_pwd: user.retry_pwd};
return { troppilogin: user.retry_pwd > maxnum, retry_pwd: user.retry_pwd };
}
return {troppilogin: false, retry_pwd: 0};
return { troppilogin: false, retry_pwd: 0 };
};
UserSchema.statics.setLastCircuitOpened = async function (idapp, username, circuitpath) {