Add ability to retrieve specific page versions and nodes with ?version=XX param
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:
@@ -115,8 +115,35 @@ class Page extends VersionedModel {
|
||||
|
||||
get nodes() {
|
||||
const Node = this.models.get("api:Node")
|
||||
return this.has_many(Node, "NodeIds", "UUID")
|
||||
const node_promise = this.has_many(Node, "NodeIds", "UUID")
|
||||
if ( this.is_a_version() ) {
|
||||
// return the nodes for this version!
|
||||
return (async () => {
|
||||
const nodes = await node_promise
|
||||
const version_data = this.raw_version_data()
|
||||
const return_nodes = []
|
||||
if ( version_data?.node_version_nums ) {
|
||||
const node_x_version_num = {}
|
||||
for ( const item of version_data.node_version_nums ) {
|
||||
node_x_version_num[item.NodeId] = item.version_num
|
||||
}
|
||||
|
||||
for ( const node of nodes ) {
|
||||
if ( node_x_version_num[node.UUID] ) {
|
||||
return_nodes.push(await node.as_version(node_x_version_num[node.UUID]))
|
||||
} else {
|
||||
return_nodes.push(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return return_nodes
|
||||
})()
|
||||
} else {
|
||||
return node_promise
|
||||
}
|
||||
}
|
||||
|
||||
get childPages() {
|
||||
const Page = this.models.get("api:Page")
|
||||
return this.has_many(Page, "ChildPageIds", "UUID")
|
||||
|
||||
Reference in New Issue
Block a user