2013-09-24 14:46:30 +04:00
|
|
|
var User = require('./user').User,
|
|
|
|
Permission = require('./permission').Permission,
|
2013-09-23 02:20:08 +04:00
|
|
|
ghostBookshelf = require('./base'),
|
2013-06-25 15:43:15 +04:00
|
|
|
Role,
|
|
|
|
Roles;
|
|
|
|
|
2013-09-23 02:20:08 +04:00
|
|
|
Role = ghostBookshelf.Model.extend({
|
2013-06-25 15:43:15 +04:00
|
|
|
|
2013-09-14 23:01:46 +04:00
|
|
|
tableName: 'roles',
|
2013-08-25 14:49:31 +04:00
|
|
|
|
2013-09-14 23:01:46 +04:00
|
|
|
permittedAttributes: ['id', 'uuid', 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'],
|
2013-08-25 14:49:31 +04:00
|
|
|
|
|
|
|
validate: function () {
|
2013-09-23 02:20:08 +04:00
|
|
|
ghostBookshelf.validator.check(this.get('name'), "Role name cannot be blank").notEmpty();
|
|
|
|
ghostBookshelf.validator.check(this.get('description'), "Role description cannot be blank").notEmpty();
|
2013-08-25 14:49:31 +04:00
|
|
|
},
|
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
users: function () {
|
|
|
|
return this.belongsToMany(User);
|
|
|
|
},
|
|
|
|
|
|
|
|
permissions: function () {
|
|
|
|
return this.belongsToMany(Permission);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-23 02:20:08 +04:00
|
|
|
Roles = ghostBookshelf.Collection.extend({
|
2013-06-25 15:43:15 +04:00
|
|
|
model: Role
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Role: Role,
|
|
|
|
Roles: Roles
|
|
|
|
};
|