Commit 273862fe5841a51d2f5a24237203c9c449023c27
1 parent
b4c2385a5e
Exists in
master
Handler addbalance
Showing 3 changed files with 39 additions and 1 deletions 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,7 @@ 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'); | |
16 | 17 | |
17 | 18 | function execute(msg, params, cb) { |
18 | 19 | |
... | ... | @@ -31,6 +32,9 @@ function execute(msg, params, cb) { |
31 | 32 | else if (commandGroup === 'balance') { |
32 | 33 | handlerBalance(tokens, params, cb); |
33 | 34 | } |
35 | + else if (commandGroup === 'addbalance') { | |
36 | + handlerAddBalance(tokens, params, cb); | |
37 | + } | |
34 | 38 | else if (commandGroup === 'price') { |
35 | 39 | handlerPrice(tokens, params, cb); |
36 | 40 | } |