Add endpoint for setting database name (Noded/frontend#16)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-10-13 10:09:23 -05:00
parent 2a5e3419e8
commit a0b5003087
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 31 additions and 0 deletions

View File

@ -94,6 +94,34 @@ class FormDatabase extends Controller {
return res.api(columns) 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) { async set_columns(req, res) {
const PageId = req.params.PageId const PageId = req.params.PageId

View File

@ -80,6 +80,9 @@ const index = {
// Set the column configs for a database ref // Set the column configs for a database ref
'/db/:PageId/:NodeId/set/:DatabaseId/columns': [ 'controller::api:v1:FormDatabase.set_columns' ], '/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 // Delete the specified database ref
'/db/:PageId/:NodeId/drop/:DatabaseId': [ 'controller::api:v1:FormDatabase.drop_database' ], '/db/:PageId/:NodeId/drop/:DatabaseId': [ 'controller::api:v1:FormDatabase.drop_database' ],