diff --git a/lib/command-handler/addbalance.js b/lib/command-handler/addbalance.js index 7a63027..c92d0d2 100644 --- a/lib/command-handler/addbalance.js +++ b/lib/command-handler/addbalance.js @@ -1,34 +1,50 @@ -"use strict"; +const CORE_ENDPOINT = '/stores/add-balance'; const commandError = require('./error'); const coreapi = require('../coreapi'); -const coreEndpoint = '/stores/add-balance'; - function help(keyword) { - return `Untuk menambah saldo downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.<IDDOWNLINE>.<JUMLAH>.<PIN>`; + return ` +Untuk menambah saldo downline, ketik perintah dengan format: + +${keyword.toUpperCase()}.#<IDDOWNLINE>.<JUMLAH>.<PIN> +atau +${keyword.toUpperCase()}.<TERMINALDOWNLINE>.<JUMLAH>.<PIN> +`.trim(); } function execute(tokens, params, cb) { - if (!tokens || tokens.length < 4) { 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 destinationStoreId; + let destinationTerminalName; + if (tokens[1].indexOf('#') === 0) { + destinationStoreId = tokens[1].replace(/^#/, ''); + } else { + destinationTerminalName = tokens[1]; + } + const coreParams = { asker_terminal_name: params.from, - destination_store_id: tokens[1], + destination_store_id: destinationStoreId, + destination_terminal_name: destinationTerminalName, amount: tokens[2], asker_terminal_password: tokens[3], additional_note: tokens.slice(4).join(' ') || '' }; - coreapi(coreEndpoint, coreParams, 'GET', cb); + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb); } module.exports = execute; \ No newline at end of file diff --git a/lib/command-handler/price.js b/lib/command-handler/price.js index 496e275..18412a5 100644 --- a/lib/command-handler/price.js +++ b/lib/command-handler/price.js @@ -1,10 +1,8 @@ -"use strict"; +const CORE_ENDPOINT = '/services/pricelist'; const commandError = require('./error'); const coreapi = require('../coreapi'); -const coreEndpoint = '/services/pricelist'; - function help(keyword) { return `Untuk cek harga, ketik perintah dengan format: ${ keyword.toUpperCase() }.<KODEPRODUK>.<PIN>`; } @@ -27,7 +25,7 @@ function execute(tokens, params, cb) { postpaid: 0 }; - coreapi(coreEndpoint, coreParams, 'GET', cb); + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb); } module.exports = execute; \ No newline at end of file