From 390bc24c1cf18063be67b3c9f565ed874ed0a2a8 Mon Sep 17 00:00:00 2001 From: ivan1548 <47206132+ivan1548@users.noreply.github.com> Date: Mon, 25 Feb 2019 07:35:49 -0800 Subject: [PATCH] Remove duplicates from history (#216) --- src/js/history.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/js/history.js b/src/js/history.js index 750f141ff..784435d79 100644 --- a/src/js/history.js +++ b/src/js/history.js @@ -30,7 +30,20 @@ function addToHistory(videoId){ videoId: videoId, timeWatched: new Date().getTime(), }; - historyDb.insert(data, (err, newDoc) => {}); + + historyDb.findOne({ videoId: videoId }, function (err, doc) { + if(doc === null) { + historyDb.insert(data, (err, newDoc) => {}); + } else { + historyDb.update( + { videoId: videoId }, + { + $set: { + timeWatched: data.timeWatched, + } + }, {}, (err, newDoc) => {}); + } + }); } /**