feat: save page + create event for storage targets

This commit is contained in:
NGPixel
2018-07-22 16:25:39 -04:00
parent cb84df7a53
commit 076e923d48
22 changed files with 158 additions and 89 deletions

View File

@@ -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
}
}

View File

@@ -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
})
})
}
}
}

View File

@@ -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)