diff --git a/lib/command-handler/index.js b/lib/command-handler/index.js index c367c60..e095c25 100644 --- a/lib/command-handler/index.js +++ b/lib/command-handler/index.js @@ -6,10 +6,11 @@ const commandParser = require('../command-parser'); const commandError = require('./error'); +const handlerHelp = require('./help'); const handlerBuy = require('./buy'); const handlerBalance = require('./balance'); const handlerPrice = require('./price'); -const handlerHelp = require('./help'); +const handlerListDownline = require('./listdownline'); function execute(msg, params, cb) { @@ -31,6 +32,9 @@ function execute(msg, params, cb) { else if (commandGroup === 'price') { handlerPrice(tokens, params, cb); } + else if (commandGroup === 'listdownline') { + handlerListDownline(tokens, params, cb); + } else if (commandGroup === 'help') { handlerHelp(cb) } diff --git a/lib/command-handler/listdownline.js b/lib/command-handler/listdownline.js new file mode 100644 index 0000000..7b6d88f --- /dev/null +++ b/lib/command-handler/listdownline.js @@ -0,0 +1,31 @@ +"use strict"; + +const commandError = require('./error'); +const coreapi = require('../coreapi'); + +const coreEndpoint = '/stores/downlines'; + +function help(keyword) { + return `Untuk list downline anda, 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 = { + terminal_name: params.from, + password: tokens[1], + }; + + coreapi(coreEndpoint, coreParams, 'GET', cb); +} + +module.exports = execute; \ No newline at end of file