hooks.js 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const Model = require('objection').Model
  2. /* global WIKI */
  3. /**
  4. * Hook model
  5. */
  6. module.exports = class Hook extends Model {
  7. static get tableName () { return 'hooks' }
  8. static get jsonAttributes () {
  9. return ['events']
  10. }
  11. $beforeUpdate () {
  12. this.updatedAt = new Date()
  13. }
  14. static async createHook (data) {
  15. return WIKI.models.hooks.query().insertAndFetch({
  16. name: data.name,
  17. events: data.events,
  18. url: data.url,
  19. includeMetadata: data.includeMetadata,
  20. includeContent: data.includeContent,
  21. acceptUntrusted: data.acceptUntrusted,
  22. authHeader: data.authHeader,
  23. state: 'pending',
  24. lastErrorMessage: null
  25. })
  26. }
  27. static async updateHook (id, patch) {
  28. return WIKI.models.hooks.query().findById(id).patch({
  29. ...patch,
  30. state: 'pending',
  31. lastErrorMessage: null
  32. })
  33. }
  34. static async deleteHook (id) {
  35. return WIKI.models.hooks.query().deleteById(id)
  36. }
  37. }