Skip to content

Commit 4a6c859

Browse files
authored
Merge pull request #3 from cap-js/create-class
AlertNotificationService Class
2 parents 7e1b1b7 + 314516c commit 4a6c859

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

cds-plugin.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ const {
66
readFileContent,
77
} = require("./lib/utils");
88

9-
global.alert = {
10-
notify: notifier.postNotification,
11-
};
12-
139
cds.once("served", () => {
1410
/**
1511
* For local testing initialise VCAP_SERVICES variables for the application
@@ -38,4 +34,3 @@ cds.once("served", () => {
3834
}
3935
});
4036

41-
module.exports = { alert: alert };

package.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,28 @@
1212
"srv"
1313
],
1414
"dependencies": {
15-
"@sap-cloud-sdk/core": "^1.54.2"
15+
"@sap-cloud-sdk/core": "^1.54.2"
16+
},
17+
"devDependencies": {
18+
"jest": "^29.6.4"
1619
},
1720
"scripts": {
1821
"lint": "npx eslint .",
1922
"test": "npx jest --silent"
2023
},
21-
"devDependencies": {
22-
"jest": "^29.6.4"
23-
}
24+
"cds": {
25+
"requires": {
26+
"kinds": {
27+
"notifications": {
28+
"[development]": {
29+
"kind": "notify-to-console"
30+
}
31+
},
32+
"notify-to-console": {
33+
"impl": "@cap-js/alert-notification/srv/notifyToConsole",
34+
"outbox": false
35+
}
36+
}
37+
}
38+
}
2439
}

srv/notifyToConsole.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const AlertNotificationService = require('./service')
2+
3+
module.exports = class NotifyToConsole extends AlertNotificationService {
4+
async init() {
5+
6+
// call AlertNotificationService's init
7+
await super.init()
8+
}
9+
}

srv/service.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,19 @@
22
* TODO: Add the entry point for the Plugin Service here.
33
* We will branch out for development and production profile here
44
*/
5+
6+
const cds = require('@sap/cds')
7+
const notifier = require("../lib/notifications");
8+
9+
// REVISIT: cds.OutboxService or technique to avoid extending OutboxService
10+
const OutboxService = require('@sap/cds/libx/_runtime/messaging/Outbox')
11+
12+
module.exports = class AlertNotificationService extends OutboxService {
13+
async init() {
14+
15+
// call OutboxService's init
16+
await super.init()
17+
18+
this.notify = notifier.postNotification
19+
}
20+
}

0 commit comments

Comments
 (0)