Commit 90fbdbf1de0776b8f2535e37ef4cc410b68c306d
1 parent
e8bf179ec4
Exists in
master
Handler list downline
Showing 2 changed files with 36 additions and 1 deletions Side-by-side Diff
lib/command-handler/index.js
... | ... | @@ -6,10 +6,11 @@ const commandParser = require('../command-parser'); |
6 | 6 | |
7 | 7 | const commandError = require('./error'); |
8 | 8 | |
9 | +const handlerHelp = require('./help'); | |
9 | 10 | const handlerBuy = require('./buy'); |
10 | 11 | const handlerBalance = require('./balance'); |
11 | 12 | const handlerPrice = require('./price'); |
12 | -const handlerHelp = require('./help'); | |
13 | +const handlerListDownline = require('./listdownline'); | |
13 | 14 | |
14 | 15 | function execute(msg, params, cb) { |
15 | 16 | |
... | ... | @@ -31,6 +32,9 @@ function execute(msg, params, cb) { |
31 | 32 | else if (commandGroup === 'price') { |
32 | 33 | handlerPrice(tokens, params, cb); |
33 | 34 | } |
35 | + else if (commandGroup === 'listdownline') { | |
36 | + handlerListDownline(tokens, params, cb); | |
37 | + } | |
34 | 38 | else if (commandGroup === 'help') { |
35 | 39 | handlerHelp(cb) |
36 | 40 | } |
lib/command-handler/listdownline.js
... | ... | @@ -0,0 +1,31 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/stores/downlines'; | |
7 | + | |
8 | +function help(keyword) { | |
9 | + return `Untuk list downline anda, ketik perintah dengan format: ${ keyword.toUpperCase() }.<PIN>`; | |
10 | +} | |
11 | + | |
12 | +function execute(tokens, params, cb) { | |
13 | + | |
14 | + if (!tokens || tokens.length < 2) { | |
15 | + const responseParams = { | |
16 | + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` | |
17 | + } | |
18 | + | |
19 | + cb(null, null, responseParams); | |
20 | + return; | |
21 | + } | |
22 | + | |
23 | + const coreParams = { | |
24 | + terminal_name: params.from, | |
25 | + password: tokens[1], | |
26 | + }; | |
27 | + | |
28 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
29 | +} | |
30 | + | |
31 | +module.exports = execute; | |
0 | 32 | \ No newline at end of file |