mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
2 years ago
|
import { Model } from 'objection'
|
||
|
|
||
|
import { User } from './users.mjs'
|
||
7 years ago
|
|
||
|
/**
|
||
7 years ago
|
* Groups model
|
||
7 years ago
|
*/
|
||
2 years ago
|
export class Group extends Model {
|
||
7 years ago
|
static get tableName() { return 'groups' }
|
||
|
|
||
|
static get jsonSchema () {
|
||
|
return {
|
||
|
type: 'object',
|
||
|
required: ['name'],
|
||
|
|
||
|
properties: {
|
||
|
id: {type: 'integer'},
|
||
|
name: {type: 'string'},
|
||
5 years ago
|
isSystem: {type: 'boolean'},
|
||
|
redirectOnLogin: {type: 'string'},
|
||
7 years ago
|
createdAt: {type: 'string'},
|
||
|
updatedAt: {type: 'string'}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
static get jsonAttributes() {
|
||
|
return ['permissions', 'pageRules']
|
||
|
}
|
||
|
|
||
7 years ago
|
static get relationMappings() {
|
||
|
return {
|
||
|
users: {
|
||
|
relation: Model.ManyToManyRelation,
|
||
2 years ago
|
modelClass: User,
|
||
7 years ago
|
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()
|
||
|
}
|
||
|
}
|