1 | var RuleEngine = require('../index');
|
2 |
|
3 | var rule = {
|
4 | "condition": function(R) {
|
5 | R.when(this.transactionTotal < 500);
|
6 | },
|
7 | "consequence": function(R) {
|
8 | this.result = false;
|
9 | this.reason = "The transaction was blocked as it was less than 500";
|
10 | R.stop();
|
11 | }
|
12 | };
|
13 |
|
14 | var R = new RuleEngine();
|
15 | R.register(rule);
|
16 |
|
17 | var fact = {
|
18 | "name": "user4",
|
19 | "application": "MOB2",
|
20 | "transactionTotal": 400,
|
21 | "cardType": "Credit Card"
|
22 | };
|
23 | R.execute(fact, function(data) {
|
24 | if (data.result) {
|
25 | console.log("Valid transaction");
|
26 | } else {
|
27 | console.log("Blocked Reason:" + data.reason);
|
28 | }
|
29 | }); |
\ | No newline at end of file |