2020-02-17 12:35:50 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
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
|
|
|
|
*/
|
2020-02-17 12:35:59 -05:00
|
|
|
let MockDocUpdaterApi
|
|
|
|
const express = require('express')
|
2020-03-23 06:10:24 -04:00
|
|
|
const bodyParser = require('body-parser')
|
2020-02-17 12:35:59 -05:00
|
|
|
const app = express()
|
2020-03-23 06:10:24 -04:00
|
|
|
app.use(bodyParser.json())
|
2020-02-17 12:35:39 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
module.exports = MockDocUpdaterApi = {
|
|
|
|
docs: {},
|
2020-02-17 12:35:39 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
getDoc(project_id, doc_id, callback) {
|
|
|
|
if (callback == null) {
|
2021-10-27 05:49:18 -04:00
|
|
|
callback = function () {}
|
2020-02-17 12:35:59 -05:00
|
|
|
}
|
|
|
|
return callback(null, this.docs[doc_id])
|
|
|
|
},
|
2020-02-17 12:35:39 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
setDoc(project_id, doc_id, lines, user_id, undoing, callback) {
|
|
|
|
if (callback == null) {
|
2021-10-27 05:49:18 -04:00
|
|
|
callback = function () {}
|
2020-02-17 12:35:59 -05:00
|
|
|
}
|
|
|
|
if (!this.docs[doc_id]) {
|
|
|
|
this.docs[doc_id] = {}
|
|
|
|
}
|
|
|
|
this.docs[doc_id].lines = lines
|
|
|
|
return callback()
|
|
|
|
},
|
2020-02-17 12:35:39 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
run() {
|
|
|
|
app.get('/project/:project_id/doc/:doc_id', (req, res, next) => {
|
|
|
|
return this.getDoc(
|
|
|
|
req.params.project_id,
|
|
|
|
req.params.doc_id,
|
|
|
|
(error, doc) => {
|
|
|
|
if (error != null) {
|
2020-03-23 06:17:32 -04:00
|
|
|
res.sendStatus(500)
|
2020-02-17 12:35:59 -05:00
|
|
|
}
|
|
|
|
if (doc == null) {
|
2020-03-23 06:17:32 -04:00
|
|
|
return res.sendStatus(404)
|
2020-02-17 12:35:59 -05:00
|
|
|
} else {
|
|
|
|
return res.send(JSON.stringify(doc))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2020-02-17 12:35:39 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
app.post('/project/:project_id/doc/:doc_id', (req, res, next) => {
|
|
|
|
return this.setDoc(
|
|
|
|
req.params.project_id,
|
|
|
|
req.params.doc_id,
|
|
|
|
req.body.lines,
|
|
|
|
req.body.user_id,
|
|
|
|
req.body.undoing,
|
|
|
|
(errr, doc) => {
|
|
|
|
if (typeof error !== 'undefined' && error !== null) {
|
|
|
|
return res.sendStatus(500)
|
|
|
|
} else {
|
|
|
|
return res.sendStatus(204)
|
2020-02-17 12:35:59 -05:00
|
|
|
}
|
2020-06-04 04:24:21 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2020-02-17 12:35:39 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
return app
|
2021-07-13 07:04:43 -04:00
|
|
|
.listen(3003, error => {
|
2020-02-17 12:35:59 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
})
|
2021-07-13 07:04:43 -04:00
|
|
|
.on('error', error => {
|
2020-02-17 12:35:59 -05:00
|
|
|
console.error('error starting MockDocUpdaterApi:', error.message)
|
|
|
|
return process.exit(1)
|
|
|
|
})
|
2021-07-13 07:04:43 -04:00
|
|
|
},
|
2020-02-17 12:35:59 -05:00
|
|
|
}
|
2014-03-04 10:27:03 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
MockDocUpdaterApi.run()
|