From dc15e4fca2c5211bd0f33a9a07bea80d5d163e3e Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 7 Jan 2020 15:19:34 +0530 Subject: [PATCH 1/2] adding platform filtering condition for API call and updating core lib ver to latest (npm security fixes) --- .circleci/config.yml | 2 +- package.json | 2 +- src/services/NotificationService.js | 33 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1628f9a..f87288b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -102,7 +102,7 @@ workflows: context : org-global filters: branches: - only: [dev, 'hotfix/V5-API-Standards', 'v5-upgrade'] + only: [dev, 'hotfix/V5-API-Standards', 'v5-upgrade', 'feature/platform-filtering'] - "build-prod": context : org-global filters: diff --git a/package.json b/package.json index 5ed55b2..c7f4382 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "remarkable": "^1.7.1", "sequelize": "^4.21.0", "superagent": "^3.8.0", - "tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6", + "tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6.2", "topcoder-healthcheck-dropin": "^1.0.3", "urijs": "^1.19.1", "winston": "^2.2.0" diff --git a/src/services/NotificationService.js b/src/services/NotificationService.js index 9b5ea52..5c96426 100644 --- a/src/services/NotificationService.js +++ b/src/services/NotificationService.js @@ -57,8 +57,11 @@ getSettings.schema = { * @param {Number} userId the user id */ function* saveNotificationSetting(entry, userId) { - const setting = yield models.NotificationSetting.findOne({ where: { - userId, topic: entry.topic, serviceId: entry.serviceId, name: entry.name } }); + const setting = yield models.NotificationSetting.findOne({ + where: { + userId, topic: entry.topic, serviceId: entry.serviceId, name: entry.name + } + }); if (setting) { setting.value = entry.value; yield setting.save(); @@ -79,8 +82,11 @@ function* saveNotificationSetting(entry, userId) { * @param {Number} userId the user id */ function* saveServiceSetting(entry, userId) { - const setting = yield models.ServiceSettings.findOne({ where: { - userId, serviceId: entry.serviceId, name: entry.name } }); + const setting = yield models.ServiceSettings.findOne({ + where: { + userId, serviceId: entry.serviceId, name: entry.name + } + }); if (setting) { setting.value = entry.value; yield setting.save(); @@ -181,12 +187,21 @@ function* listNotifications(query, userId) { const notificationSettings = settings.notifications; const limit = query.limit || query.per_page; const offset = (query.page - 1) * limit; - const filter = { where: { - userId, - }, offset, limit, order: [['createdAt', 'DESC']] }; - if (query.platform) { - filter.where.type = { $like: `notifications\.${query.platform}\.%` }; + const filter = { + where: { + userId, + }, offset, limit, order: [['createdAt', 'DESC']] + }; + + switch (query.platform) { + case 'connect': + filter.where.type = { $like: 'notification.connect.%' }; + break; + case 'community': + filter.where.type = { $notLike: 'notification.connect.%' }; + break; } + if (_.keys(notificationSettings).length > 0) { // only filter out notifications types which were explicitly set to 'no' - so we return notification by default const notifications = _.keys(notificationSettings).filter((notificationType) => From ca04a12a7eedb7d83529eb98bac4246505e45359 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 7 Jan 2020 15:31:46 +0530 Subject: [PATCH 2/2] typo --- src/services/NotificationService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/NotificationService.js b/src/services/NotificationService.js index 5c96426..cb92781 100644 --- a/src/services/NotificationService.js +++ b/src/services/NotificationService.js @@ -195,10 +195,10 @@ function* listNotifications(query, userId) { switch (query.platform) { case 'connect': - filter.where.type = { $like: 'notification.connect.%' }; + filter.where.type = { $like: 'connect.notification.%' }; break; case 'community': - filter.where.type = { $notLike: 'notification.connect.%' }; + filter.where.type = { $notLike: 'connect.notification.%' }; break; }