2013-09-24 12:46:30 +02:00
|
|
|
var User = require('./user').User,
|
|
|
|
Permission = require('./permission').Permission,
|
2013-09-22 18:20:08 -04:00
|
|
|
ghostBookshelf = require('./base'),
|
2014-02-19 14:57:26 +01:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
Role,
|
|
|
|
Roles;
|
|
|
|
|
2013-09-22 18:20:08 -04:00
|
|
|
Role = ghostBookshelf.Model.extend({
|
2013-06-25 12:43:15 +01:00
|
|
|
|
2013-09-14 20:01:46 +01:00
|
|
|
tableName: 'roles',
|
2013-08-25 11:49:31 +01:00
|
|
|
|
|
|
|
validate: function () {
|
2013-09-22 18: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 11:49:31 +01:00
|
|
|
},
|
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
users: function () {
|
|
|
|
return this.belongsToMany(User);
|
|
|
|
},
|
|
|
|
|
|
|
|
permissions: function () {
|
|
|
|
return this.belongsToMany(Permission);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-22 18:20:08 -04:00
|
|
|
Roles = ghostBookshelf.Collection.extend({
|
2013-06-25 12:43:15 +01:00
|
|
|
model: Role
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Role: Role,
|
|
|
|
Roles: Roles
|
|
|
|
};
|