1 | var RuleEngine = require('../index');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var rules = [{
|
9 | "condition": function(R) {
|
10 | R.when(this.transactionTotal < 500);
|
11 | },
|
12 | "consequence": function(R) {
|
13 | this.result = false;
|
14 | this.reason = "The transaction was blocked as it was less than 500";
|
15 | R.stop();
|
16 | }
|
17 | }, {
|
18 | "condition": function(R) {
|
19 | R.when(this.cardType === "Debit");
|
20 | },
|
21 | "consequence": function(R) {
|
22 | this.result = false;
|
23 | this.reason = "The transaction was blocked as debit cards are not allowed";
|
24 | R.stop();
|
25 | }
|
26 | }];
|
27 |
|
28 | var R = new RuleEngine();
|
29 | R.register(rules);
|
30 |
|
31 | var fact = {
|
32 | "name": "user4",
|
33 | "application": "MOB2",
|
34 | "transactionTotal": 600,
|
35 | "cardType": "Debit"
|
36 | };
|
37 | R.execute(fact, function(data) {
|
38 | if (data.result) {
|
39 | console.log("Valid transaction");
|
40 | } else {
|
41 | console.log("Blocked Reason:" + data.reason);
|
42 | }
|
43 | }); |
\ | No newline at end of file |