diff --git a/lib/command-handler/index.js b/lib/command-handler/index.js index 98407e8..33a56e0 100644 --- a/lib/command-handler/index.js +++ b/lib/command-handler/index.js @@ -21,6 +21,7 @@ const handlerHelp = require('./help'); const handlerListDownline = require('./listdownline'); const handlerListTerminal = require('./listterminal'); const handlerPrice = require('./price'); +const handlerSupplierBalances = require('./supplierbalances'); const handlerTransferBalance = require('./transferbalance'); function execute(msg, params, cb) { @@ -79,6 +80,9 @@ function execute(msg, params, cb) { else if (commandGroup === 'disabledownline') { handlerDisableDownline(tokens, params, cb); } + else if (commandGroup === 'supplierbalances') { + handlerSupplierBalances(tokens, params, cb); + } else if (commandGroup === 'help') { handlerHelp(cb) } diff --git a/lib/command-handler/supplierbalances.js b/lib/command-handler/supplierbalances.js new file mode 100644 index 0000000..f0f01a7 --- /dev/null +++ b/lib/command-handler/supplierbalances.js @@ -0,0 +1,31 @@ +"use strict"; + +const commandError = require('./error'); +const coreapi = require('../coreapi'); + +const coreEndpoint = '/services/suppliers/balances'; + +function help(keyword) { + return `Untuk melihat sisa saldo terkini di supplier, ketik perintah dengan format: ${ keyword.toUpperCase() }.<PIN>`; +} + +function execute(tokens, params, cb) { + + if (!tokens || tokens.length < 2) { + const responseParams = { + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` + } + + cb(null, null, responseParams); + return; + } + + const coreParams = { + asker_terminal_name: params.from, + asker_terminal_password: tokens[1], + }; + + coreapi(coreEndpoint, coreParams, 'GET', cb); +} + +module.exports = execute; \ No newline at end of file diff --git a/lib/default-command.js b/lib/default-command.js index 399fdc6..a541b36 100644 --- a/lib/default-command.js +++ b/lib/default-command.js @@ -156,6 +156,16 @@ module.exports = { 'tambahterminal', 'terminaladd', ], + supplierbalances: [ + 'supplier', + 'supplierbal', + 'supplierbalance', + 'supplierbalances', + 'suppliers', + 'suppliersbal', + 'suppliersbalance', + 'suppliersbalances', + ], _setmarkup: [ 'markup' ]