I am trying out json-rules-engine and I thought of making an extremely simple express api to try it out. But, it turns out it's giving me a tough time.
The array I am trying to return in the body is always an empty one, even if I do console.log in the map it actually logs the messages.
I have this controller:
'use strict';
var rulesEngine = require('./rulesEngine');
exports.run = function(req, res) {
var outcome = rulesEngine.run(req.params.numberOfFaults);
res.json({outcome: outcome});
}
And the rulesEngine run method would be this one:
exports.run = function(numberOfFaults) {
var facts = {
personalFoulCount: numberOfFaults,
gameDuration: 40
},
outcome = [];
rulesEngine
.run(facts)
.then(events => { // run() returns events with truthy conditions
events.map(event => outcome.push(event.params.message))
})
return outcome;
};
Thanks!