2020-02-17 12:35:50 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
handle-callback-err,
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:35:39 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
let MockDocUpdaterApi;
|
|
|
|
const express = require("express");
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
module.exports = (MockDocUpdaterApi = {
|
|
|
|
docs: {},
|
|
|
|
|
|
|
|
getDoc(project_id, doc_id, callback) {
|
|
|
|
if (callback == null) { callback = function(error) {}; }
|
|
|
|
return callback(null, this.docs[doc_id]);
|
|
|
|
},
|
|
|
|
|
|
|
|
setDoc(project_id, doc_id, lines, user_id, undoing, callback) {
|
|
|
|
if (callback == null) { callback = function(error) {}; }
|
|
|
|
if (!this.docs[doc_id]) { this.docs[doc_id] = {}; }
|
|
|
|
this.docs[doc_id].lines = lines;
|
|
|
|
return callback();
|
|
|
|
},
|
|
|
|
|
|
|
|
run() {
|
|
|
|
app.get("/project/:project_id/doc/:doc_id", (req, res, next) => {
|
2020-02-17 12:35:50 -05:00
|
|
|
return this.getDoc(req.params.project_id, req.params.doc_id, (error, doc) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
if (error != null) {
|
|
|
|
res.send(500);
|
|
|
|
}
|
|
|
|
if ((doc == null)) {
|
|
|
|
return res.send(404);
|
|
|
|
} else {
|
|
|
|
return res.send(JSON.stringify(doc));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post("/project/:project_id/doc/:doc_id", express.bodyParser(), (req, res, next) => {
|
2020-02-17 12:35:50 -05:00
|
|
|
return this.setDoc(req.params.project_id, req.params.doc_id, req.body.lines, req.body.user_id, req.body.undoing, (errr, doc) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
if (typeof error !== 'undefined' && error !== null) {
|
|
|
|
return res.send(500);
|
|
|
|
} else {
|
|
|
|
return res.send(204);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-17 12:35:50 -05:00
|
|
|
return app.listen(3003, (error) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
if (error != null) { throw error; }
|
2020-02-17 12:35:50 -05:00
|
|
|
}).on("error", (error) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
console.error("error starting MockDocUpdaterApi:", error.message);
|
|
|
|
return process.exit(1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
MockDocUpdaterApi.run();
|
2014-03-04 10:27:03 -05:00
|
|
|
|