From 1aee6daf6a555574e51ac5ee6d0abee10dcc44d5 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Mon, 18 Nov 2019 15:38:35 +0700 Subject: [PATCH] LISTTERMINAL multiple formats --- lib/command-handler/listterminal.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/command-handler/listterminal.js b/lib/command-handler/listterminal.js index ead4941..8d6e323 100644 --- a/lib/command-handler/listterminal.js +++ b/lib/command-handler/listterminal.js @@ -4,27 +4,52 @@ const commandError = require('./error'); const coreapi = require('../coreapi'); function help(keyword) { - return `Untuk list terminal anda, ketik perintah dengan format: ${ keyword.toUpperCase() }.<PIN> atau ${ keyword.toUpperCase() }.<IDDOWNLINE>.<PIN>`; + return ` +Untuk list terminal anda, ketik perintah dengan format: + +${ keyword.toUpperCase() }.<PIN> +atau +${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN> +atau +${ keyword.toUpperCase() }.<TERMINALDOWNLINE>.<PIN> + `.trim(); } function execute(tokens, params, cb) { - + if (!tokens || tokens.length < 2) { 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; } + const idxDownline = (tokens.length <= 2) ? null : 1; const idxPin = (tokens.length <= 2) ? 1 : 2; + let downline; + let downlineStoreId; + let downlineTerminalName; + if (idxDownline) { + downline = tokens[idxDownline]; + if (downline.indexOf('#') === 0) { + downlineStoreId = downline.replace(/^#/, ''); + } else { + downlineTerminalName = downline; + } + } + const coreParams = { asker_terminal_name: params.from, asker_terminal_password: tokens[ idxPin ], - store_id: tokens[1].replace(/^#/, ''), - + store_id: downlineStoreId, + terminal_name: downlineTerminalName, }; coreapi(CORE_ENDPOINT, coreParams, 'GET', cb); -- 1.9.0