enable endpoints for embedded code editor
This commit is contained in:
parent
3bf4c9eb1f
commit
30f61077fe
96
app/controllers/api/v1/FormCode.controller.js
Normal file
96
app/controllers/api/v1/FormCode.controller.js
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
const Controller = require('libflitter/controller/Controller')
|
||||||
|
const Codium = require('../../../models/api/Codium.model')
|
||||||
|
const Page = require('../../../models/api/Page.model')
|
||||||
|
const Node = require('../../../models/api/Node.model')
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FormCode Controller
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* Put some description here!
|
||||||
|
*/
|
||||||
|
class FormCode extends Controller {
|
||||||
|
|
||||||
|
async create_new(req, res) {
|
||||||
|
const PageId = req.params.PageId
|
||||||
|
|
||||||
|
let page = await Page.findOne({UUID: PageId})
|
||||||
|
if ( !page ) return res.status(404).message('Page not found with that ID.').api({})
|
||||||
|
if ( !page.accessible_by(req.user) ) return req.security.deny()
|
||||||
|
|
||||||
|
const NodeId = req.params.NodeId
|
||||||
|
|
||||||
|
let node = await Node.findOne({UUID: NodeId})
|
||||||
|
if ( !node ) return res.status(404).message('Node not found with that ID.').api({})
|
||||||
|
|
||||||
|
const code = new Codium({
|
||||||
|
NodeId: node.UUID,
|
||||||
|
PageId: page.UUID,
|
||||||
|
code: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
await code.save()
|
||||||
|
return res.api(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
async get_config(req, res) {
|
||||||
|
const PageId = req.params.PageId
|
||||||
|
|
||||||
|
let page = await Page.findOne({UUID: PageId})
|
||||||
|
if ( !page ) return res.status(404).message('Page not found with that ID.').api({})
|
||||||
|
if ( !page.accessible_by(req.user) ) return req.security.deny()
|
||||||
|
|
||||||
|
const NodeId = req.params.NodeId
|
||||||
|
|
||||||
|
let node = await Node.findOne({UUID: NodeId})
|
||||||
|
if ( !node ) return res.status(404).message('Node not found with that ID.').api({})
|
||||||
|
|
||||||
|
const code = await Codium.findOne({UUID: req.params.CodiumId})
|
||||||
|
if ( !code ) return res.status(404).message('Unable to find code with that ID.').api({})
|
||||||
|
|
||||||
|
return res.api(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
async set_values(req, res) {
|
||||||
|
const PageId = req.params.PageId
|
||||||
|
|
||||||
|
let page = await Page.findOne({UUID: PageId})
|
||||||
|
if ( !page ) return res.status(404).message('Page not found with that ID.').api({})
|
||||||
|
if ( !page.accessible_by(req.user) ) return req.security.deny()
|
||||||
|
|
||||||
|
const NodeId = req.params.NodeId
|
||||||
|
|
||||||
|
let node = await Node.findOne({UUID: NodeId})
|
||||||
|
if ( !node ) return res.status(404).message('Node not found with that ID.').api({})
|
||||||
|
|
||||||
|
const code = await Codium.findOne({UUID: req.params.CodiumId})
|
||||||
|
if ( !code ) return res.status(404).message('Unable to find code with that ID.').api({})
|
||||||
|
|
||||||
|
code.code = req.body.code
|
||||||
|
code.language = req.body.language
|
||||||
|
code.NodeId = node.UUID
|
||||||
|
code.PageId = page.UUID
|
||||||
|
await code.save()
|
||||||
|
return res.api(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
async drop_code(req, res) {
|
||||||
|
const PageId = req.params.PageId
|
||||||
|
|
||||||
|
let page = await Page.findOne({UUID: PageId})
|
||||||
|
if ( !page ) return res.status(404).message('Page not found with that ID.').api({})
|
||||||
|
if ( !page.accessible_by(req.user) ) return req.security.deny()
|
||||||
|
|
||||||
|
const NodeId = req.params.NodeId
|
||||||
|
|
||||||
|
let node = await Node.findOne({UUID: NodeId})
|
||||||
|
if ( !node ) return res.status(404).message('Node not found with that ID.').api({})
|
||||||
|
|
||||||
|
const code = await Codium.findOne({UUID: req.params.CodiumId})
|
||||||
|
if ( !code ) return res.status(404).message('Unable to find code with that ID.').api({})
|
||||||
|
|
||||||
|
await code.delete()
|
||||||
|
return res.api({})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = FormCode
|
@ -207,6 +207,7 @@ class FormDatabase extends Controller {
|
|||||||
|
|
||||||
await DBEntry.deleteMany({DatabaseId: db.UUID})
|
await DBEntry.deleteMany({DatabaseId: db.UUID})
|
||||||
await db.delete()
|
await db.delete()
|
||||||
|
return res.api({})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -249,6 +249,7 @@ class Page extends Controller {
|
|||||||
page = await PageModel.findOne({UUID: PageId})
|
page = await PageModel.findOne({UUID: PageId})
|
||||||
if ( !page ) return res.status(404).message('Page not found with that ID.').api({})
|
if ( !page ) return res.status(404).message('Page not found with that ID.').api({})
|
||||||
if ( !page.accessible_by(req.user, 'update') ) return req.security.deny()
|
if ( !page.accessible_by(req.user, 'update') ) return req.security.deny()
|
||||||
|
if ( page.ParentId === '0' ) return req.security.kickout()
|
||||||
}
|
}
|
||||||
|
|
||||||
page.Active = false
|
page.Active = false
|
||||||
|
24
app/models/api/Codium.model.js
Normal file
24
app/models/api/Codium.model.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const Model = require('flitter-orm/src/model/Model')
|
||||||
|
const uuid = require('uuid/v4')
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Codium Model
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* Put some description here!
|
||||||
|
*/
|
||||||
|
class Codium extends Model {
|
||||||
|
static get schema() {
|
||||||
|
// Return a flitter-orm schema here.
|
||||||
|
return {
|
||||||
|
language: {type: String, default: 'javascript'},
|
||||||
|
NodeId: String,
|
||||||
|
PageId: String,
|
||||||
|
code: String,
|
||||||
|
UUID: { type: String, default: () => uuid() },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static and instance methods can go here
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = Codium
|
@ -44,6 +44,8 @@ const index = {
|
|||||||
'/db/:PageId/:NodeId/get/:DatabaseId': ['controller::api:v1:FormDatabase.get_config'],
|
'/db/:PageId/:NodeId/get/:DatabaseId': ['controller::api:v1:FormDatabase.get_config'],
|
||||||
'/db/:PageId/:NodeId/get/:DatabaseId/columns': [ 'controller::api:v1:FormDatabase.get_columns' ],
|
'/db/:PageId/:NodeId/get/:DatabaseId/columns': [ 'controller::api:v1:FormDatabase.get_columns' ],
|
||||||
'/db/:PageId/:NodeId/get/:DatabaseId/data': [ 'controller::api:v1:FormDatabase.get_data' ],
|
'/db/:PageId/:NodeId/get/:DatabaseId/data': [ 'controller::api:v1:FormDatabase.get_data' ],
|
||||||
|
|
||||||
|
'/code/:PageId/:NodeId/get/:CodiumId': ['controller::api:v1:FormCode.get_config'],
|
||||||
},
|
},
|
||||||
|
|
||||||
post: {
|
post: {
|
||||||
@ -57,6 +59,10 @@ const index = {
|
|||||||
'/db/:PageId/:NodeId/set/:DatabaseId/columns': [ 'controller::api:v1:FormDatabase.set_columns' ],
|
'/db/:PageId/:NodeId/set/:DatabaseId/columns': [ 'controller::api:v1:FormDatabase.set_columns' ],
|
||||||
'/db/:PageId/:NodeId/drop/:DatabaseId': [ 'controller::api:v1:FormDatabase.drop_database' ],
|
'/db/:PageId/:NodeId/drop/:DatabaseId': [ 'controller::api:v1:FormDatabase.drop_database' ],
|
||||||
'/db/:PageId/:NodeId/set/:DatabaseId/data': ['controller::api:v1:FormDatabase.set_data'],
|
'/db/:PageId/:NodeId/set/:DatabaseId/data': ['controller::api:v1:FormDatabase.set_data'],
|
||||||
|
|
||||||
|
'/code/:PageId/:NodeId/create': ['controller::api:v1:FormCode.create_new'],
|
||||||
|
'/code/:PageId/:NodeId/set/:CodiumId': ['controller::api:v1:FormCode.set_values'],
|
||||||
|
'/code/:PageId/:NodeId/delete/:CodiumId': ['controller::api:v1:FormCode.drop_code'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user