feat: save page - updated + page history
This commit is contained in:
@@ -51,6 +51,14 @@ module.exports = class Page extends Model {
|
||||
to: 'users.id'
|
||||
}
|
||||
},
|
||||
creator: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: require('./users'),
|
||||
join: {
|
||||
from: 'pages.creatorId',
|
||||
to: 'users.id'
|
||||
}
|
||||
},
|
||||
editor: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: require('./editors'),
|
||||
@@ -82,6 +90,7 @@ module.exports = class Page extends Model {
|
||||
const page = await WIKI.db.pages.query().insertAndFetch({
|
||||
authorId: opts.authorId,
|
||||
content: opts.content,
|
||||
creatorId: opts.authorId,
|
||||
description: opts.description,
|
||||
editorKey: opts.editor,
|
||||
isPrivate: opts.isPrivate,
|
||||
@@ -92,7 +101,26 @@ module.exports = class Page extends Model {
|
||||
publishStartDate: opts.publishStartDate,
|
||||
title: opts.title
|
||||
})
|
||||
await WIKI.db.storage.createPage(page)
|
||||
await WIKI.db.storage.pageEvent({
|
||||
event: 'created',
|
||||
page
|
||||
})
|
||||
return page
|
||||
}
|
||||
|
||||
static async updatePage(opts) {
|
||||
const ogPage = await WIKI.db.pages.query().findById(opts.id)
|
||||
if (!ogPage) {
|
||||
throw new Error('Invalid Page Id')
|
||||
}
|
||||
await WIKI.db.pageHistory.addVersion(ogPage)
|
||||
const page = await WIKI.db.pages.query().patchAndFetch({
|
||||
title: opts.title
|
||||
}).where('id', opts.id)
|
||||
await WIKI.db.storage.pageEvent({
|
||||
event: 'updated',
|
||||
page
|
||||
})
|
||||
return page
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user