Skip to content

Commit a651a47

Browse files
committed
Adress comments
1 parent d810851 commit a651a47

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

lib/notifications.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ async function postNotification() {
1111
});
1212

1313
const notification = createNotification(arguments);
14-
return (await executeRequest("post", `${NOTIFICATIONS_API_ENDPOINT}/Notifications`, notification, notifServiceDest, csrfHeaders)).data.d;
14+
15+
if (notification) {
16+
return (await executeRequest("post", `${NOTIFICATIONS_API_ENDPOINT}/Notifications`, notification, notifServiceDest, csrfHeaders)).data.d;
17+
}
1518
}
1619

1720
module.exports = {

lib/utils.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ function validateNotificationTypes(notificationTypes) {
2020

2121
function validateNotifyParameters(recipients, priority, title) {
2222
if (!recipients || !priority || !title) {
23-
throw new Error(messages.MANDATORY_PARAMETER_NOT_PASSED);
23+
console.log(messages.MANDATORY_PARAMETER_NOT_PASSED);
24+
return false;
2425
}
2526

2627
if (!PRIORITIES.includes(priority)) {
27-
throw new Error(`Invalid priority ${priority}. Allowed priorities are LOW, NEUTRAL, MEDIUM, HIGH`);
28+
console.log(`Invalid priority ${priority}. Allowed priorities are LOW, NEUTRAL, MEDIUM, HIGH`);
29+
return false;
2830
}
31+
32+
return true;
2933
}
3034

3135
function doesKeyExist(obj, key) {
@@ -64,7 +68,6 @@ async function executeRequest(httpMethod, targetUrl, payload, notifServiceDest,
6468
});
6569
} catch (e) {
6670
console.log(e);
67-
return e;
6871
}
6972
return response;
7073
}
@@ -112,7 +115,9 @@ function createNotification(passedArguments) {
112115
const title = passedArguments[2];
113116
const description = passedArguments[3] ? passedArguments[3] : "";
114117

115-
validateNotifyParameters(recipients, priority, title);
118+
if (!validateNotifyParameters(recipients, priority, title)) {
119+
return;
120+
}
116121

117122
notification = createDefaultNotification(
118123
recipients,

srv/notifyToConsole.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const NotificationService = require('./service');
2-
const { createNotification } = require("./../lib/utils");
2+
const { createNotification, readFile, doesKeyExist } = require("./../lib/utils");
3+
const { createNotificationTypesMap } = require("./../lib/notificationTypes");
34

45
module.exports = class NotifyToConsole extends NotificationService {
56
async init() {
@@ -8,8 +9,23 @@ module.exports = class NotifyToConsole extends NotificationService {
89
}
910

1011
notify() {
12+
1113
const notification = createNotification(arguments);
1214

13-
console.log(`SAP Alert Notification service notification: ${JSON.stringify(notification, null, 2)}`);
15+
if (notification) {
16+
console.log(`SAP Alert Notification service notification: ${JSON.stringify(notification, null, 2)}`);
17+
18+
const typesFile = readFile(cds.env.requires.notifications.types);
19+
const existingTypes = createNotificationTypesMap(typesFile);
20+
21+
if (!doesKeyExist(existingTypes, notification["NotificationTypeKey"])) {
22+
console.log(`Notification Type ${notification["NotificationTypeKey"]} is not in the notification types file`);
23+
}
24+
25+
if (!doesKeyExist(existingTypes[notification["NotificationTypeKey"]], notification["NotificationTypeVersion"])) {
26+
console.log(`Notification Type Version ${notification["NotificationTypeVersion"]} for type ${notification["NotificationTypeKey"]} is not in the notification types file`);
27+
}
28+
}
29+
1430
}
1531
}

0 commit comments

Comments
 (0)