Skip to content

Commit a7daf1f

Browse files
committed
Fix comments
1 parent 9667f25 commit a7daf1f

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

lib/utils.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const messages = {
99
TYPES_FILE_NOT_EXISTS: "Notification Types file path is incorrect.",
1010
INVALID_NOTIFICATION_TYPES: "Notification Types must contain the following key: 'NotificationTypeKey'.",
1111
DESTINATION_NOT_FOUND: "Failed to get destination: ",
12-
MANDATORY_PARAMETER_NOT_PASSED_FOR_DEFAULT_NOTIFICATION: "Recipients, priority and title are mandatory parameters",
12+
MANDATORY_PARAMETER_NOT_PASSED_FOR_DEFAULT_NOTIFICATION: "Recipients and title are mandatory parameters",
1313
MANDATORY_PARAMETER_NOT_PASSED_FOR_CUSTOM_NOTIFICATION: "Recipients, type are mandatory parameters",
1414
RECIPIENTS_IS_NOT_ARRAY: "Recipients is not an array or it is empty",
1515
TITLE_IS_NOT_STRING: "Title is not a string",
@@ -32,7 +32,7 @@ function validateNotificationTypes(notificationTypes) {
3232
}
3333

3434
function validateDefaultNotifyParameters(recipients, priority, title, description) {
35-
if (!recipients || !priority || !title) {
35+
if (!recipients || !title) {
3636
console.log(messages.MANDATORY_PARAMETER_NOT_PASSED_FOR_DEFAULT_NOTIFICATION);
3737
return false;
3838
}
@@ -47,12 +47,12 @@ function validateDefaultNotifyParameters(recipients, priority, title, descriptio
4747
return false;
4848
}
4949

50-
if (!PRIORITIES.includes(priority)) {
50+
if (priority && !PRIORITIES.includes(priority.toUpperCase())) {
5151
console.log(`Invalid priority ${priority}. Allowed priorities are LOW, NEUTRAL, MEDIUM, HIGH`);
5252
return false;
5353
}
5454

55-
if (description !== undefined && typeof description !== "string") {
55+
if (description && typeof description !== "string") {
5656
console.log(messages.DESCRIPTION_IS_NOT_STRING);
5757
return false;
5858
}
@@ -71,22 +71,22 @@ function validateCustomNotifyParameters(type, recipients, properties, navigation
7171
return false;
7272
}
7373

74-
if (priority === undefined || !PRIORITIES.includes(priority)) {
74+
if (priority && !PRIORITIES.includes(priority.toUpperCase())) {
7575
console.log(`Invalid priority ${priority}. Allowed priorities are LOW, NEUTRAL, MEDIUM, HIGH`);
7676
return false;
7777
}
7878

79-
if (properties !== undefined && !Array.isArray(properties)) {
79+
if (properties && !Array.isArray(properties)) {
8080
console.log(messages.PROPERTIES_IS_NOT_OBJECT);
8181
return false;
8282
}
8383

84-
if (navigation !== undefined && typeof navigation !== "object") {
84+
if (navigation && typeof navigation !== "object") {
8585
console.log(messages.NAVIGATION_IS_NOT_OBJECT);
8686
return false;
8787
}
8888

89-
if (payload !== undefined && typeof payload !== "object") {
89+
if (payload && typeof payload !== "object") {
9090
console.log(messages.PAYLOAD_IS_NOT_OBJECT);
9191
return false;
9292
}
@@ -144,7 +144,7 @@ async function executeRequest(httpMethod, targetUrl, payload, notificationDestin
144144

145145
function buildDefaultNotification(
146146
recipients,
147-
priority,
147+
priority = "NEUTRAL",
148148
title,
149149
description = ""
150150
) {
@@ -183,7 +183,7 @@ function buildCustomNotification(notificationData) {
183183
NotificationTypeVersion: notificationData["payload"] ? notificationData["payload"]["NotificationTypeVersion"] : "1",
184184
NavigationTargetAction: notificationData["navigation"] ? notificationData["navigation"]["NavigationTargetAction"] : undefined,
185185
NavigationTargetObject: notificationData["navigation"] ? notificationData["navigation"]["NavigationTargetObject"] : undefined,
186-
Priority: notificationData["priority"] ? notificationData["priority"] : "MEDIUM",
186+
Priority: notificationData["priority"] ? notificationData["priority"] : "NEUTRAL",
187187
ProviderId: notificationData["payload"] ? notificationData["payload"]["ProviderId"] : undefined,
188188
ActorId: notificationData["payload"] ? notificationData["payload"]["ActorId"] : undefined,
189189
ActorDisplayText: notificationData["payload"] ? notificationData["payload"]["ActorDisplayText"] : undefined,
@@ -239,4 +239,3 @@ module.exports = {
239239
executeRequest,
240240
buildNotification
241241
};
242-

srv/notifyToConsole.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = class NotifyToConsole extends NotificationService {
1010

1111
notify() {
1212

13-
const notification = buildNotification(arguments);
13+
const notification = buildNotification(arguments[0]);
1414

1515
if (notification) {
1616
console.log(`SAP Alert Notification service notification: ${JSON.stringify(notification, null, 2)}`);

0 commit comments

Comments
 (0)