Commit 1aee6daf6a555574e51ac5ee6d0abee10dcc44d5

Authored by Adhidarma Hadiwinoto
1 parent 478db8b4ca
Exists in master

LISTTERMINAL multiple formats

Showing 1 changed file with 30 additions and 5 deletions Side-by-side Diff

lib/command-handler/listterminal.js
... ... @@ -4,27 +4,52 @@ const commandError = require('./error');
4 4 const coreapi = require('../coreapi');
5 5  
6 6 function help(keyword) {
7   - return `Untuk list terminal anda, ketik perintah dengan format: ${ keyword.toUpperCase() }.<PIN> atau ${ keyword.toUpperCase() }.<IDDOWNLINE>.<PIN>`;
  7 + return `
  8 +Untuk list terminal anda, ketik perintah dengan format:
  9 +
  10 +${ keyword.toUpperCase() }.<PIN>
  11 +atau
  12 +${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN>
  13 +atau
  14 +${ keyword.toUpperCase() }.<TERMINALDOWNLINE>.<PIN>
  15 + `.trim();
8 16 }
9 17  
10 18 function execute(tokens, params, cb) {
11   -
  19 +
12 20 if (!tokens || tokens.length < 2) {
13 21 const responseParams = {
14   - body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`
  22 + body: `
  23 +${ commandError.ERR_INVALID_FORMAT }: ${params.msg}
  24 +
  25 +${ help(tokens[0]) }
  26 + `.trim(),
15 27 }
16 28  
17 29 cb(null, null, responseParams);
18 30 return;
19 31 }
20 32  
  33 + const idxDownline = (tokens.length <= 2) ? null : 1;
21 34 const idxPin = (tokens.length <= 2) ? 1 : 2;
22 35  
  36 + let downline;
  37 + let downlineStoreId;
  38 + let downlineTerminalName;
  39 + if (idxDownline) {
  40 + downline = tokens[idxDownline];
  41 + if (downline.indexOf('#') === 0) {
  42 + downlineStoreId = downline.replace(/^#/, '');
  43 + } else {
  44 + downlineTerminalName = downline;
  45 + }
  46 + }
  47 +
23 48 const coreParams = {
24 49 asker_terminal_name: params.from,
25 50 asker_terminal_password: tokens[ idxPin ],
26   - store_id: tokens[1].replace(/^#/, ''),
27   -
  51 + store_id: downlineStoreId,
  52 + terminal_name: downlineTerminalName,
28 53 };
29 54  
30 55 coreapi(CORE_ENDPOINT, coreParams, 'GET', cb);