2017-09-27 08:37:20 +00:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
2017-11-27 17:09:51 +00:00
|
|
|
bodyParser = require "body-parser"
|
|
|
|
jsonParser = bodyParser.json()
|
2017-09-27 08:37:20 +00:00
|
|
|
|
|
|
|
module.exports = MockDocUpdaterApi =
|
2017-11-29 11:07:49 +00:00
|
|
|
updates: {}
|
2017-11-27 17:09:51 +00:00
|
|
|
|
|
|
|
clearProjectStructureUpdates: () ->
|
2017-11-29 11:07:49 +00:00
|
|
|
@updates = {}
|
2017-11-27 17:09:51 +00:00
|
|
|
|
|
|
|
getProjectStructureUpdates: (project_id) ->
|
2017-11-29 11:07:49 +00:00
|
|
|
@updates[project_id] || { docUpdates: [], fileUpdates: [] }
|
2017-11-27 17:09:51 +00:00
|
|
|
|
|
|
|
addProjectStructureUpdates: (project_id, userId, docUpdates, fileUpdates) ->
|
2017-11-29 11:07:49 +00:00
|
|
|
@updates[project_id] ||= { docUpdates: [], fileUpdates: [] }
|
|
|
|
|
2017-11-27 17:09:51 +00:00
|
|
|
for update in docUpdates
|
|
|
|
update.userId = userId
|
2017-11-29 11:07:49 +00:00
|
|
|
@updates[project_id].docUpdates.push(update)
|
2017-11-27 17:09:51 +00:00
|
|
|
|
|
|
|
for update in fileUpdates
|
|
|
|
update.userId = userId
|
2017-11-29 11:07:49 +00:00
|
|
|
@updates[project_id].fileUpdates.push(update)
|
2017-11-27 17:09:51 +00:00
|
|
|
|
2017-09-27 08:37:20 +00:00
|
|
|
run: () ->
|
|
|
|
app.post "/project/:project_id/flush", (req, res, next) =>
|
|
|
|
res.sendStatus 200
|
|
|
|
|
2017-11-27 17:09:51 +00: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-09-27 08:37:20 +00:00
|
|
|
app.listen 3003, (error) ->
|
|
|
|
throw error if error?
|
2017-10-20 14:31:10 +00:00
|
|
|
.on "error", (error) ->
|
|
|
|
console.error "error starting MockDocUpdaterApi:", error.message
|
|
|
|
process.exit(1)
|
2017-09-27 08:37:20 +00:00
|
|
|
|
|
|
|
MockDocUpdaterApi.run()
|