3
3
* @desc Actions related to notifications data.
4
4
*/
5
5
6
+ import _ from 'lodash' ;
6
7
import { createActions } from 'redux-actions' ;
7
8
import { getService } from '../services/notifications' ;
8
9
10
+ /**
11
+ * TODO: We will need to change this based on API and
12
+ * frontend mapping we need later.
13
+ */
14
+ function processData ( data ) {
15
+ const retData = _ . map ( data , ( item ) => {
16
+ const object = { } ;
17
+ object . id = item . id ;
18
+ object . sourceId = item . contents . id ;
19
+ object . sourceName = item . contents . name || item . contents . title ;
20
+ object . eventType = item . type ;
21
+ object . isRead = item . read ;
22
+ object . isSeen = item . seen ;
23
+ object . contents = item . contents . message || item . contents . title ;
24
+ object . version = item . version ;
25
+ object . date = item . createdAt ;
26
+ return object ;
27
+ } ) ;
28
+ return retData ;
29
+ }
30
+
9
31
/**
10
32
* @static
11
33
* @desc Creates an action that signals beginning of notifications
@@ -19,17 +41,17 @@ function getNotificationsInit() {
19
41
/**
20
42
* @static
21
43
* @desc Creates an action that loads member achievements.
44
+ * @param {String } tokenV3 v3 auth token.
22
45
* @return {Action }
23
46
*/
24
- async function getNotificationsDone ( item ) {
47
+ async function getNotificationsDone ( tokenV3 ) {
25
48
let data ;
26
49
try {
27
- data = await getService ( ) . getNotifications ( item ) ;
50
+ data = await getService ( tokenV3 ) . getNotifications ( ) ;
28
51
} catch ( e ) {
29
52
data = [ ] ;
30
53
}
31
-
32
- return data ;
54
+ return processData ( data . items || [ ] ) ;
33
55
}
34
56
35
57
/**
@@ -45,16 +67,16 @@ function markNotificationAsReadInit() {
45
67
/**
46
68
* @static
47
69
* @desc Creates an action that marks notification as read.
70
+ * @param {String } tokenV3 v3 auth token.
48
71
* @return {Action }
49
72
*/
50
- async function markNotificationAsReadDone ( item ) {
51
- let data ;
73
+ async function markNotificationAsReadDone ( item , tokenV3 ) {
52
74
try {
53
- data = await getService ( ) . markNotificationAsRead ( item ) ;
75
+ await getService ( tokenV3 ) . markNotificationAsRead ( item . id ) ;
54
76
} catch ( e ) {
55
- data = [ ] ;
77
+ return e ;
56
78
}
57
- return data ;
79
+ return item ;
58
80
}
59
81
60
82
/**
@@ -70,16 +92,16 @@ function markAllNotificationAsReadInit() {
70
92
/**
71
93
* @static
72
94
* @desc Creates an action that marks all notification as read.
95
+ * @param {String } tokenV3 v3 auth token.
73
96
* @return {Action }
74
97
*/
75
- async function markAllNotificationAsReadDone ( ) {
76
- let data ;
98
+ async function markAllNotificationAsReadDone ( tokenV3 ) {
77
99
try {
78
- data = await getService ( ) . markAllNotificationAsRead ( ) ;
100
+ await getService ( tokenV3 ) . markAllNotificationAsRead ( ) ;
79
101
} catch ( e ) {
80
- data = [ ] ;
102
+ return e ;
81
103
}
82
- return data ;
104
+ return true ;
83
105
}
84
106
85
107
@@ -96,16 +118,16 @@ function markAllNotificationAsSeenInit() {
96
118
/**
97
119
* @static
98
120
* @desc Creates an action that marks all notification as seen.
121
+ * @param {String } tokenV3 v3 auth token.
99
122
* @return {Action }
100
123
*/
101
- async function markAllNotificationAsSeenDone ( ) {
102
- let data ;
124
+ async function markAllNotificationAsSeenDone ( items , tokenV3 ) {
103
125
try {
104
- data = await getService ( ) . markAllNotificationAsSeen ( ) ;
126
+ await getService ( tokenV3 ) . markAllNotificationAsSeen ( items ) ;
105
127
} catch ( e ) {
106
- data = [ ] ;
128
+ return e ;
107
129
}
108
- return data ;
130
+ return items ;
109
131
}
110
132
111
133
@@ -122,16 +144,16 @@ function dismissChallengeNotificationsInit() {
122
144
/**
123
145
* @static
124
146
* @desc Creates an action that dismisses all challenge notifications
147
+ * @param {String } tokenV3 v3 auth token.
125
148
* @return {Action }
126
149
*/
127
- async function dismissChallengeNotificationsDone ( challengeId ) {
128
- let data ;
150
+ async function dismissChallengeNotificationsDone ( challengeId , tokenV3 ) {
129
151
try {
130
- data = await getService ( ) . dismissChallengeNotifications ( challengeId ) ;
152
+ await getService ( tokenV3 ) . dismissChallengeNotifications ( challengeId ) ;
131
153
} catch ( e ) {
132
- data = [ ] ;
154
+ return e ;
133
155
}
134
- return data ;
156
+ return true ;
135
157
}
136
158
137
159
0 commit comments