- Permissions table (probably I'll change for others uses)
- Added CDateTime component (to save in the db)... in the component CGridTableRec and for CEventsCalendar
This commit is contained in:
@@ -105,10 +105,20 @@ MyEventSchema.statics.findAllIdApp = function (idapp) {
|
||||
};
|
||||
|
||||
|
||||
MyEventSchema.statics.getFieldsForSearch = function () {
|
||||
return ['short_tit', 'title', 'teacher', 'details']
|
||||
};
|
||||
|
||||
MyEventSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
// console.log(' createIndex MyEvent Index...');
|
||||
// MyEventSchema.index({ short_tit: 'text', title: 'text', teacher: 'text', details: 'text' });
|
||||
}
|
||||
|
||||
|
||||
const MyEvent = mongoose.model('MyEvent', MyEventSchema);
|
||||
|
||||
|
||||
59
server/models/permission.js
Normal file
59
server/models/permission.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const PermissionSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},{ _id : false });
|
||||
|
||||
|
||||
PermissionSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await Permission.findOne().limit(1).sort({_id:-1});
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id * 2;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
PermissionSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
PermissionSchema.statics.findAllIdApp = function () {
|
||||
const Permission = this;
|
||||
|
||||
const myfind = { };
|
||||
|
||||
return Permission.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
const Permission = mongoose.model('Permission', PermissionSchema);
|
||||
|
||||
module.exports = { Permission };
|
||||
@@ -358,13 +358,27 @@ UserSchema.statics.getUsersListByParams = function (params) {
|
||||
* @returns {Object} Object -> `{ rows, count }`
|
||||
*/
|
||||
|
||||
UserSchema.statics.getFieldsForSearch = function () {
|
||||
return ['name', 'surname', 'email']
|
||||
};
|
||||
|
||||
UserSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
console.log(' createIndex User Index...');
|
||||
// UserSchema.index({ username: 'text', name: 'text', surname: 'text', email: 'text' });
|
||||
// UserSchema.index({ name: 'name' });
|
||||
// UserSchema.index({ name: 1 });
|
||||
// UserSchema.index({ surname: 1 });
|
||||
}
|
||||
|
||||
const User = mongoose.model('User', UserSchema);
|
||||
|
||||
|
||||
|
||||
class Hero {
|
||||
constructor(name, level) {
|
||||
this.name = name;
|
||||
|
||||
@@ -13,6 +13,9 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const WhereSchema = new Schema({
|
||||
_id: {
|
||||
type: mongoose.Schema.Types.ObjectId
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user