-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1.47 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const path = require('path');
const pwd = path.join(__dirname, '..', '/.env');
require('dotenv').config({path: pwd});
const seneca = require('seneca')();
const trainer = require('./lib/trainer');
const util = require('./lib/util');
const modules = {
location: require('./lib/location')
};
let getFunctionByRoleAndCmd;
// select desired transport method
//const transportMethod = process.env['SENECA_TRANSPORT_METHOD'] || 'rabbitmq';
const patternPin = 'role:reporter';
// init database and then seneca and expose functions
trainer.init()
.then(() => {
seneca
//.use(transportMethod + '-transport')
.add(patternPin + ',cmd:*', (m, n) => {
n(null, {});
if(m.requesting_user_id === 'unknown') {
return console.log('doing nothing, requesting user is not logged in');
}
getFunctionByRoleAndCmd(m.origin_role, m.cmd)(m);
})
.add(patternPin + ',cmd:recommendationForPerson', trainer.recommendationForPerson)
.add(patternPin + ',cmd:recommendationForThing', trainer.recommendationForThing)
.add(patternPin + ',cmd:trainMultiple', trainer.trainMultiple)
.listen({type: 'tcp', port: 7010, pin: patternPin});
});
getFunctionByRoleAndCmd = (role, cmd) => {
console.log('incomming report for role', role, 'with cmd', cmd);
return modules[role] && modules[role][cmd] ? modules[role][cmd] : util.noop;
};