mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 03:58:02 -05:00
Fix note history updating 🐛
a7aaded6
started to use a Map for a users note history in various places, but didn't update the code to actually use the Map operations. This broke updating the note history.
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
f208f3eeef
commit
280fda1d6c
1 changed files with 12 additions and 13 deletions
|
@ -10,12 +10,12 @@ import { LogEntry } from 'winston'
|
||||||
|
|
||||||
// public
|
// public
|
||||||
|
|
||||||
type HistoryObject = {
|
class HistoryObject {
|
||||||
id: string;
|
id: string
|
||||||
text: string;
|
text: string
|
||||||
time: number;
|
time: number
|
||||||
tags: string[];
|
tags: string[]
|
||||||
pinned?: boolean;
|
pinned?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseHistoryMapToArray (historyMap: Map<string, HistoryObject>): HistoryObject[] {
|
function parseHistoryMapToArray (historyMap: Map<string, HistoryObject>): HistoryObject[] {
|
||||||
|
@ -101,15 +101,13 @@ function updateHistory (userId: string, noteId: string, document, time): void {
|
||||||
if (userId && noteId && typeof document !== 'undefined') {
|
if (userId && noteId && typeof document !== 'undefined') {
|
||||||
getHistory(userId, function (err, history) {
|
getHistory(userId, function (err, history) {
|
||||||
if (err || !history) return
|
if (err || !history) return
|
||||||
if (!history[noteId]) {
|
const noteHistory = history.get(noteId) || new HistoryObject()
|
||||||
history[noteId] = {}
|
|
||||||
}
|
|
||||||
const noteHistory = history[noteId]
|
|
||||||
const noteInfo = Note.parseNoteInfo(document)
|
const noteInfo = Note.parseNoteInfo(document)
|
||||||
noteHistory.id = noteId
|
noteHistory.id = noteId
|
||||||
noteHistory.text = noteInfo.title
|
noteHistory.text = noteInfo.title
|
||||||
noteHistory.time = time || Date.now()
|
noteHistory.time = time || Date.now()
|
||||||
noteHistory.tags = noteInfo.tags
|
noteHistory.tags = noteInfo.tags
|
||||||
|
history.set(noteId, noteHistory)
|
||||||
setHistory(userId, parseHistoryMapToArray(history), function (err, _) {
|
setHistory(userId, parseHistoryMapToArray(history), function (err, _) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.log(err)
|
logger.log(err)
|
||||||
|
@ -158,9 +156,10 @@ function historyPost (req, res): void {
|
||||||
getHistory(req.user.id, function (err, history) {
|
getHistory(req.user.id, function (err, history) {
|
||||||
if (err) return errors.errorInternalError(res)
|
if (err) return errors.errorInternalError(res)
|
||||||
if (!history) return errors.errorNotFound(res)
|
if (!history) return errors.errorNotFound(res)
|
||||||
if (!history[noteId]) return errors.errorNotFound(res)
|
const noteHistory = history.get(noteId)
|
||||||
|
if (!noteHistory) return errors.errorNotFound(res)
|
||||||
if (req.body.pinned === 'true' || req.body.pinned === 'false') {
|
if (req.body.pinned === 'true' || req.body.pinned === 'false') {
|
||||||
history[noteId].pinned = (req.body.pinned === 'true')
|
noteHistory.pinned = (req.body.pinned === 'true')
|
||||||
setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) {
|
setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) {
|
||||||
if (err) return errors.errorInternalError(res)
|
if (err) return errors.errorInternalError(res)
|
||||||
res.end()
|
res.end()
|
||||||
|
@ -187,7 +186,7 @@ function historyDelete (req, res): void {
|
||||||
getHistory(req.user.id, function (err, history) {
|
getHistory(req.user.id, function (err, history) {
|
||||||
if (err) return errors.errorInternalError(res)
|
if (err) return errors.errorInternalError(res)
|
||||||
if (!history) return errors.errorNotFound(res)
|
if (!history) return errors.errorNotFound(res)
|
||||||
delete history[noteId]
|
history.delete(noteId)
|
||||||
setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) {
|
setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) {
|
||||||
if (err) return errors.errorInternalError(res)
|
if (err) return errors.errorInternalError(res)
|
||||||
res.end()
|
res.end()
|
||||||
|
|
Loading…
Reference in a new issue