index.js
3.16 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
const logger = require('komodo-sdk/logger');
const commandParser = require('../command-parser');
const commandError = require('./error');
const handlerAddBalance = require('./addbalance');
const handlerAddDownline = require('./adddownline');
const handlerAddTerminal = require('./addterminal');
const handlerBalance = require('./balance');
const handlerBuy = require('./buy');
const handlerChangePin = require('./changepin');
const handlerDaySummary = require('./daysummary');
const handlerDepositTicket = require('./depositticket');
const handlerDisableDownline = require('./disabledownline');
const handlerDownlineInfo = require('./downlineinfo');
const handlerEnableDownline = require('./enabledownline');
const handlerHelp = require('./help');
const handlerListDownline = require('./listdownline');
const handlerListTerminal = require('./listterminal');
const handlerPrice = require('./price');
const handlerSupplierBalances = require('./supplierbalances');
const handlerTransferBalance = require('./transferbalance');
function execute(msg, params, cb) {
if ( typeof msg !== 'string' || !msg.trim() ) {
cb(commandError.ERR_EMPTY_MESSAGE);
return;
}
const tokens = commandParser.splitToken(msg);
const commandGroup = commandParser.extractCommandGroup(tokens);
logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup});
if (!commandGroup || commandGroup === 'buy') {
handlerBuy(tokens, params, cb);
}
else if (commandGroup === 'balance') {
handlerBalance(tokens, params, cb);
}
else if (commandGroup === 'addbalance') {
handlerAddBalance(tokens, params, cb);
}
else if (commandGroup === 'transferbalance') {
handlerTransferBalance(tokens, params, cb);
}
else if (commandGroup === 'price') {
handlerPrice(tokens, params, cb);
}
else if (commandGroup === 'listdownline') {
handlerListDownline(tokens, params, cb);
}
else if (commandGroup === 'downlineinfo') {
handlerDownlineInfo(tokens, params, cb);
}
else if (commandGroup === 'adddownline') {
handlerAddDownline(tokens, params, cb);
}
else if (commandGroup === 'listterminal') {
handlerListTerminal(tokens, params, cb);
}
else if (commandGroup === 'addterminal') {
handlerAddTerminal(tokens, params, cb);
}
else if (commandGroup === 'changepin') {
handlerChangePin(tokens, params, cb);
}
else if (commandGroup === 'enabledownline') {
handlerEnableDownline(tokens, params, cb);
}
else if (commandGroup === 'daysummary') {
handlerDaySummary(tokens, params, cb);
}
else if (commandGroup === 'depositticket') {
handlerDepositTicket(tokens, params, cb);
}
else if (commandGroup === 'disabledownline') {
handlerDisableDownline(tokens, params, cb);
}
else if (commandGroup === 'supplierbalances') {
handlerSupplierBalances(tokens, params, cb);
}
else if (commandGroup === 'help') {
handlerHelp(cb)
}
else {
cb(commandError.ERR_NOT_IMPLEMENTED);
}
}
module.exports = execute;