Commit 13b04dfe0df64ba87c6127d2d86d1553c106e848
1 parent
3341641eb4
Exists in
master
ESLINT on command-handler.index
Showing 1 changed file with 35 additions and 56 deletions Inline Diff
lib/command-handler/index.js
1 | const logger = require('tektrans-logger'); | 1 | const logger = require('tektrans-logger'); |
2 | 2 | ||
3 | const commandParser = require('../command-parser'); | 3 | const commandParser = require('../command-parser'); |
4 | 4 | ||
5 | const commandError = require('./error'); | 5 | const commandError = require('./error'); |
6 | 6 | ||
7 | const handlerAddBalance = require('./addbalance'); | 7 | const handlerAddBalance = require('./addbalance'); |
8 | const handlerAddDownline = require('./adddownline'); | 8 | const handlerAddDownline = require('./adddownline'); |
9 | const handlerAddTerminal = require('./addterminal'); | 9 | const handlerAddTerminal = require('./addterminal'); |
10 | const handlerBalance = require('./balance'); | 10 | const handlerBalance = require('./balance'); |
11 | const handlerBuy = require('./buy'); | 11 | const handlerBuy = require('./buy'); |
12 | const handlerChangePin = require('./changepin'); | 12 | const handlerChangePin = require('./changepin'); |
13 | const handlerClaimBonus = require('./claimbonus'); | 13 | const handlerClaimBonus = require('./claimbonus'); |
14 | const handlerComplain = require('./complain'); | 14 | const handlerComplain = require('./complain'); |
15 | const handlerDaySummary = require('./daysummary'); | 15 | const handlerDaySummary = require('./daysummary'); |
16 | const handlerDepositTicket = require('./depositticket'); | 16 | const handlerDepositTicket = require('./depositticket'); |
17 | const handlerDisableDownline = require('./disabledownline'); | 17 | const handlerDisableDownline = require('./disabledownline'); |
18 | const handlerDownlineInfo = require('./downlineinfo'); | 18 | const handlerDownlineInfo = require('./downlineinfo'); |
19 | const handlerEnableDownline = require('./enabledownline'); | 19 | const handlerEnableDownline = require('./enabledownline'); |
20 | const handlerHelp = require('./help'); | 20 | const handlerHelp = require('./help'); |
21 | const handlerInquiry = require('./inquiry'); | 21 | const handlerInquiry = require('./inquiry'); |
22 | const handlerListComplain = require('./listcomplain'); | 22 | const handlerListComplain = require('./listcomplain'); |
23 | const handlerListDeposit = require('./listdeposit'); | 23 | const handlerListDeposit = require('./listdeposit'); |
24 | const handlerListDownline = require('./listdownline'); | 24 | const handlerListDownline = require('./listdownline'); |
25 | const handlerListTerminal = require('./listterminal'); | 25 | const handlerListTerminal = require('./listterminal'); |
26 | const handlerListTrx = require('./listtrx'); | 26 | const handlerListTrx = require('./listtrx'); |
27 | const handlerPay = require('./pay'); | 27 | const handlerPay = require('./pay'); |
28 | const handlerPrice = require('./price'); | 28 | const handlerPrice = require('./price'); |
29 | const handlerSupplierBalances = require('./supplierbalances'); | 29 | const handlerSupplierBalances = require('./supplierbalances'); |
30 | const handlerTemporaryBonus = require('./temporarybonus'); | 30 | const handlerTemporaryBonus = require('./temporarybonus'); |
31 | const handlerTransferBalance = require('./transferbalance'); | 31 | const handlerTransferBalance = require('./transferbalance'); |
32 | 32 | ||
33 | function execute(msg, params, cb) { | 33 | function execute(msg, params, cb) { |
34 | 34 | if (typeof msg !== 'string' || !msg.trim()) { | |
35 | if ( typeof msg !== 'string' || !msg.trim() ) { | ||
36 | cb(commandError.ERR_EMPTY_MESSAGE); | 35 | cb(commandError.ERR_EMPTY_MESSAGE); |
37 | return; | 36 | return; |
38 | } | 37 | } |
39 | 38 | ||
40 | const tokens = commandParser.splitToken(msg); | 39 | const tokens = commandParser.splitToken(msg); |
41 | const commandGroup = commandParser.extractCommandGroup(tokens); | 40 | const commandGroup = commandParser.extractCommandGroup(tokens); |
41 | |||
42 | // eslint-disable-next-line no-param-reassign | ||
42 | params.commandGroup = commandGroup; | 43 | params.commandGroup = commandGroup; |
43 | logger.info('Processing message from partner', { msg, params, tokens, commandGroup }); | 44 | |
45 | logger.info('Processing message from partner', { | ||
46 | msg, params, tokens, commandGroup, | ||
47 | }); | ||
44 | 48 | ||
45 | if (!commandGroup || commandGroup === 'buy') { | 49 | if (!commandGroup || commandGroup === 'buy') { |
46 | handlerBuy(tokens, params, cb); | 50 | handlerBuy(tokens, params, cb); |
47 | } | 51 | } else if (commandGroup === 'balance') { |
48 | else if (commandGroup === 'balance') { | ||
49 | handlerBalance(tokens, params, cb); | 52 | handlerBalance(tokens, params, cb); |
50 | } | 53 | } else if (commandGroup === 'addbalance') { |
51 | else if (commandGroup === 'addbalance') { | ||
52 | handlerAddBalance(tokens, params, cb); | 54 | handlerAddBalance(tokens, params, cb); |
53 | } | 55 | } else if (commandGroup === 'transferbalance') { |
54 | else if (commandGroup === 'transferbalance') { | ||
55 | handlerTransferBalance(tokens, params, cb); | 56 | handlerTransferBalance(tokens, params, cb); |
56 | } | 57 | } else if (commandGroup === 'price') { |
57 | else if (commandGroup === 'price') { | ||
58 | handlerPrice(tokens, params, cb); | 58 | handlerPrice(tokens, params, cb); |
59 | } | 59 | } else if (commandGroup === 'listdownline') { |
60 | else if (commandGroup === 'listdownline') { | ||
61 | handlerListDownline(tokens, params, cb); | 60 | handlerListDownline(tokens, params, cb); |
62 | } | 61 | } else if (commandGroup === 'downlineinfo') { |
63 | else if (commandGroup === 'downlineinfo') { | ||
64 | handlerDownlineInfo(tokens, params, cb); | 62 | handlerDownlineInfo(tokens, params, cb); |
65 | } | 63 | } else if (commandGroup === 'adddownline') { |
66 | else if (commandGroup === 'adddownline') { | ||
67 | handlerAddDownline(tokens, params, cb); | 64 | handlerAddDownline(tokens, params, cb); |
68 | } | 65 | } else if (commandGroup === 'listterminal') { |
69 | else if (commandGroup === 'listterminal') { | ||
70 | handlerListTerminal(tokens, params, cb); | 66 | handlerListTerminal(tokens, params, cb); |
71 | } | 67 | } else if (commandGroup === 'listtrx' || commandGroup === 'listtrxall') { |
72 | else if (commandGroup === 'listtrx' || commandGroup === 'listtrxall') { | ||
73 | handlerListTrx(tokens, params, cb); | 68 | handlerListTrx(tokens, params, cb); |
74 | } | 69 | } else if (commandGroup === 'listdeposit') { |
75 | else if (commandGroup === 'listdeposit') { | ||
76 | handlerListDeposit(tokens, params, cb); | 70 | handlerListDeposit(tokens, params, cb); |
77 | } | 71 | } else if (commandGroup === 'addterminal') { |
78 | else if (commandGroup === 'addterminal') { | ||
79 | handlerAddTerminal(tokens, params, cb); | 72 | handlerAddTerminal(tokens, params, cb); |
80 | } | 73 | } else if (commandGroup === 'changepin') { |
81 | else if (commandGroup === 'changepin') { | ||
82 | handlerChangePin(tokens, params, cb); | 74 | handlerChangePin(tokens, params, cb); |
83 | } | 75 | } else if (commandGroup === 'enabledownline') { |
84 | else if (commandGroup === 'enabledownline') { | ||
85 | handlerEnableDownline(tokens, params, cb); | 76 | handlerEnableDownline(tokens, params, cb); |
86 | } | 77 | } else if (commandGroup === 'daysummary' || commandGroup === 'daysummaryall') { |
87 | else if (commandGroup === 'daysummary' || commandGroup === 'daysummaryall') { | ||
88 | handlerDaySummary(tokens, params, cb); | 78 | handlerDaySummary(tokens, params, cb); |
89 | } | 79 | } else if (commandGroup === 'depositticket') { |
90 | else if (commandGroup === 'depositticket') { | ||
91 | handlerDepositTicket(tokens, params, cb); | 80 | handlerDepositTicket(tokens, params, cb); |
92 | } | 81 | } else if (commandGroup === 'disabledownline') { |
93 | else if (commandGroup === 'disabledownline') { | ||
94 | handlerDisableDownline(tokens, params, cb); | 82 | handlerDisableDownline(tokens, params, cb); |
95 | } | 83 | } else if (commandGroup === 'supplierbalances') { |
96 | else if (commandGroup === 'supplierbalances') { | ||
97 | handlerSupplierBalances(tokens, params, cb); | 84 | handlerSupplierBalances(tokens, params, cb); |
98 | } | 85 | } else if (commandGroup === 'claimbonus') { |
99 | else if (commandGroup === 'claimbonus') { | ||
100 | handlerClaimBonus(tokens, params, cb); | 86 | handlerClaimBonus(tokens, params, cb); |
101 | } | 87 | } else if (commandGroup === 'temporarybonus') { |
102 | else if (commandGroup === 'temporarybonus') { | ||
103 | handlerTemporaryBonus(tokens, params, cb); | 88 | handlerTemporaryBonus(tokens, params, cb); |
104 | } | 89 | } else if (commandGroup === 'inquiry') { |
105 | else if (commandGroup === 'inquiry') { | ||
106 | handlerInquiry(tokens, params, cb); | 90 | handlerInquiry(tokens, params, cb); |
107 | } | 91 | } else if (commandGroup === 'pay') { |
108 | else if (commandGroup === 'pay') { | ||
109 | handlerPay(tokens, params, cb); | 92 | handlerPay(tokens, params, cb); |
110 | } | 93 | } else if (commandGroup === 'complain') { |
111 | else if (commandGroup === 'complain') { | ||
112 | handlerComplain(tokens, params, cb); | 94 | handlerComplain(tokens, params, cb); |
113 | } | 95 | } else if (commandGroup === 'listcomplain') { |
114 | else if (commandGroup === 'listcomplain') { | ||
115 | handlerListComplain(tokens, params, cb); | 96 | handlerListComplain(tokens, params, cb); |
116 | } | 97 | } else if (commandGroup === 'help') { |
117 | else if (commandGroup === 'help') { | 98 | handlerHelp(tokens, params, cb); |
118 | handlerHelp(tokens, params, cb) | 99 | } else { |
119 | } | ||
120 | else { |