Commit 8fb3694e9e29156f590ad9e493654219e71f5844

Authored by Adhidarma Hadiwinoto
1 parent 1f6bf43975
Exists in master

downlineinfo can be select by store_name or terminal_name

Showing 1 changed file with 24 additions and 7 deletions Side-by-side Diff

lib/command-handler/downlineinfo.js
1   -"use strict";
  1 +const CORE_ENDPOINT = '/stores/view';
2 2  
3 3 const commandError = require('./error');
4 4 const coreapi = require('../coreapi');
5 5  
6   -const coreEndpoint = '/stores/view';
7   -
8 6 function help(keyword) {
9   - return `Untuk info sebuah downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN>`;
  7 + return `
  8 +Untuk info sebuah downline, ketik perintah dengan format:
  9 +
  10 +${keyword.toUpperCase()}.#<IDDOWNLINE>.<PIN>
  11 +atau
  12 +${keyword.toUpperCase()}.<TERMINALDOWNLINE>.<PIN>
  13 + `.trim();
10 14 }
11 15  
12 16 function execute(tokens, params, cb) {
13 17  
14 18 if (!tokens || tokens.length < 3) {
15 19 const responseParams = {
16   - body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`
  20 + body: `
  21 +${ commandError.ERR_INVALID_FORMAT }: ${params.msg}
  22 +
  23 +${ help(tokens[0]) }
  24 + `.trim(),
17 25 }
18 26  
19 27 cb(null, null, responseParams);
20 28 return;
21 29 }
22 30  
  31 + let downlineStoreId;
  32 + let downlineTerminalName;
  33 + if (tokens[1].indexOf('#') === 0) {
  34 + downlineStoreId = tokens[1].replace(/^#/, '');
  35 + } else {
  36 + downlineTerminalName = tokens[1];
  37 + }
  38 +
23 39 const coreParams = {
24 40 asker_terminal_name: params.from,
25 41 asker_terminal_password: tokens[2],
26   - downline_store_id: tokens[1].replace(/^#/, ''),
  42 + downline_store_id: downlineStoreId,
  43 + downline_terminal_name: downlineTerminalName,
27 44 };
28 45  
29   - coreapi(coreEndpoint, coreParams, 'GET', cb);
  46 + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb);
30 47 }
31 48  
32 49 module.exports = execute;
33 50 \ No newline at end of file