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