()
| 14 | const { Engine } = require('json-rules-engine') |
| 15 | |
| 16 | async function start () { |
| 17 | /** |
| 18 | * Setup a new engine |
| 19 | */ |
| 20 | const engine = new Engine() |
| 21 | |
| 22 | /** |
| 23 | * Condition that will be used to determine if a user likes screwdrivers |
| 24 | */ |
| 25 | engine.setCondition('screwdriverAficionado', { |
| 26 | all: [ |
| 27 | { |
| 28 | fact: 'drinksOrangeJuice', |
| 29 | operator: 'equal', |
| 30 | value: true |
| 31 | }, |
| 32 | { |
| 33 | fact: 'enjoysVodka', |
| 34 | operator: 'equal', |
| 35 | value: true |
| 36 | } |
| 37 | ] |
| 38 | }) |
| 39 | |
| 40 | /** |
| 41 | * Rule for identifying people who should be invited to a screwdriver social |
| 42 | * - Only invite people who enjoy screw drivers |
| 43 | * - Only invite people who are sociable |
| 44 | */ |
| 45 | const inviteRule = { |
| 46 | conditions: { |
| 47 | all: [ |
| 48 | { |
| 49 | condition: 'screwdriverAficionado' |
| 50 | }, |
| 51 | { |
| 52 | fact: 'isSociable', |
| 53 | operator: 'equal', |
| 54 | value: true |
| 55 | } |
| 56 | ] |
| 57 | }, |
| 58 | event: { type: 'invite-to-screwdriver-social' } |
| 59 | } |
| 60 | engine.addRule(inviteRule) |
| 61 | |
| 62 | /** |
| 63 | * Rule for identifying people who should be invited to the other social |
| 64 | * - Only invite people who don't enjoy screw drivers |
| 65 | * - Only invite people who are sociable |
| 66 | */ |
| 67 | const otherInviteRule = { |
| 68 | conditions: { |
| 69 | all: [ |
| 70 | { |
| 71 | not: { |
| 72 | condition: 'screwdriverAficionado' |
| 73 | } |
no test coverage detected
searching dependent graphs…