Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 24 additions & 9 deletions src/services/NotificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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) =>
Expand Down