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.
43 lines
906 B
43 lines
906 B
2 years ago
|
import { Model } from 'objection'
|
||
2 years ago
|
|
||
|
/**
|
||
|
* Hook model
|
||
|
*/
|
||
2 years ago
|
export class Hook extends Model {
|
||
2 years ago
|
static get tableName () { return 'hooks' }
|
||
|
|
||
|
static get jsonAttributes () {
|
||
|
return ['events']
|
||
|
}
|
||
|
|
||
|
$beforeUpdate () {
|
||
|
this.updatedAt = new Date()
|
||
|
}
|
||
|
|
||
|
static async createHook (data) {
|
||
2 years ago
|
return WIKI.db.hooks.query().insertAndFetch({
|
||
2 years ago
|
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) {
|
||
2 years ago
|
return WIKI.db.hooks.query().findById(id).patch({
|
||
2 years ago
|
...patch,
|
||
|
state: 'pending',
|
||
|
lastErrorMessage: null
|
||
|
})
|
||
|
}
|
||
|
|
||
|
static async deleteHook (id) {
|
||
2 years ago
|
return WIKI.db.hooks.query().deleteById(id)
|
||
2 years ago
|
}
|
||
|
}
|