Add endpoint for retrieving page versions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-11-02 20:22:24 -06:00
parent 52382f6bf7
commit 2e34deb203
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 34 additions and 0 deletions

View File

@ -8,6 +8,37 @@ const Node = require('../../../models/api/Node.model')
* Put some description here! * Put some description here!
*/ */
class Page extends Controller { class Page extends Controller {
static get services() {
return [...super.services, 'models']
}
async get_page_versions(req, res, next) {
const User = this.models.get('auth:User')
const PageId = req.params.PageId
const user = req.user
let page = await PageModel.findOne({UUID: PageId})
if ( !page ) return res.status(404).message('Page not found with that ID.').api({})
if ( !(await page.is_accessible_by(user)) ) return req.security.deny()
const versions = page.version_archive.map(version_data => {
return {
current_version: Number(version_data.version_num) === Number(page.version_num),
version_num: version_data.version_num,
version_user_id: version_data.version_user_id,
version_message: version_data.version_message,
version_UUID: version_data.version_UUID,
}
})
for ( const version of versions ) {
version.user_display = (await User.findById(version.version_user_id))?.uid || 'Unknown User'
}
return res.api(versions.reverse())
}
async get_page(req, res) { async get_page(req, res) {
const PageId = req.params.PageId const PageId = req.params.PageId
const user = req.user const user = req.user

View File

@ -25,6 +25,9 @@ const index = {
// Get the data for the specified page // Get the data for the specified page
'/page/:PageId': ['controller::api:v1:Page.get_page'], '/page/:PageId': ['controller::api:v1:Page.get_page'],
// Get the available versions of the given page
'/page/:PageId/versions': ['controller::api:v1:Page.get_page_versions'],
// Get the nodes present on the specified page // Get the nodes present on the specified page
'/page/:PageId/nodes': ['controller::api:v1:Page.get_nodes'], '/page/:PageId/nodes': ['controller::api:v1:Page.get_nodes'],