diff --git a/app/controllers/api/v1/Misc.controller.js b/app/controllers/api/v1/Misc.controller.js index df257b6..f8b5eb0 100644 --- a/app/controllers/api/v1/Misc.controller.js +++ b/app/controllers/api/v1/Misc.controller.js @@ -1,4 +1,6 @@ const Controller = require('libflitter/controller/Controller') +const { ObjectId } = require("mongodb"); +const Page = require("../../../models/api/Page.model") /* * Misc Controller @@ -12,6 +14,39 @@ class Misc extends Controller { hello: 'world', }) } + + async save_page(req, res) { + // return res.status(400).message('Missing required field: some_field').api({}) + + // Name, Parent, originalID + requried_fields = { + Name: String, + Parent: ObjectId, + OriginalId: ObjectId + } + + requried_fields.name = req.name + requried_fields.Parrent = req.Parrent + requried_fields.OriginalId = req.OriginalId + + if (!requried_fields.Name) { + return res.status(400).message('Missing required field: Name').api({}) + } else if (!requried_fields.Parrent) { + return res.status(400).message('Missing required field: Parent').api({}) + + } else if (!requried_fields.ObjectId) { + return res.status(400).message('Missing required field: ObjectId').api({}) + } + + if (req.body.PageId) { + //use the page model to find by id and + const page = await Page.findById(req.body.PageId) + if (!page) { + + } + } + + } } module.exports = exports = Misc diff --git a/app/models/api/Page.model.js b/app/models/api/Page.model.js index 255a2ab..51b141f 100644 --- a/app/models/api/Page.model.js +++ b/app/models/api/Page.model.js @@ -15,7 +15,7 @@ class Page extends Model { return { Name: String, OrgUserId: ObjectId, - IsPublic: Boolean, + IsPublic: { type: Boolean, default: true }, IsVisibleInMenu: { type: Boolean, default: true }, ParentId: ObjectId, NodeIds: [ObjectId], diff --git a/app/routing/routers/api/v1.routes.js b/app/routing/routers/api/v1.routes.js index 77de025..716cec1 100644 --- a/app/routing/routers/api/v1.routes.js +++ b/app/routing/routers/api/v1.routes.js @@ -36,10 +36,11 @@ const index = { * or middleware that are applied in order. */ get: { - '/hello_world': [ 'controller::api:v1:Misc.hello_world' ], + '/hello_world': ['controller::api:v1:Misc.hello_world'], }, post: { + '/page/save': ['middleware::auth:UserOnly', 'controller::api:v1:Misc.save_page'] }, }