From f78540c3fbf109d6ccf2d92c5b1cf0148c88f722 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 27 Oct 2019 13:51:53 +0100 Subject: Move note actions to their own file. Because of circular import problems, this commit also moves the error messages from response.js to errors.js Signed-off-by: David Mehren --- lib/history.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'lib/history.js') 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) } } -- cgit v1.2.3