From 73831f0dd057621c8c419e1cf68331b6d3aee9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BBki=20Vachot?= Date: Mon, 13 Dec 2021 23:07:16 +0100 Subject: [PATCH 1/2] Update: Ad.update remove duplicate interests + Ad.findAll can filter with multiple interest with ',' --- app-backend/controllers/ad.controller.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app-backend/controllers/ad.controller.js b/app-backend/controllers/ad.controller.js index 0182491..2b6dd6f 100644 --- a/app-backend/controllers/ad.controller.js +++ b/app-backend/controllers/ad.controller.js @@ -70,7 +70,7 @@ exports.findAll = (req, res) => { query.url = condition; const interests = req.query.interests; - condition = interests ? {$in: interests} : undefined; + condition = interests ? {$in: interests.split(',')} : undefined; query["interests.interest"] = condition const comment = req.query.comment; @@ -174,9 +174,9 @@ exports.update = (req, res) => { condition = url ? url : undefined; update.url = condition; - const interests = req.body.interests; - condition = interests ? interests : undefined; - update.interests = condition; + let interests = req.body.interests; + condition = interests ? {interests: [...new Map(interests.map(v => [v.id, v])).values()]} : undefined; + update.$addToSet = condition; const comment = req.body.comment; condition = comment ? comment : undefined; From c465b87b3f3af19d2d89c13880edfe6e9c088e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BBki=20Vachot?= Date: Mon, 13 Dec 2021 23:17:48 +0100 Subject: [PATCH 2/2] Update: User.history missing sort by watchedDate --- app-backend/controllers/user.controller.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app-backend/controllers/user.controller.js b/app-backend/controllers/user.controller.js index dedab4e..125c6d3 100644 --- a/app-backend/controllers/user.controller.js +++ b/app-backend/controllers/user.controller.js @@ -457,7 +457,8 @@ exports.history = (req, res) => { watchedDate: {$arrayElemAt: ["$watchedDates", -1]}, createdAt: true, updatedAt: true - }}]) + }}, + {$sort: {watchedDate: -1}}]) .then(async data => { let yt_results = []; let dm_results = [];