Compare View
Commits (4)
Changes
Showing 6 changed files Side-by-side Diff
lib/command-handler/addbalance.js
... | ... | @@ -0,0 +1,34 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/stores/add-balance'; | |
7 | + | |
8 | +function help(keyword) { | |
9 | + return `Untuk menambah saldo downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.<IDDOWNLINE>.<JUMLAH>.<PIN>`; | |
10 | +} | |
11 | + | |
12 | +function execute(tokens, params, cb) { | |
13 | + | |
14 | + if (!tokens || tokens.length < 4) { | |
15 | + const responseParams = { | |
16 | + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` | |
17 | + } | |
18 | + | |
19 | + cb(null, null, responseParams); | |
20 | + return; | |
21 | + } | |
22 | + | |
23 | + const coreParams = { | |
24 | + asker_terminal_name: params.from, | |
25 | + destination_store_id: tokens[1], | |
26 | + amount: tokens[2], | |
27 | + asker_terminal_password: tokens[3], | |
28 | + additional_note: tokens.slice(4).join(' ') || '' | |
29 | + }; | |
30 | + | |
31 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
32 | +} | |
33 | + | |
34 | +module.exports = execute; | |
0 | 35 | \ No newline at end of file |
lib/command-handler/index.js
... | ... | @@ -13,6 +13,8 @@ const handlerPrice = require('./price'); |
13 | 13 | const handlerListDownline = require('./listdownline'); |
14 | 14 | const handlerDownlineInfo = require('./downlineinfo'); |
15 | 15 | const handlerAddDownline = require('./adddownline'); |
16 | +const handlerAddBalance = require('./addbalance'); | |
17 | +const handlerTransferBalance = require('./transferbalance'); | |
16 | 18 | |
17 | 19 | function execute(msg, params, cb) { |
18 | 20 | |
... | ... | @@ -31,6 +33,12 @@ function execute(msg, params, cb) { |
31 | 33 | else if (commandGroup === 'balance') { |
32 | 34 | handlerBalance(tokens, params, cb); |
33 | 35 | } |
36 | + else if (commandGroup === 'addbalance') { | |
37 | + handlerAddBalance(tokens, params, cb); | |
38 | + } | |
39 | + else if (commandGroup === 'transferbalance') { | |
40 | + handlerTransferBalance(tokens, params, cb); | |
41 | + } | |
34 | 42 | else if (commandGroup === 'price') { |
35 | 43 | handlerPrice(tokens, params, cb); |
36 | 44 | } |
lib/command-handler/transferbalance.js
... | ... | @@ -0,0 +1,35 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/stores/transfer-balance'; | |
7 | + | |
8 | +function help(keyword) { | |
9 | + return `Untuk transfer saldo ke downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.<IDDOWNLINE>.<JUMLAH>.<PIN>`; | |
10 | +} | |
11 | + | |
12 | +function execute(tokens, params, cb) { | |
13 | + | |
14 | + if (!tokens || tokens.length < 4) { | |
15 | + const responseParams = { | |
16 | + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` | |
17 | + } | |
18 | + | |
19 | + cb(null, null, responseParams); | |
20 | + return; | |
21 | + } | |
22 | + | |
23 | + const coreParams = { | |
24 | + asker_terminal_name: params.from, | |
25 | + destination_store_id: tokens[1], | |
26 | + amount: tokens[2], | |
27 | + asker_terminal_password: tokens[3], | |
28 | + additional_note: tokens.slice(4).join(' ') || '', | |
29 | + origin: params.origin | |
30 | + }; | |
31 | + | |
32 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
33 | +} | |
34 | + | |
35 | +module.exports = execute; | |
0 | 36 | \ No newline at end of file |
lib/default-command.js
... | ... | @@ -27,11 +27,11 @@ module.exports = { |
27 | 27 | "ceksaldo", |
28 | 28 | "checksaldo" |
29 | 29 | ], |
30 | - _transferbalance: [ | |
30 | + transferbalance: [ | |
31 | 31 | "transfer", |
32 | 32 | "trf" |
33 | 33 | ], |
34 | - _addbalance: [ | |
34 | + addbalance: [ | |
35 | 35 | "addbalance", |
36 | 36 | "addbal", |
37 | 37 | "tambahsaldo" |
... | ... | @@ -142,11 +142,13 @@ module.exports = { |
142 | 142 | 'newterminal', |
143 | 143 | 'registerterminal', |
144 | 144 | 'regterminal', |
145 | + 'createterminal', | |
145 | 146 | 'addmsisdn', |
146 | 147 | 'msisdnadd', |
147 | 148 | 'tambahmsisdn', |
148 | 149 | 'newmsisdn', |
149 | - 'regmsisdn' | |
150 | + 'regmsisdn', | |
151 | + 'createmsisdn' | |
150 | 152 | ], |
151 | 153 | _listdownlineterminal: [ |
152 | 154 | 'listdownlineterminal', |
package-lock.json