33 lines
944 B
JavaScript
33 lines
944 B
JavaScript
const Controller = require('libflitter/controller/Controller')
|
|
|
|
/*
|
|
* Export Controller
|
|
* -------------------------------------------------------------
|
|
* Put some description here!
|
|
*/
|
|
class Export extends Controller {
|
|
static get services() {
|
|
return [...super.services, 'models']
|
|
}
|
|
/*
|
|
* Serve the main page.
|
|
*/
|
|
async json_export(req, res){
|
|
const Page = this.models.get('api:Page')
|
|
const user = req.user
|
|
const pages = await Page.find({OrgUserId:user.id})
|
|
const Node = this.models.get('api:Node')
|
|
|
|
const ExportData = {}
|
|
for (const page of pages ) {
|
|
const nodes = await Node.find({PageId:page.UUID})
|
|
|
|
const PageData = {...page}
|
|
PageData.Nodes = nodes.map( node => { return {...node} } )
|
|
ExportData[page.Name] = PageData
|
|
}
|
|
return res.api(ExportData)
|
|
}
|
|
}
|
|
|
|
module.exports = exports = Export |