hooks.mjs 906 B

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