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..cb92781 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: 'connect.notification.%' }; + break; + case 'community': + filter.where.type = { $notLike: 'connect.notification.%' }; + 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) =>