feat: new page UI + db fixes + installer improvements

This commit is contained in:
Nicolas Giard
2018-08-19 01:22:59 -04:00
parent 04c972c1d0
commit 4bb522f9d9
21 changed files with 357 additions and 182 deletions

View File

@@ -1,4 +1,5 @@
const Model = require('objection').Model
const _ = require('lodash')
/* global WIKI */
@@ -19,6 +20,7 @@ module.exports = class Page extends Model {
title: {type: 'string'},
description: {type: 'string'},
isPublished: {type: 'boolean'},
privateNS: {type: 'string'},
publishStartDate: {type: 'string'},
publishEndDate: {type: 'string'},
content: {type: 'string'},
@@ -87,6 +89,27 @@ module.exports = class Page extends Model {
this.updatedAt = new Date().toISOString()
}
static async getPage(opts) {
const page = await WIKI.models.pages.query().where({
path: opts.path,
localeCode: opts.locale
}).andWhere(builder => {
builder.where({
isPublished: true
}).orWhere({
isPublished: false,
authorId: opts.userId
})
}).andWhere(builder => {
if (opts.private) {
builder.where({ isPrivate: true, privateNS: opts.privateNS })
} else {
builder.where({ isPrivate: false })
}
}).first()
return page
}
static async createPage(opts) {
await WIKI.models.pages.renderPage(opts)
const page = await WIKI.models.pages.query().insertAndFetch({