@@ -7,26 +7,26 @@ const cds = require("@sap/cds");
7
7
const LOG = cds . log ( 'notifications' ) ;
8
8
9
9
const defaultTemplate = {
10
- " NotificationTypeKey" : "Default" ,
11
- " NotificationTypeVersion" : "1" ,
12
- " Templates" : [
10
+ NotificationTypeKey : "Default" ,
11
+ NotificationTypeVersion : "1" ,
12
+ Templates : [
13
13
{
14
- " Language" : "en" ,
15
- " Description" : "Other Notifications" ,
16
- " TemplatePublic" : "{{title}}" ,
17
- " TemplateSensitive" : "{{title}}" ,
18
- " TemplateGrouped" : "Other Notifications" ,
19
- " TemplateLanguage" : "mustache" ,
20
- " Subtitle" : "{{description}}"
14
+ Language : "en" ,
15
+ Description : "Other Notifications" ,
16
+ TemplatePublic : "{{title}}" ,
17
+ TemplateSensitive : "{{title}}" ,
18
+ TemplateGrouped : "Other Notifications" ,
19
+ TemplateLanguage : "mustache" ,
20
+ Subtitle : "{{description}}"
21
21
}
22
22
]
23
23
} ;
24
24
25
25
function fromOdataArrayFormat ( objectInArray ) {
26
26
if ( objectInArray === undefined || objectInArray === null || Array . isArray ( objectInArray ) ) {
27
- return objectInArray ;
27
+ return ( objectInArray === undefined || objectInArray === null ) ? [ ] : objectInArray ;
28
28
} else {
29
- return objectInArray . results ;
29
+ return ( objectInArray . results === undefined || objectInArray . results === null ) ? [ ] : objectInArray . results ;
30
30
}
31
31
}
32
32
@@ -63,15 +63,15 @@ async function getNotificationTypes() {
63
63
const notificationDestination = await getNotificationDestination ( ) ;
64
64
const response = await executeHttpRequest ( notificationDestination , {
65
65
url : `${ NOTIFICATION_TYPES_API_ENDPOINT } /NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels` ,
66
- method : "get" ,
66
+ method : "get"
67
67
} ) ;
68
68
return response . data . d . results ;
69
69
}
70
70
71
71
async function createNotificationType ( notificationType ) {
72
72
const notificationDestination = await getNotificationDestination ( ) ;
73
73
const csrfHeaders = await buildHeadersForDestination ( notificationDestination , {
74
- url : NOTIFICATION_TYPES_API_ENDPOINT ,
74
+ url : NOTIFICATION_TYPES_API_ENDPOINT
75
75
} ) ;
76
76
77
77
LOG . _warn && LOG . warn (
@@ -82,15 +82,15 @@ async function createNotificationType(notificationType) {
82
82
url : `${ NOTIFICATION_TYPES_API_ENDPOINT } /NotificationTypes` ,
83
83
method : "post" ,
84
84
data : notificationType ,
85
- headers : csrfHeaders ,
85
+ headers : csrfHeaders
86
86
} ) ;
87
87
return response . data ?. d ?? response ;
88
88
}
89
89
90
90
async function updateNotificationType ( id , notificationType ) {
91
91
const notificationDestination = await getNotificationDestination ( ) ;
92
92
const csrfHeaders = await buildHeadersForDestination ( notificationDestination , {
93
- url : NOTIFICATION_TYPES_API_ENDPOINT ,
93
+ url : NOTIFICATION_TYPES_API_ENDPOINT
94
94
} ) ;
95
95
96
96
LOG . _info && LOG . info (
@@ -101,15 +101,15 @@ async function updateNotificationType(id, notificationType) {
101
101
url : `${ NOTIFICATION_TYPES_API_ENDPOINT } /NotificationTypes(guid'${ id } ')` ,
102
102
method : "patch" ,
103
103
data : notificationType ,
104
- headers : csrfHeaders ,
104
+ headers : csrfHeaders
105
105
} ) ;
106
106
return response . status ;
107
107
}
108
108
109
109
async function deleteNotificationType ( notificationType ) {
110
110
const notificationDestination = await getNotificationDestination ( ) ;
111
111
const csrfHeaders = await buildHeadersForDestination ( notificationDestination , {
112
- url : NOTIFICATION_TYPES_API_ENDPOINT ,
112
+ url : NOTIFICATION_TYPES_API_ENDPOINT
113
113
} ) ;
114
114
115
115
LOG . _info && LOG . info (
@@ -119,16 +119,12 @@ async function deleteNotificationType(notificationType) {
119
119
const response = await executeHttpRequest ( notificationDestination , {
120
120
url : `${ NOTIFICATION_TYPES_API_ENDPOINT } /NotificationTypes(guid'${ notificationType . NotificationTypeId } ')` ,
121
121
method : "delete" ,
122
- headers : csrfHeaders ,
122
+ headers : csrfHeaders
123
123
} ) ;
124
124
return response . status ;
125
125
}
126
126
127
127
function _createChannelsMap ( channels ) {
128
- if ( channels === null || channels === undefined ) {
129
- return { } ;
130
- }
131
-
132
128
const channelMap = { } ;
133
129
134
130
channels . forEach ( ( channel ) => {
@@ -240,9 +236,9 @@ function isNotificationTypeEqual(oldNotificationType, newNotificationType) {
240
236
241
237
return (
242
238
oldNotificationType . IsGroupable == newNotificationType . IsGroupable &&
243
- areTemplatesEqual ( oldNotificationType . Templates . results , fromOdataArrayFormat ( newNotificationType . Templates ) ) &&
244
- areActionsEqual ( oldNotificationType . Actions . results , fromOdataArrayFormat ( newNotificationType . Actions ) ) &&
245
- areDeliveryChannelsEqual ( oldNotificationType . DeliveryChannels . results , fromOdataArrayFormat ( newNotificationType . DeliveryChannels ) )
239
+ areTemplatesEqual ( fromOdataArrayFormat ( oldNotificationType . Templates ) , fromOdataArrayFormat ( newNotificationType . Templates ) ) &&
240
+ areActionsEqual ( fromOdataArrayFormat ( oldNotificationType . Actions ) , fromOdataArrayFormat ( newNotificationType . Actions ) ) &&
241
+ areDeliveryChannelsEqual ( fromOdataArrayFormat ( oldNotificationType . DeliveryChannels ) , fromOdataArrayFormat ( newNotificationType . DeliveryChannels ) )
246
242
) ;
247
243
}
248
244
@@ -262,9 +258,7 @@ async function processNotificationTypes(notificationTypesJSON) {
262
258
}
263
259
264
260
if ( ! existingType . NotificationTypeKey . startsWith ( `${ prefix } /` ) ) {
265
- LOG . _info && LOG . info (
266
- `Skipping Notification Type of other application: ${ existingType . NotificationTypeKey } .`
267
- ) ;
261
+ LOG . _info && LOG . info ( `Skipping Notification Type of other application: ${ existingType . NotificationTypeKey } .` ) ;
268
262
continue ;
269
263
}
270
264
0 commit comments