Pull out schema fetching, as some times we fetch schemas when we don't actually have a handler for the type.

This commit is contained in:
Rob 2015-11-12 15:01:33 -05:00
parent 234d1b5950
commit 836a01d1a8
2 changed files with 6 additions and 1 deletions

View file

@ -42,6 +42,7 @@ module.exports.handlerUrlOverrides =
'level_session': 'level.session'
'level_system': 'level.system'
'thang_type': 'thang.type'
'thang_component': 'thang.component'
'user_code_problem': 'user.code.problem'
'user_remark': 'user.remark'
'mail_sent': 'mail.sent'

View file

@ -26,7 +26,7 @@ module.exports.setup = (app) ->
parts = req.path[4..].split('/')
return getSchema(req, res, module) if parts[1] is 'schema'
if (not req.user) and req.route.method isnt 'get'
return errors.unauthorized(res, 'Must have an identity to do anything with the db. Do you have cookies enabled?')
@ -56,6 +56,10 @@ module.exports.setup = (app) ->
app.all '/db/' + moduleName + '/*', routeHandler
app.all '/db/' + moduleName, routeHandler
app.get '/db/:module/schema', (req, res) ->
res.setHeader('Content-Type', 'application/json')
getSchema req, res, req.params.module
for moduleNameUnder of handlers
name = handlers[moduleNameUnder]
moduleName = handlerUrlOverrides[moduleNameUnder] or moduleNameUnder