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