diff --git a/services/document-updater/app/js/HttpController.js b/services/document-updater/app/js/HttpController.js index 8c2501fdbe..800aee4c44 100644 --- a/services/document-updater/app/js/HttpController.js +++ b/services/document-updater/app/js/HttpController.js @@ -2,13 +2,6 @@ camelcase, handle-callback-err, */ -// TODO: This file was created by bulk-decaffeinate. -// Fix any style issues and re-enable lint. -/* - * decaffeinate suggestions: - * DS207: Consider shorter variations of null checks - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ let HttpController const DocumentManager = require('./DocumentManager') const HistoryManager = require('./HistoryManager') @@ -25,15 +18,12 @@ const TWO_MEGABYTES = 2 * 1024 * 1024 module.exports = HttpController = { getDoc(req, res, next) { let fromVersion - if (next == null) { - next = function (error) {} - } const { doc_id } = req.params const { project_id } = req.params logger.log({ project_id, doc_id }, 'getting doc via http') const timer = new Metrics.Timer('http.getDoc') - if ((req.query != null ? req.query.fromVersion : undefined) != null) { + if (req.query.fromVersion != null) { fromVersion = parseInt(req.query.fromVersion, 10) } else { fromVersion = -1 @@ -45,7 +35,7 @@ module.exports = HttpController = { fromVersion, function (error, lines, version, ops, ranges, pathname) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log({ project_id, doc_id }, 'got doc via http') @@ -73,11 +63,8 @@ module.exports = HttpController = { }, getProjectDocsAndFlushIfOld(req, res, next) { - if (next == null) { - next = function (error) {} - } const { project_id } = req.params - const projectStateHash = req.query != null ? req.query.state : undefined + const projectStateHash = req.query.state // exclude is string of existing docs "id:version,id:version,..." const excludeItems = req.query.exclude != null ? req.query.exclude.split(',') : [] @@ -100,7 +87,7 @@ module.exports = HttpController = { timer.done() if (error instanceof Errors.ProjectStateChangedError) { res.sendStatus(409) // conflict - } else if (error != null) { + } else if (error) { next(error) } else { logger.log( @@ -117,15 +104,12 @@ module.exports = HttpController = { }, clearProjectState(req, res, next) { - if (next == null) { - next = function (error) {} - } const { project_id } = req.params const timer = new Metrics.Timer('http.clearProjectState') logger.log({ project_id }, 'clearing project state via http') ProjectManager.clearProjectState(project_id, function (error) { timer.done() - if (error != null) { + if (error) { next(error) } else { res.sendStatus(200) @@ -134,9 +118,6 @@ module.exports = HttpController = { }, setDoc(req, res, next) { - if (next == null) { - next = function (error) {} - } const { doc_id } = req.params const { project_id } = req.params const { lines, source, user_id, undoing } = req.body @@ -162,7 +143,7 @@ module.exports = HttpController = { undoing, function (error) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log({ project_id, doc_id }, 'set doc via http') @@ -172,9 +153,6 @@ module.exports = HttpController = { }, // No Content flushDocIfLoaded(req, res, next) { - if (next == null) { - next = function (error) {} - } const { doc_id } = req.params const { project_id } = req.params logger.log({ project_id, doc_id }, 'flushing doc via http') @@ -183,7 +161,7 @@ module.exports = HttpController = { error ) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log({ project_id, doc_id }, 'flushed doc via http') @@ -192,9 +170,6 @@ module.exports = HttpController = { }, // No Content deleteDoc(req, res, next) { - if (next == null) { - next = function (error) {} - } const { doc_id } = req.params const { project_id } = req.params const ignoreFlushErrors = req.query.ignore_flush_errors === 'true' @@ -210,7 +185,7 @@ module.exports = HttpController = { // failed and sometimes it is required HistoryManager.flushProjectChangesAsync(project_id) - if (error != null) { + if (error) { return next(error) } logger.log({ project_id, doc_id }, 'deleted doc via http') @@ -220,15 +195,12 @@ module.exports = HttpController = { }, // No Content flushProject(req, res, next) { - if (next == null) { - next = function (error) {} - } const { project_id } = req.params logger.log({ project_id }, 'flushing project via http') const timer = new Metrics.Timer('http.flushProject') ProjectManager.flushProjectWithLocks(project_id, function (error) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log({ project_id }, 'flushed project via http') @@ -237,21 +209,18 @@ module.exports = HttpController = { }, // No Content deleteProject(req, res, next) { - if (next == null) { - next = function (error) {} - } const { project_id } = req.params logger.log({ project_id }, 'deleting project via http') const options = {} - if (req.query != null ? req.query.background : undefined) { + if (req.query.background) { options.background = true } // allow non-urgent flushes to be queued - if (req.query != null ? req.query.shutdown : undefined) { + if (req.query.shutdown) { options.skip_history_flush = true } // don't flush history when realtime shuts down - if (req.query != null ? req.query.background : undefined) { + if (req.query.background) { ProjectManager.queueFlushAndDeleteProject(project_id, function (error) { - if (error != null) { + if (error) { return next(error) } logger.log({ project_id }, 'queue delete of project via http') @@ -264,7 +233,7 @@ module.exports = HttpController = { options, function (error) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log({ project_id }, 'deleted project via http') @@ -275,11 +244,7 @@ module.exports = HttpController = { }, // No Content deleteMultipleProjects(req, res, next) { - if (next == null) { - next = function (error) {} - } - const project_ids = - (req.body != null ? req.body.project_ids : undefined) || [] + const project_ids = req.body.project_ids || [] logger.log({ project_ids }, 'deleting multiple projects via http') async.eachSeries( project_ids, @@ -288,7 +253,7 @@ module.exports = HttpController = { ProjectManager.queueFlushAndDeleteProject(project_id, cb) }, function (error) { - if (error != null) { + if (error) { return next(error) } res.sendStatus(204) @@ -297,11 +262,8 @@ module.exports = HttpController = { }, // No Content acceptChanges(req, res, next) { - if (next == null) { - next = function (error) {} - } const { project_id, doc_id } = req.params - let change_ids = req.body != null ? req.body.change_ids : undefined + let change_ids = req.body.change_ids if (change_ids == null) { change_ids = [req.params.change_id] } @@ -316,7 +278,7 @@ module.exports = HttpController = { change_ids, function (error) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log( @@ -329,9 +291,6 @@ module.exports = HttpController = { }, // No Content deleteComment(req, res, next) { - if (next == null) { - next = function (error) {} - } const { project_id, doc_id, comment_id } = req.params logger.log({ project_id, doc_id, comment_id }, 'deleting comment via http') const timer = new Metrics.Timer('http.deleteComment') @@ -341,7 +300,7 @@ module.exports = HttpController = { comment_id, function (error) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log( @@ -354,9 +313,6 @@ module.exports = HttpController = { }, // No Content updateProject(req, res, next) { - if (next == null) { - next = function (error) {} - } const timer = new Metrics.Timer('http.updateProject') const { project_id } = req.params const { @@ -380,7 +336,7 @@ module.exports = HttpController = { version, function (error) { timer.done() - if (error != null) { + if (error) { return next(error) } logger.log({ project_id }, 'updated project via http') @@ -390,9 +346,6 @@ module.exports = HttpController = { }, // No Content resyncProjectHistory(req, res, next) { - if (next == null) { - next = function (error) {} - } const { project_id } = req.params const { projectHistoryId, docs, files } = req.body @@ -406,7 +359,7 @@ module.exports = HttpController = { docs, files, function (error) { - if (error != null) { + if (error) { return next(error) } logger.log({ project_id }, 'queued project history resync via http') @@ -416,9 +369,6 @@ module.exports = HttpController = { }, flushAllProjects(req, res, next) { - if (next == null) { - next = function (error) {} - } res.setTimeout(5 * 60 * 1000) const options = { limit: req.query.limit || 1000, @@ -426,7 +376,7 @@ module.exports = HttpController = { dryRun: req.query.dryRun || false } ProjectFlusher.flushAllProjects(options, function (err, project_ids) { - if (err != null) { + if (err) { logger.err({ err }, 'error bulk flushing projects') res.sendStatus(500) } else { @@ -436,9 +386,6 @@ module.exports = HttpController = { }, flushQueuedProjects(req, res, next) { - if (next == null) { - next = function (error) {} - } res.setTimeout(10 * 60 * 1000) const options = { limit: req.query.limit || 1000, @@ -449,7 +396,7 @@ module.exports = HttpController = { err, flushed ) { - if (err != null) { + if (err) { logger.err({ err }, 'error flushing old projects') res.sendStatus(500) } else {