Skip to content

Commit fa7c98c

Browse files
committed
fix(notifications): refactored notifications module
refactored notifications UI and API modules
1 parent 1599ab7 commit fa7c98c

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

apps/api/src/app/notifications/notification/notification.service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export class NotificationService extends CrudService<Notification> {
4545
title: notification.title,
4646
body: notification.body,
4747
icon: 'assets/icons/icon-72x72.png',
48-
data: {
49-
click_url: '/dashboard',
50-
},
48+
data: notification,
5149
vibrate: [200, 100, 200],
5250
};
5351

libs/core/src/lib/services/in-memory-data.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class InMemoryDataService implements InMemoryDbService {
4343

4444
parseRequestUrl(url: string, utils: RequestInfoUtilities): ParsedRequestUrl {
4545
const newUrl = url
46+
.replace(/\/notifications\/user/, '/notifications')
4647
.replace(/\/datapower\/serviceproxy/, '/serviceproxy')
4748
.replace(/\/nas\/cluster/, '/cluster')
4849
.replace(/\/layer7\/my.cnf/, '/mycnf');

libs/notifications/src/lib/notifications.handler.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
33
import { AddNotification, DeleteNotification, MarkAllAsRead, MarkAsRead } from './notifications.actions';
44
import { SendWebSocketAction } from '@ngx-starter-kit/socketio-plugin';
55
import { SwPush } from '@angular/service-worker';
6-
import { AppNotification } from '@ngx-starter-kit/notifications';
6+
import { AppNotification } from './app-notification.model';
77

88
@Injectable({
99
providedIn: 'root',
@@ -12,7 +12,7 @@ export class NotificationsHandler {
1212
constructor(private actions$: Actions, private store: Store, private readonly swPush: SwPush) {
1313
this.actions$
1414
.pipe(ofActionSuccessful(DeleteNotification))
15-
.subscribe(action => {console.log(action); this.store.dispatch(new SendWebSocketAction(action))});
15+
.subscribe(action => this.store.dispatch(new SendWebSocketAction(action)));
1616
this.actions$
1717
.pipe(ofActionSuccessful(MarkAsRead))
1818
.subscribe(action => this.store.dispatch(new SendWebSocketAction(action)));
@@ -21,11 +21,10 @@ export class NotificationsHandler {
2121
.subscribe(action => this.store.dispatch(new SendWebSocketAction(action)));
2222

2323
if (this.swPush.isEnabled) {
24-
// subscribe for new messages for testing
25-
this.swPush.messages.subscribe(message => {
26-
console.log('received push notification in NotificationsHandler', message);
27-
// TODO:
28-
// this.store.dispatch(new AddNotification(message as AppNotification));
24+
this.swPush.messages.subscribe((message: { notification: Notification }) => {
25+
if (message.notification.data.targetType) {
26+
this.store.dispatch(new AddNotification(new AppNotification(message.notification.data)));
27+
}
2928
});
3029
}
3130
}

0 commit comments

Comments
 (0)