Add endpoint for retrieving page versions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
52382f6bf7
commit
2e34deb203
@ -8,6 +8,37 @@ const Node = require('../../../models/api/Node.model')
|
||||
* Put some description here!
|
||||
*/
|
||||
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) {
|
||||
const PageId = req.params.PageId
|
||||
const user = req.user
|
||||
|
@ -25,6 +25,9 @@ const index = {
|
||||
// Get the data for the specified 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
|
||||
'/page/:PageId/nodes': ['controller::api:v1:Page.get_nodes'],
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user