From f77a8568e30a18e3b94eadac525a8244bb955f47 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Fri, 5 Jul 2019 14:58:53 +0700 Subject: [PATCH] Enable/disable downline --- lib/command-handler/disabledownline.js | 33 +++++++++++++++++++++++++++++++++ lib/command-handler/enabledownline.js | 33 +++++++++++++++++++++++++++++++++ lib/command-handler/index.js | 8 ++++++++ lib/coreapi/core-version.js | 2 +- lib/default-command.js | 4 ++-- 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 lib/command-handler/disabledownline.js create mode 100644 lib/command-handler/enabledownline.js diff --git a/lib/command-handler/disabledownline.js b/lib/command-handler/disabledownline.js new file mode 100644 index 0000000..ae5925b --- /dev/null +++ b/lib/command-handler/disabledownline.js @@ -0,0 +1,33 @@ +"use strict"; + +const coreEndpoint = '/stores/disable'; + +const commandError = require('./error'); +const coreapi = require('../coreapi'); + +function help(keyword) { + return `Untuk menonaktifkan sebuah downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN>`; +} + +function execute(tokens, params, cb) { + + if (!tokens || tokens.length < 3) { + const responseParams = { + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` + } + + cb(null, null, responseParams); + return; + } + + const coreParams = { + origin: params.origin, + asker_terminal_name: params.from, + store_id: tokens[1].replace(/^#/, ''), + asker_terminal_password: tokens[2] + }; + + coreapi(coreEndpoint, coreParams, 'GET', cb); +} + +module.exports = execute; \ No newline at end of file diff --git a/lib/command-handler/enabledownline.js b/lib/command-handler/enabledownline.js new file mode 100644 index 0000000..5094d84 --- /dev/null +++ b/lib/command-handler/enabledownline.js @@ -0,0 +1,33 @@ +"use strict"; + +const coreEndpoint = '/stores/enable'; + +const commandError = require('./error'); +const coreapi = require('../coreapi'); + +function help(keyword) { + return `Untuk mengaktifkan kembali sebuah downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN>`; +} + +function execute(tokens, params, cb) { + + if (!tokens || tokens.length < 3) { + const responseParams = { + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` + } + + cb(null, null, responseParams); + return; + } + + const coreParams = { + origin: params.origin, + asker_terminal_name: params.from, + store_id: tokens[1].replace(/^#/, ''), + asker_terminal_password: tokens[2] + }; + + 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 8561c15..9ae305c 100644 --- a/lib/command-handler/index.js +++ b/lib/command-handler/index.js @@ -18,6 +18,8 @@ const handlerTransferBalance = require('./transferbalance'); const handlerListTerminal = require('./listterminal'); const handlerAddTerminal = require('./addterminal'); const handlerChangePin = require('./changepin'); +const handlerEnableDownline = require('./enabledownline'); +const handlerDisableDownline = require('./disabledownline'); function execute(msg, params, cb) { @@ -63,6 +65,12 @@ function execute(msg, params, cb) { else if (commandGroup === 'changepin') { handlerChangePin(tokens, params, cb); } + else if (commandGroup === 'enabledownline') { + handlerEnableDownline(tokens, params, cb); + } + else if (commandGroup === 'disabledownline') { + handlerDisableDownline(tokens, params, cb); + } else if (commandGroup === 'help') { handlerHelp(cb) } diff --git a/lib/coreapi/core-version.js b/lib/coreapi/core-version.js index e8aabc1..4cedaf7 100644 --- a/lib/coreapi/core-version.js +++ b/lib/coreapi/core-version.js @@ -1,6 +1,6 @@ "use strict"; -const MINIMUM_VERSION = 'v1.33.1-29'; +const MINIMUM_VERSION = 'v1.33.1-30'; const util = require('util'); const naturalCompare = require('natural-compare-lite'); diff --git a/lib/default-command.js b/lib/default-command.js index 6ccfa7a..ca95da4 100644 --- a/lib/default-command.js +++ b/lib/default-command.js @@ -74,7 +74,7 @@ module.exports = { "sd", "sdl", ], - _disabledownline: [ + disabledownline: [ "disabledl", "disabledownline", "disablemitra", @@ -85,7 +85,7 @@ module.exports = { "nonaktifkanmitra", "nonaktifmitra", ], - _enabledownline: [ + enabledownline: [ "aktifkandl", "aktifkandownline", "aktifkanmitra", -- 1.9.0