diff options
author | Sheogorath | 2019-11-20 20:07:35 +0100 |
---|---|---|
committer | GitHub | 2019-11-20 20:07:35 +0100 |
commit | 689f5a0a9583fdd774a271a9e6265ee5356d72a0 (patch) | |
tree | 754bed08f4724a4bc4f91743f6dfe12f92857c01 /lib/history.js | |
parent | f894d3c2fa29865288a31cd80cd2a772ce44b330 (diff) | |
parent | b5ccceff59002034fbb089935076f40b8aa16e58 (diff) |
Merge pull request #213 from davidmehren/refactor_backend_notes
First steps in refactoring the backend code
Diffstat (limited to 'lib/history.js')
-rw-r--r-- | lib/history.js | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/history.js b/lib/history.js index 88a7ee05..3ebf77fd 100644 --- a/lib/history.js +++ b/lib/history.js @@ -5,8 +5,8 @@ var LZString = require('lz-string') // core var logger = require('./logger') -var response = require('./response') var models = require('./models') +const errors = require('./errors') // public var History = { @@ -121,14 +121,14 @@ function parseHistoryToObject (history) { function historyGet (req, res) { if (req.isAuthenticated()) { getHistory(req.user.id, function (err, history) { - if (err) return response.errorInternalError(res) - if (!history) return response.errorNotFound(res) + if (err) return errors.errorInternalError(res) + if (!history) return errors.errorNotFound(res) res.send({ history: parseHistoryToArray(history) }) }) } else { - return response.errorForbidden(res) + return errors.errorForbidden(res) } } @@ -136,40 +136,40 @@ function historyPost (req, res) { if (req.isAuthenticated()) { var noteId = req.params.noteId if (!noteId) { - if (typeof req.body['history'] === 'undefined') return response.errorBadRequest(res) + if (typeof req.body['history'] === 'undefined') return errors.errorBadRequest(res) logger.debug(`SERVER received history from [${req.user.id}]: ${req.body.history}`) try { var history = JSON.parse(req.body.history) } catch (err) { - return response.errorBadRequest(res) + return errors.errorBadRequest(res) } if (Array.isArray(history)) { setHistory(req.user.id, history, function (err, count) { - if (err) return response.errorInternalError(res) + if (err) return errors.errorInternalError(res) res.end() }) } else { - return response.errorBadRequest(res) + return errors.errorBadRequest(res) } } else { - if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(res) + if (typeof req.body['pinned'] === 'undefined') return errors.errorBadRequest(res) getHistory(req.user.id, function (err, history) { - if (err) return response.errorInternalError(res) - if (!history) return response.errorNotFound(res) - if (!history[noteId]) return response.errorNotFound(res) + if (err) return errors.errorInternalError(res) + if (!history) return errors.errorNotFound(res) + if (!history[noteId]) return errors.errorNotFound(res) if (req.body.pinned === 'true' || req.body.pinned === 'false') { history[noteId].pinned = (req.body.pinned === 'true') setHistory(req.user.id, history, function (err, count) { - if (err) return response.errorInternalError(res) + if (err) return errors.errorInternalError(res) res.end() }) } else { - return response.errorBadRequest(res) + return errors.errorBadRequest(res) } }) } } else { - return response.errorForbidden(res) + return errors.errorForbidden(res) } } @@ -178,22 +178,22 @@ function historyDelete (req, res) { var noteId = req.params.noteId if (!noteId) { setHistory(req.user.id, [], function (err, count) { - if (err) return response.errorInternalError(res) + if (err) return errors.errorInternalError(res) res.end() }) } else { getHistory(req.user.id, function (err, history) { - if (err) return response.errorInternalError(res) - if (!history) return response.errorNotFound(res) + if (err) return errors.errorInternalError(res) + if (!history) return errors.errorNotFound(res) delete history[noteId] setHistory(req.user.id, history, function (err, count) { - if (err) return response.errorInternalError(res) + if (err) return errors.errorInternalError(res) res.end() }) }) } } else { - return response.errorForbidden(res) + return errors.errorForbidden(res) } } |