From 3ffb579ed6dee3e76836b711577af215fb4ec08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BBki=20Vachot?= Date: Tue, 14 Dec 2021 17:02:02 +0100 Subject: [PATCH] Update: Playlist.update videoIds + videoId fields --- app-backend/controllers/playlist.controller.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app-backend/controllers/playlist.controller.js b/app-backend/controllers/playlist.controller.js index 3fb4ae2..a6d6b65 100644 --- a/app-backend/controllers/playlist.controller.js +++ b/app-backend/controllers/playlist.controller.js @@ -316,12 +316,19 @@ exports.update = (req, res) => { update.name = condition; const videoIds = req.body.videoIds; - if(typeof videoIds !== 'undefined' && videoIds !== null){ - condition = videoIds ? {videoIds: videoIds} : undefined; - } else { - condition = undefined; + condition = videoIds ? videoIds : undefined; + update.videoIds = condition; + + const videoId = req.body.videoId; + if(typeof videoId !== 'undefined' && typeof videoId.id !== 'undefined' && typeof videoId.action !== 'undefined'){ + if(videoId.action === 'add'){ + condition = videoId.id ? {videoIds: videoId.id} : undefined; + update.$addToSet = condition; + } else if(videoId.action === 'delete'){ + condition = videoId.id ? {videoIds: videoId.id} : undefined; + update.$pull = condition; + } } - update.$addToSet = condition; const isActive = req.body.isActive; if(typeof isActive !== 'undefined'){