Commit 5c5aa9c4426fd10431966069fe636f403350c21f
1 parent
bb75b53b6a
Exists in
master
transferbalance support nama terminal sebagai tujuan
Showing 1 changed file with 18 additions and 8 deletions Side-by-side Diff
lib/command-handler/transferbalance.js
1 | -"use strict"; | |
1 | +const CORE_ENDPOINT = '/stores/transfer-balance'; | |
2 | 2 | |
3 | 3 | const commandError = require('./error'); |
4 | 4 | const coreapi = require('../coreapi'); |
5 | 5 | |
6 | -const coreEndpoint = '/stores/transfer-balance'; | |
7 | - | |
8 | 6 | function help(keyword) { |
9 | - return `Untuk transfer saldo ke downline, ketik perintah dengan format: | |
10 | -${ keyword.toUpperCase() }.<IDDOWNLINE>.<JUMLAH>.<PIN> | |
7 | + return ` | |
8 | +Untuk transfer saldo ke downline, ketik perintah dengan format: | |
9 | + | |
10 | +${keyword.toUpperCase()}.#<IDDOWNLINE>.<JUMLAH>.<PIN> | |
11 | +atau | |
12 | +${keyword.toUpperCase()}.<TERMINALDOWNLINE>.<JUMLAH>.<PIN> | |
11 | 13 | `.trim(); |
12 | 14 | } |
13 | 15 | |
14 | 16 | function execute(tokens, params, cb) { |
15 | - | |
16 | 17 | if (!tokens || tokens.length < 4) { |
17 | 18 | const responseParams = { |
18 | 19 | body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` |
... | ... | @@ -22,16 +23,25 @@ function execute(tokens, params, cb) { |
22 | 23 | return; |
23 | 24 | } |
24 | 25 | |
26 | + let destinationStoreId; | |
27 | + let destinationTerminalName; | |
28 | + if (tokens[1].indexOf('#') === 0) { | |
29 | + destinationStoreId = tokens[1].replace(/^#/, ''); | |
30 | + } else { | |
31 | + destinationTerminalName = tokens[1]; | |
32 | + } | |
33 | + | |
25 | 34 | const coreParams = { |
26 | 35 | asker_terminal_name: params.from, |
27 | - destination_store_id: tokens[1], | |
36 | + destination_store_id: destinationStoreId, | |
37 | + destination_terminal_name: destinationTerminalName, | |
28 | 38 | amount: tokens[2], |
29 | 39 | asker_terminal_password: tokens[3], |
30 | 40 | additional_note: tokens.slice(4).join(' ') || '', |
31 | 41 | origin: params.origin |
32 | 42 | }; |
33 | 43 | |
34 | - coreapi(coreEndpoint, coreParams, 'GET', cb); | |
44 | + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb); | |
35 | 45 | } |
36 | 46 | |
37 | 47 | module.exports = execute; |
38 | 48 | \ No newline at end of file |