Task #21 - add page controller and page/node api endpoints
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
const Middleware = [
|
||||
"auth:Utility",
|
||||
"api:GuaranteeRootNode",
|
||||
|
||||
// 'MiddlewareName',
|
||||
|
||||
|
||||
43
app/routing/middleware/api/GuaranteeRootNode.middleware.js
Normal file
43
app/routing/middleware/api/GuaranteeRootNode.middleware.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const Middleware = require('libflitter/middleware/Middleware')
|
||||
|
||||
/*
|
||||
* GuaranteeRootNode Middleware
|
||||
* -------------------------------------------------------------
|
||||
* Put some description here!
|
||||
*/
|
||||
class GuaranteeRootNode extends Middleware {
|
||||
static get services() {
|
||||
return [...super.services, 'models']
|
||||
}
|
||||
|
||||
/*
|
||||
* Run the middleware test.
|
||||
* This method is required by all Flitter middleware.
|
||||
* It should either call the next function in the stack,
|
||||
* or it should handle the response accordingly.
|
||||
*/
|
||||
async test(req, res, next, args = {}){
|
||||
const Page = this.models.get('api:Page')
|
||||
if ( req.user ) {
|
||||
const root_page = await Page.findOne({ OrgUserId: req.user._id, ParentId: "0" })
|
||||
if ( !root_page ) {
|
||||
const new_page = new Page({
|
||||
Name: `${req.user.uid} virtual root`,
|
||||
OrgUserId: req.user._id,
|
||||
ParentId: "0",
|
||||
CreatedUserId: req.user.id,
|
||||
UpdateUserId: req.user.id,
|
||||
})
|
||||
|
||||
await new_page.save()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Call the next function in the stack.
|
||||
*/
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = GuaranteeRootNode
|
||||
@@ -38,10 +38,12 @@ const index = {
|
||||
get: {
|
||||
'/hello_world': ['controller::api:v1:Misc.hello_world'],
|
||||
'/page/:PageId': ['controller::api:v1:Page.get_page'],
|
||||
'/page/:PageId/nodes': ['controller::api:v1:Page.get_nodes'],
|
||||
},
|
||||
|
||||
post: {
|
||||
'/page/:PageId/save': ['controller::api:v1:Page.save_page'],
|
||||
'/page/:PageId/nodes/save': ['controller::api:v1:Page.save_nodes'],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user