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.

51 lines
1.0 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. createdAt: {type: 'string'},
  15. updatedAt: {type: 'string'}
  16. }
  17. }
  18. }
  19. static get jsonAttributes() {
  20. return ['permissions', 'pageRules']
  21. }
  22. static get relationMappings() {
  23. return {
  24. users: {
  25. relation: Model.ManyToManyRelation,
  26. modelClass: require('./users'),
  27. join: {
  28. from: 'groups.id',
  29. through: {
  30. from: 'userGroups.groupId',
  31. to: 'userGroups.userId'
  32. },
  33. to: 'users.id'
  34. }
  35. }
  36. }
  37. }
  38. $beforeUpdate() {
  39. this.updatedAt = new Date().toISOString()
  40. }
  41. $beforeInsert() {
  42. this.createdAt = new Date().toISOString()
  43. this.updatedAt = new Date().toISOString()
  44. }
  45. }