feat: save page + create event for storage targets
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const Model = require('objection').Model
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* Pages model
|
||||
*/
|
||||
@@ -75,4 +77,22 @@ module.exports = class Page extends Model {
|
||||
this.createdAt = new Date().toISOString()
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
|
||||
static async createPage(opts) {
|
||||
const page = await WIKI.db.pages.query().insertAndFetch({
|
||||
authorId: opts.authorId,
|
||||
content: opts.content,
|
||||
description: opts.description,
|
||||
editorKey: opts.editor,
|
||||
isPrivate: opts.isPrivate,
|
||||
isPublished: opts.isPublished,
|
||||
localeCode: opts.locale,
|
||||
path: opts.path,
|
||||
publishEndDate: opts.publishEndDate,
|
||||
publishStartDate: opts.publishStartDate,
|
||||
title: opts.title
|
||||
})
|
||||
await WIKI.db.storage.createPage(page)
|
||||
return page
|
||||
}
|
||||
}
|
||||
|
@@ -86,4 +86,19 @@ module.exports = class Storage extends Model {
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
static async createPage(page) {
|
||||
const targets = await WIKI.db.storage.query().where('isEnabled', true)
|
||||
if (targets && targets.length > 0) {
|
||||
_.forEach(targets, target => {
|
||||
WIKI.queue.job.syncStorage.add({
|
||||
event: 'created',
|
||||
target,
|
||||
page
|
||||
}, {
|
||||
removeOnComplete: true
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -193,7 +193,6 @@ module.exports = class User extends Model {
|
||||
}
|
||||
|
||||
static async login (opts, context) {
|
||||
console.info(context)
|
||||
if (_.has(WIKI.auth.strategies, opts.strategy)) {
|
||||
_.set(context.req, 'body.email', opts.username)
|
||||
_.set(context.req, 'body.password', opts.password)
|
||||
|
Reference in New Issue
Block a user