Skip to content

Commit

Permalink
feat(core): Support sub rules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbrg committed Oct 1, 2024
1 parent 367780e commit ea66431
Showing 1 changed file with 13 additions and 62 deletions.
75 changes: 13 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,26 +535,14 @@ import { fetchAccount } from './api'

const rule: Rule = {
conditions: [{
all: [{
field: "account.balance",
operator: ">=",
value: 100.00,
},
{
field: "account.age",
operator: ">=",
value: 18,
}],
all: [
{ field: "account.balance", operator: ">=", value: 100.00 },
{ field: "account.age", operator: ">=", value: 18 }
],
}],
};

const criteria = [{
account: 123,
}, {
account: 123,
}, {
account: 124,
}];
const criteria = [{ account: 123 }, { account: 123 }, { account: 124 }];

// Instantiate a new RulePilot instance (recommended)
const rulePilot = new RulePilot();
Expand Down Expand Up @@ -635,43 +623,19 @@ const rule: Rule = {
any: [
{
all: [
{
field: "country",
operator: "in",
value: ["GB", "FI"],
},
{
field: "hasCoupon",
operator: "==",
value: true,
},
{
field: "totalCheckoutPrice",
operator: ">=",
value: 120.0,
},
{ field: "country", operator: "in", value: ["GB", "FI"] },
{ field: "hasCoupon", operator: "==", value: true },
{ field: "totalCheckoutPrice", operator: ">=", value: 120.0 },
],
},
{
field: "country",
operator: "==",
value: "SE",
},
{ field: "country", operator: "==", value: "SE" },
],
result: 5,
},
{
all: [
{
field: "age",
operator: ">=",
value: 18,
},
{
field: "hasStudentCard",
operator: "==",
value: true,
},
{ field: "age", operator: ">=", value: 18 },
{ field: "hasStudentCard", operator: "==", value: true },
],
result: 10,
},
Expand All @@ -691,26 +655,13 @@ The following will be returned in the `introspection` variable:
"result": 5,
"options": [
{ "country": "SE" },
{
"country": ["GB", "FI"],
"hasCoupon": true,
"totalCheckoutPrice": {
"operator": ">=",
"value": 120
}
}
{ "country": ["GB", "FI"], "hasCoupon": true, "totalCheckoutPrice": { "operator": ">=", "value": 120 } }
]
},
{
"result": 10,
"options": [
{
"age": {
"operator": ">=",
"value": 18
},
"hasStudentCard": true
}
{ "age": { "operator": ">=", "value": 18 }, "hasStudentCard": true }
]
}
]
Expand Down

0 comments on commit ea66431

Please sign in to comment.