2017-09-27 04:37:20 -04:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
2017-11-27 12:09:51 -05:00
|
|
|
bodyParser = require "body-parser"
|
|
|
|
jsonParser = bodyParser.json()
|
2017-09-27 04:37:20 -04:00
|
|
|
|
|
|
|
module.exports = MockDocUpdaterApi =
|
2017-11-29 06:07:49 -05:00
|
|
|
updates: {}
|
2017-11-27 12:09:51 -05:00
|
|
|
|
|
|
|
clearProjectStructureUpdates: () ->
|
2017-11-29 06:07:49 -05:00
|
|
|
@updates = {}
|
2017-11-27 12:09:51 -05:00
|
|
|
|
|
|
|
getProjectStructureUpdates: (project_id) ->
|
2017-11-29 06:07:49 -05:00
|
|
|
@updates[project_id] || { docUpdates: [], fileUpdates: [] }
|
2017-11-27 12:09:51 -05:00
|
|
|
|
|
|
|
addProjectStructureUpdates: (project_id, userId, docUpdates, fileUpdates) ->
|
2017-11-29 06:07:49 -05:00
|
|
|
@updates[project_id] ||= { docUpdates: [], fileUpdates: [] }
|
|
|
|
|
2017-11-27 12:09:51 -05:00
|
|
|
for update in docUpdates
|
|
|
|
update.userId = userId
|
2017-11-29 06:07:49 -05:00
|
|
|
@updates[project_id].docUpdates.push(update)
|
2017-11-27 12:09:51 -05:00
|
|
|
|
|
|
|
for update in fileUpdates
|
|
|
|
update.userId = userId
|
2017-11-29 06:07:49 -05:00
|
|
|
@updates[project_id].fileUpdates.push(update)
|
2017-11-27 12:09:51 -05:00
|
|
|
|
2017-09-27 04:37:20 -04:00
|
|
|
run: () ->
|
|
|
|
app.post "/project/:project_id/flush", (req, res, next) =>
|
|
|
|
res.sendStatus 200
|
|
|
|
|
2017-11-27 12:09:51 -05:00
|
|
|
app.post "/project/:project_id", jsonParser, (req, res, next) =>
|
|
|
|
project_id = req.params.project_id
|
|
|
|
{userId, docUpdates, fileUpdates} = req.body
|
|
|
|
@addProjectStructureUpdates(project_id, userId, docUpdates, fileUpdates)
|
|
|
|
res.sendStatus 200
|
|
|
|
|
2017-12-14 11:03:57 -05:00
|
|
|
app.delete "/project/:project_id/doc/:doc_id", (req, res, next) =>
|
|
|
|
res.send 204
|
|
|
|
|
2017-09-27 04:37:20 -04:00
|
|
|
app.listen 3003, (error) ->
|
|
|
|
throw error if error?
|
2017-10-20 10:31:10 -04:00
|
|
|
.on "error", (error) ->
|
|
|
|
console.error "error starting MockDocUpdaterApi:", error.message
|
|
|
|
process.exit(1)
|
2017-09-27 04:37:20 -04:00
|
|
|
|
|
|
|
MockDocUpdaterApi.run()
|