123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { Model } from 'objection'
- /**
- * Hook model
- */
- export class Hook extends Model {
- static get tableName () { return 'hooks' }
- static get jsonAttributes () {
- return ['events']
- }
- $beforeUpdate () {
- this.updatedAt = new Date()
- }
- static async createHook (data) {
- return WIKI.db.hooks.query().insertAndFetch({
- name: data.name,
- events: data.events,
- url: data.url,
- includeMetadata: data.includeMetadata,
- includeContent: data.includeContent,
- acceptUntrusted: data.acceptUntrusted,
- authHeader: data.authHeader,
- state: 'pending',
- lastErrorMessage: null
- })
- }
- static async updateHook (id, patch) {
- return WIKI.db.hooks.query().findById(id).patch({
- ...patch,
- state: 'pending',
- lastErrorMessage: null
- })
- }
- static async deleteHook (id) {
- return WIKI.db.hooks.query().deleteById(id)
- }
- }
|