summaryrefslogtreecommitdiff
path: root/lib/history.js
diff options
context:
space:
mode:
authorDavid Mehren2019-10-27 13:51:53 +0100
committerDavid Mehren2019-10-27 13:51:53 +0100
commitf78540c3fbf109d6ccf2d92c5b1cf0148c88f722 (patch)
tree7f8b968b925b8b262cca0f4cd180027abc4b745e /lib/history.js
parent20a67e3446723231961043bffeb5a7b974e891c0 (diff)
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 <dmehren1@gmail.com>
Diffstat (limited to '')
-rw-r--r--lib/history.js40
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)
}
}