diff --git a/lib/command-handler/downlineinfo.js b/lib/command-handler/downlineinfo.js index ee24b8f..087a1dd 100644 --- a/lib/command-handler/downlineinfo.js +++ b/lib/command-handler/downlineinfo.js @@ -1,32 +1,49 @@ -"use strict"; +const CORE_ENDPOINT = '/stores/view'; const commandError = require('./error'); const coreapi = require('../coreapi'); -const coreEndpoint = '/stores/view'; - function help(keyword) { - return `Untuk info sebuah downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN>`; + return ` +Untuk info sebuah downline, ketik perintah dengan format: + +${keyword.toUpperCase()}.#<IDDOWNLINE>.<PIN> +atau +${keyword.toUpperCase()}.<TERMINALDOWNLINE>.<PIN> + `.trim(); } function execute(tokens, params, cb) { if (!tokens || tokens.length < 3) { const responseParams = { - body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` + body: ` +${ commandError.ERR_INVALID_FORMAT }: ${params.msg} + +${ help(tokens[0]) } + `.trim(), } cb(null, null, responseParams); return; } + let downlineStoreId; + let downlineTerminalName; + if (tokens[1].indexOf('#') === 0) { + downlineStoreId = tokens[1].replace(/^#/, ''); + } else { + downlineTerminalName = tokens[1]; + } + const coreParams = { asker_terminal_name: params.from, asker_terminal_password: tokens[2], - downline_store_id: tokens[1].replace(/^#/, ''), + downline_store_id: downlineStoreId, + downline_terminal_name: downlineTerminalName, }; - coreapi(coreEndpoint, coreParams, 'GET', cb); + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb); } module.exports = execute; \ No newline at end of file