Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
t6decisionrules.checkRulesFromUser = function(user_id, payload) {
payload.user_id = user_id;
rules = dbRules.getCollection("rules");
var query = {
"$and": [
{ "user_id": { "$eq": user_id } },
{ "active": true },
]
}
var r = rules.chain().find(query).data();
let engine = new Engine();
if ( r.length > 0 ) {
r.forEach(function(theRule) {
theRule.rule.event.params.rule_id = theRule.id;
engine.addRule(new Rule(theRule.rule));
});
}
//conditions.facts = [user_id, environment, dtepoch, value, flow, datetime]
//conditions.operators = [isDayTime:, user_id:, environment:, dtepoch:, value:, flow:, datetime:]
//https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#operators
// Event Condition example:
// {"all":[{"fact":"dtepoch","operator":"isDayTime","value":true}]}
engine.addOperator("isDayTime", (factValue, jsonValue) => {
var factLatitude = payload.latitude?payload.latitude:localization.latitude; // TODO: we should use https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#condition-helpers-params
var factLongitude = payload.longitude?payload.longitude:localization.longitude;
createEngine(rules) {
this.rules = rules;
this.engine = new Engine();
rules.forEach(rule => this.engine.addRule(rule));
}
createEngine(rules) {
this.rules = rules;
this.engine = new Engine();
rules.forEach(rule => this.engine.addRule(rule));
}
createEngine(rules) {
this.rules = rules;
this.engine = new Engine();
rules.forEach(rule => this.engine.addRule(rule));
}
r.forEach(function(theRule) {
theRule.rule.event.params.rule_id = theRule.id;
engine.addRule(new Rule(theRule.rule));
});
}