mirror of https://github.com/requarks/wiki
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.
45 lines
954 B
45 lines
954 B
const Model = require('objection').Model
|
|
|
|
/* global WIKI */
|
|
|
|
/**
|
|
* Hook model
|
|
*/
|
|
module.exports = 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.models.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.models.hooks.query().findById(id).patch({
|
|
...patch,
|
|
state: 'pending',
|
|
lastErrorMessage: null
|
|
})
|
|
}
|
|
|
|
static async deleteHook (id) {
|
|
return WIKI.models.hooks.query().deleteById(id)
|
|
}
|
|
}
|