Merge pull request #1179 from cdancette/update-history-on-creation

Update history on note creation
This commit is contained in:
Raccoon 2019-04-15 13:26:30 +08:00 committed by GitHub
commit 43c0bff8c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -14,6 +14,7 @@ var config = require('./config')
var logger = require('./logger') var logger = require('./logger')
var models = require('./models') var models = require('./models')
var utils = require('./utils') var utils = require('./utils')
var history = require('./history')
// public // public
var response = { var response = {
@ -106,6 +107,12 @@ function responseCodiMD (res, note) {
}) })
} }
function updateHistory (userId, note, document, time) {
var noteId = note.alias ? note.alias : models.Note.encodeNoteId(note.id)
history.updateHistory(userId, noteId, document, time)
logger.info("history updated")
}
function newNote (req, res, next) { function newNote (req, res, next) {
var owner = null var owner = null
var body = '' var body = ''
@ -125,6 +132,11 @@ function newNote (req, res, next) {
alias: req.alias ? req.alias : null, alias: req.alias ? req.alias : null,
content: body content: body
}).then(function (note) { }).then(function (note) {
if (req.isAuthenticated()) {
updateHistory(owner, note, body);
}
return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id)) return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id))
}).catch(function (err) { }).catch(function (err) {
logger.error(err) logger.error(err)