summaryrefslogtreecommitdiff
path: root/lib/history.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/history.js')
-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)
}
}