fix: history api failed cause by circular dependency

Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
BoHong Li 2019-08-05 03:51:00 +08:00
parent 18abc20f39
commit 6c968f9622
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
2 changed files with 38 additions and 46 deletions

View File

@ -9,14 +9,6 @@ var logger = require('./logger')
var response = require('./response') var response = require('./response')
var models = require('./models') var models = require('./models')
// public
var History = {
historyGet: historyGet,
historyPost: historyPost,
historyDelete: historyDelete,
updateHistory: updateHistory
}
function getHistory (userid, callback) { function getHistory (userid, callback) {
models.User.findOne({ models.User.findOne({
where: { where: {
@ -200,4 +192,8 @@ function historyDelete (req, res) {
} }
} }
module.exports = History // public
exports.historyGet = historyGet
exports.historyPost = historyPost
exports.historyDelete = historyDelete
exports.updateHistory = updateHistory

View File

@ -17,42 +17,40 @@ var utils = require('./utils')
var history = require('./history') var history = require('./history')
// public // public
var response = { exports.errorForbidden = function (res) {
errorForbidden: function (res) { const { req } = res
const { req } = res if (req.user) {
if (req.user) { responseError(res, '403', 'Forbidden', 'oh no.')
responseError(res, '403', 'Forbidden', 'oh no.') } else {
} else { req.flash('error', 'You are not allowed to access this page. Maybe try logging in?')
req.flash('error', 'You are not allowed to access this page. Maybe try logging in?') res.redirect(config.serverURL + '/')
res.redirect(config.serverURL + '/') }
}
},
errorNotFound: function (res) {
responseError(res, '404', 'Not Found', 'oops.')
},
errorBadRequest: function (res) {
responseError(res, '400', 'Bad Request', 'something not right.')
},
errorTooLong: function (res) {
responseError(res, '413', 'Payload Too Large', 'Shorten your note!')
},
errorInternalError: function (res) {
responseError(res, '500', 'Internal Error', 'wtf.')
},
errorServiceUnavailable: function (res) {
res.status(503).send("I'm busy right now, try again later.")
},
newNote: newNote,
showNote: showNote,
showPublishNote: showPublishNote,
showPublishSlide: showPublishSlide,
showIndex: showIndex,
noteActions: noteActions,
publishNoteActions: publishNoteActions,
publishSlideActions: publishSlideActions,
githubActions: githubActions,
gitlabActions: gitlabActions
} }
exports.errorNotFound = function (res) {
responseError(res, '404', 'Not Found', 'oops.')
}
exports.errorBadRequest = function (res) {
responseError(res, '400', 'Bad Request', 'something not right.')
}
exports.errorTooLong = function (res) {
responseError(res, '413', 'Payload Too Large', 'Shorten your note!')
}
exports.errorInternalError = function (res) {
responseError(res, '500', 'Internal Error', 'wtf.')
}
exports.errorServiceUnavailable = function (res) {
res.status(503).send("I'm busy right now, try again later.")
}
exports.newNote = newNote
exports.showNote = showNote
exports.showPublishNote = showPublishNote
exports.showPublishSlide = showPublishSlide
exports.showIndex = showIndex
exports.noteActions = noteActions
exports.publishNoteActions = publishNoteActions
exports.publishSlideActions = publishSlideActions
exports.githubActions = githubActions
exports.gitlabActions = gitlabActions
function responseError (res, code, detail, msg) { function responseError (res, code, detail, msg) {
res.status(code).render('error.ejs', { res.status(code).render('error.ejs', {
@ -635,5 +633,3 @@ function renderPublishSlide (data, res) {
}) })
res.render('slide.ejs', data) res.render('slide.ejs', data)
} }
module.exports = response