Permalink
Browse files

implements definition of views

  • Loading branch information...
Raphaël Bleuse
Raphaël Bleuse committed Sep 14, 2012
1 parent fd05d75 commit 4e956ae19de465d43fad8401a49d97caf01821ce
Showing with 24 additions and 2 deletions.
  1. +22 −2 app/controllers/request_controller.coffee
  2. +2 −0 config/routes.coffee
@@ -18,6 +18,26 @@ action 'access', ->
delete value._rev # CouchDB specific, user don't need it
send res
-# PUT /request/:id
+# PUT /request/:req_name
+action 'definition', ->
+ db.get "_design/cozy-request", (err, res) ->
+ if err && err.error is 'not_found'
+ design_doc = {}
+ design_doc[params.req_name] = body
+ db.save "_design/cozy-request", design_doc, (err, res) ->
+ if err
+ console.log "[Definition] err: " + JSON.stringify err
+ send 500
+ else
+ send 200
+ else
+ views = res.views
+ views[params.req_name] = body
+ db.merge "_design/cozy-request", {views:views}, (err, res) ->
+ if err
+ console.log "[Definition] err: " + JSON.stringify err
+ send 500
+ else
+ send 200
-# DELETE /request/:id
+# DELETE /request/:req_name
View
@@ -14,3 +14,5 @@ exports.routes = (map) ->
#Request handling
map.get '/request/:req_name/', 'request#access'
+
+ map.put 'request/:req_name/', 'request#definition'

0 comments on commit 4e956ae

Please sign in to comment.