wikijs-fork/server/models/groups.js

52 lines
1.0 KiB
JavaScript
Raw Normal View History

const Model = require('objection').Model
/**
2018-05-20 22:50:51 +00:00
* Groups model
*/
module.exports = class Group extends Model {
static get tableName() { return 'groups' }
static get jsonSchema () {
return {
type: 'object',
required: ['name'],
properties: {
id: {type: 'integer'},
name: {type: 'string'},
createdAt: {type: 'string'},
updatedAt: {type: 'string'}
}
}
}
2019-02-10 00:10:34 +00:00
static get jsonAttributes() {
return ['permissions', 'pageRules']
}
static get relationMappings() {
return {
users: {
relation: Model.ManyToManyRelation,
2018-05-20 22:50:51 +00:00
modelClass: require('./users'),
join: {
from: 'groups.id',
through: {
from: 'userGroups.groupId',
to: 'userGroups.userId'
},
to: 'users.id'
}
}
}
}
$beforeUpdate() {
this.updatedAt = new Date().toISOString()
}
$beforeInsert() {
this.createdAt = new Date().toISOString()
this.updatedAt = new Date().toISOString()
}
}