From 280fda1d6c23da1aa2a7baadca8f686a582e733d Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 24 May 2020 20:54:56 +0200 Subject: [PATCH] Fix note history updating :bug: 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 --- src/lib/history.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/lib/history.ts b/src/lib/history.ts index 694900a78..6bc8ad4fb 100644 --- a/src/lib/history.ts +++ b/src/lib/history.ts @@ -10,12 +10,12 @@ import { LogEntry } from 'winston' // public -type HistoryObject = { - id: string; - text: string; - time: number; - tags: string[]; - pinned?: boolean; +class HistoryObject { + id: string + text: string + time: number + tags: string[] + pinned?: boolean } function parseHistoryMapToArray (historyMap: Map): HistoryObject[] { @@ -101,15 +101,13 @@ function updateHistory (userId: string, noteId: string, document, time): void { if (userId && noteId && typeof document !== 'undefined') { getHistory(userId, function (err, history) { if (err || !history) return - if (!history[noteId]) { - history[noteId] = {} - } - const noteHistory = history[noteId] + const noteHistory = history.get(noteId) || new HistoryObject() const noteInfo = Note.parseNoteInfo(document) noteHistory.id = noteId noteHistory.text = noteInfo.title noteHistory.time = time || Date.now() noteHistory.tags = noteInfo.tags + history.set(noteId, noteHistory) setHistory(userId, parseHistoryMapToArray(history), function (err, _) { if (err) { logger.log(err) @@ -158,9 +156,10 @@ function historyPost (req, res): void { getHistory(req.user.id, function (err, history) { if (err) return errors.errorInternalError(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') { - history[noteId].pinned = (req.body.pinned === 'true') + noteHistory.pinned = (req.body.pinned === 'true') setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) { if (err) return errors.errorInternalError(res) res.end() @@ -187,7 +186,7 @@ function historyDelete (req, res): void { getHistory(req.user.id, function (err, history) { if (err) return errors.errorInternalError(res) if (!history) return errors.errorNotFound(res) - delete history[noteId] + history.delete(noteId) setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) { if (err) return errors.errorInternalError(res) res.end()