Skip to content

Commit c54be52

Browse files
author
sachin-maheshwari
authored
Merge pull request #168 from topcoder-platform/dev
API - Platform filtering support (query param)
2 parents a1cff31 + 1f911f0 commit c54be52

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ workflows:
102102
context : org-global
103103
filters:
104104
branches:
105-
only: [dev, 'hotfix/V5-API-Standards', 'v5-upgrade']
105+
only: [dev, 'hotfix/V5-API-Standards', 'v5-upgrade', 'feature/platform-filtering']
106106
- "build-prod":
107107
context : org-global
108108
filters:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"remarkable": "^1.7.1",
5454
"sequelize": "^4.21.0",
5555
"superagent": "^3.8.0",
56-
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6",
56+
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6.2",
5757
"topcoder-healthcheck-dropin": "^1.0.3",
5858
"urijs": "^1.19.1",
5959
"winston": "^2.2.0"

src/services/NotificationService.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ getSettings.schema = {
5757
* @param {Number} userId the user id
5858
*/
5959
function* saveNotificationSetting(entry, userId) {
60-
const setting = yield models.NotificationSetting.findOne({ where: {
61-
userId, topic: entry.topic, serviceId: entry.serviceId, name: entry.name } });
60+
const setting = yield models.NotificationSetting.findOne({
61+
where: {
62+
userId, topic: entry.topic, serviceId: entry.serviceId, name: entry.name
63+
}
64+
});
6265
if (setting) {
6366
setting.value = entry.value;
6467
yield setting.save();
@@ -79,8 +82,11 @@ function* saveNotificationSetting(entry, userId) {
7982
* @param {Number} userId the user id
8083
*/
8184
function* saveServiceSetting(entry, userId) {
82-
const setting = yield models.ServiceSettings.findOne({ where: {
83-
userId, serviceId: entry.serviceId, name: entry.name } });
85+
const setting = yield models.ServiceSettings.findOne({
86+
where: {
87+
userId, serviceId: entry.serviceId, name: entry.name
88+
}
89+
});
8490
if (setting) {
8591
setting.value = entry.value;
8692
yield setting.save();
@@ -181,12 +187,21 @@ function* listNotifications(query, userId) {
181187
const notificationSettings = settings.notifications;
182188
const limit = query.limit || query.per_page;
183189
const offset = (query.page - 1) * limit;
184-
const filter = { where: {
185-
userId,
186-
}, offset, limit, order: [['createdAt', 'DESC']] };
187-
if (query.platform) {
188-
filter.where.type = { $like: `notifications\.${query.platform}\.%` };
190+
const filter = {
191+
where: {
192+
userId,
193+
}, offset, limit, order: [['createdAt', 'DESC']]
194+
};
195+
196+
switch (query.platform) {
197+
case 'connect':
198+
filter.where.type = { $like: 'connect.notification.%' };
199+
break;
200+
case 'community':
201+
filter.where.type = { $notLike: 'connect.notification.%' };
202+
break;
189203
}
204+
190205
if (_.keys(notificationSettings).length > 0) {
191206
// only filter out notifications types which were explicitly set to 'no' - so we return notification by default
192207
const notifications = _.keys(notificationSettings).filter((notificationType) =>

0 commit comments

Comments
 (0)