forked from mithunsatheesh/node-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
30 lines (26 loc) · 821 Bytes
/
test.js
File metadata and controls
30 lines (26 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
process.on('unhandledRejection', (err) => console.log(err.stack));
var RuleEngine = require('./lib/node-rules.js');
var moment = require('moment');
var engine = new RuleEngine([{
name: 'test-rule',
priority: 0,
conditions: [{
items: { '#min': { $lt: 4 }},
'items#max': { $maxOf: { $field: 'items' }},
index: 2,
}],
consequences: [{
items: { $each: { $mul: { $field: 'multiplier' }}},
daysBetween: { $daysBetween: [{ $field: 'dateB' }, { $field: 'dateA' }]},
'_global.this': 'isGlobal',
}],
}]);
var now = moment();
engine.execute({
items: [1, 3, 5, 2],
multiplier: 4,
dateA: now.toDate(),
dateB: now.add(5, 'days').toISOString(),
daysBetween: null,
index: [1, 2]
}, ['index', { this: 'isNotGlobal' }]).then(console.log);