diff --git a/lib/command-handler/addbalance.js b/lib/command-handler/addbalance.js new file mode 100644 index 0000000..7a63027 --- /dev/null +++ b/lib/command-handler/addbalance.js @@ -0,0 +1,34 @@ +"use strict"; + +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>`; +} + +function execute(tokens, params, cb) { + + if (!tokens || tokens.length < 4) { + const responseParams = { + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` + } + + cb(null, null, responseParams); + return; + } + + const coreParams = { + asker_terminal_name: params.from, + destination_store_id: tokens[1], + amount: tokens[2], + asker_terminal_password: tokens[3], + additional_note: tokens.slice(4).join(' ') || '' + }; + + coreapi(coreEndpoint, coreParams, 'GET', cb); +} + +module.exports = execute; \ No newline at end of file diff --git a/lib/command-handler/index.js b/lib/command-handler/index.js index f4eb73c..a35a94a 100644 --- a/lib/command-handler/index.js +++ b/lib/command-handler/index.js @@ -13,6 +13,7 @@ const handlerPrice = require('./price'); const handlerListDownline = require('./listdownline'); const handlerDownlineInfo = require('./downlineinfo'); const handlerAddDownline = require('./adddownline'); +const handlerAddBalance = require('./addbalance'); function execute(msg, params, cb) { @@ -31,6 +32,9 @@ function execute(msg, params, cb) { else if (commandGroup === 'balance') { handlerBalance(tokens, params, cb); } + else if (commandGroup === 'addbalance') { + handlerAddBalance(tokens, params, cb); + } else if (commandGroup === 'price') { handlerPrice(tokens, params, cb); } diff --git a/lib/default-command.js b/lib/default-command.js index c1127a5..aeccc27 100644 --- a/lib/default-command.js +++ b/lib/default-command.js @@ -31,7 +31,7 @@ module.exports = { "transfer", "trf" ], - _addbalance: [ + addbalance: [ "addbalance", "addbal", "tambahsaldo"