Remove duplicates from history (#216)

This commit is contained in:
ivan1548 2019-02-25 07:35:49 -08:00 committed by Preston
parent 916812b8f9
commit 390bc24c1c
1 changed files with 14 additions and 1 deletions

View File

@ -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) => {});
}
});
}
/**