2014-03-04 15:27:03 +00:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
|
|
|
|
|
|
|
module.exports = MockDocUpdaterApi =
|
|
|
|
docs: {}
|
|
|
|
|
|
|
|
getDoc: (project_id, doc_id, callback = (error) ->) ->
|
|
|
|
callback null, @docs[doc_id]
|
|
|
|
|
2014-03-11 13:01:07 +00:00
|
|
|
setDoc: (project_id, doc_id, lines, user_id, callback = (error) ->) ->
|
2014-03-10 16:58:26 +00:00
|
|
|
@docs[doc_id] ||= {}
|
|
|
|
@docs[doc_id].lines = lines
|
|
|
|
callback()
|
|
|
|
|
2014-03-04 15:27:03 +00:00
|
|
|
run: () ->
|
|
|
|
app.get "/project/:project_id/doc/:doc_id", (req, res, next) =>
|
|
|
|
@getDoc req.params.project_id, req.params.doc_id, (error, doc) ->
|
|
|
|
if error?
|
|
|
|
res.send 500
|
|
|
|
if !doc?
|
|
|
|
res.send 404
|
|
|
|
else
|
|
|
|
res.send JSON.stringify doc
|
|
|
|
|
2014-03-10 16:58:26 +00:00
|
|
|
app.post "/project/:project_id/doc/:doc_id", express.bodyParser(), (req, res, next) =>
|
2014-03-11 13:01:07 +00:00
|
|
|
@setDoc req.params.project_id, req.params.doc_id, req.body.lines, req.body.user_id, (errr, doc) ->
|
2014-03-10 16:58:26 +00:00
|
|
|
if error?
|
|
|
|
res.send 500
|
|
|
|
else
|
|
|
|
res.send 204
|
|
|
|
|
2014-03-04 15:27:03 +00:00
|
|
|
app.listen 3003, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
|
|
|
|
MockDocUpdaterApi.run()
|
|
|
|
|