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
|
|
|
|
2018-02-27 11:58:30 +00:00
|
|
|
addProjectStructureUpdates: (project_id, userId, docUpdates, fileUpdates, version) ->
|
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)
|
2018-02-27 11:58:30 +00:00
|
|
|
|
|
|
|
@updates[project_id].version = version
|
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
|
2018-02-27 11:58:30 +00:00
|
|
|
{userId, docUpdates, fileUpdates, version} = req.body
|
|
|
|
@addProjectStructureUpdates(project_id, userId, docUpdates, fileUpdates, version)
|
2017-11-27 17:09:51 +00:00
|
|
|
res.sendStatus 200
|
|
|
|
|
2017-12-14 16:03:57 +00:00
|
|
|
app.delete "/project/:project_id/doc/:doc_id", (req, res, next) =>
|
2018-03-16 12:21:07 +00:00
|
|
|
res.sendStatus 204
|
2017-12-14 16:03:57 +00:00
|
|
|
|
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()
|