Add endpoint for setting database name (Noded/frontend#16)
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:
parent
2a5e3419e8
commit
a0b5003087
@ -94,6 +94,34 @@ class FormDatabase extends Controller {
|
||||
return res.api(columns)
|
||||
}
|
||||
|
||||
async set_name(req, res) {
|
||||
if ( !req.body.Name ) {
|
||||
return res.status(400)
|
||||
.message('Missing required field: Name')
|
||||
.api()
|
||||
}
|
||||
|
||||
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 ( !(await page.is_accessible_by(req.user, 'update')) ) 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 DatabaseId = req.params.DatabaseId
|
||||
const db = await Database.findOne({UUID: DatabaseId})
|
||||
if ( !db ) return res.status(404).message('Database not found with that ID.').api({})
|
||||
// if ( !db.accessible_by(req.user, 'update') ) return req.security.deny()
|
||||
|
||||
db.Name = req.body.Name
|
||||
await db.save()
|
||||
return res.api(db)
|
||||
}
|
||||
|
||||
async set_columns(req, res) {
|
||||
const PageId = req.params.PageId
|
||||
|
||||
|
@ -80,6 +80,9 @@ const index = {
|
||||
// Set the column configs for a database ref
|
||||
'/db/:PageId/:NodeId/set/:DatabaseId/columns': [ 'controller::api:v1:FormDatabase.set_columns' ],
|
||||
|
||||
// Set the database name
|
||||
'/db/:PageId/:NodeId/set/:DatabaseId/Name': [ 'controller::api:v1:FormDatabase.set_name' ],
|
||||
|
||||
// Delete the specified database ref
|
||||
'/db/:PageId/:NodeId/drop/:DatabaseId': [ 'controller::api:v1:FormDatabase.drop_database' ],
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user