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.

53 lines
1.1 KiB

  1. const Model = require('objection').Model
  2. /**
  3. * Groups model
  4. */
  5. module.exports = class Group extends Model {
  6. static get tableName() { return 'groups' }
  7. static get jsonSchema () {
  8. return {
  9. type: 'object',
  10. required: ['name'],
  11. properties: {
  12. id: {type: 'integer'},
  13. name: {type: 'string'},
  14. isSystem: {type: 'boolean'},
  15. redirectOnLogin: {type: 'string'},
  16. createdAt: {type: 'string'},
  17. updatedAt: {type: 'string'}
  18. }
  19. }
  20. }
  21. static get jsonAttributes() {
  22. return ['permissions', 'pageRules']
  23. }
  24. static get relationMappings() {
  25. return {
  26. users: {
  27. relation: Model.ManyToManyRelation,
  28. modelClass: require('./users'),
  29. join: {
  30. from: 'groups.id',
  31. through: {
  32. from: 'userGroups.groupId',
  33. to: 'userGroups.userId'
  34. },
  35. to: 'users.id'
  36. }
  37. }
  38. }
  39. }
  40. $beforeUpdate() {
  41. this.updatedAt = new Date().toISOString()
  42. }
  43. $beforeInsert() {
  44. this.createdAt = new Date().toISOString()
  45. this.updatedAt = new Date().toISOString()
  46. }
  47. }