Commit b39444c35e25a85a04fadf73046a03d6a32e4c51
1 parent
8e3a1cb0d9
Exists in
master
Command adddownline
Showing 3 changed files with 55 additions and 0 deletions Side-by-side Diff
lib/command-handler/adddownline.js
... | ... | @@ -0,0 +1,32 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/stores/create'; | |
7 | + | |
8 | +function help(keyword) { | |
9 | + return `Untuk membuat downline baru, ketik perintah dengan format: ${ keyword.toUpperCase() }.<NAMADOWNLINE>.<PIN>`; | |
10 | +} | |
11 | + | |
12 | +function execute(tokens, params, cb) { | |
13 | + | |
14 | + if (!tokens || tokens.length < 3) { | |
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 | + asker_terminal_name: params.from, | |
25 | + new_store_name: tokens[1], | |
26 | + asker_terminal_password: tokens[2], | |
27 | + }; | |
28 | + | |
29 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
30 | +} | |
31 | + | |
32 | +module.exports = execute; | |
0 | 33 | \ No newline at end of file |
lib/command-handler/index.js
... | ... | @@ -12,6 +12,7 @@ const handlerBalance = require('./balance'); |
12 | 12 | const handlerPrice = require('./price'); |
13 | 13 | const handlerListDownline = require('./listdownline'); |
14 | 14 | const handlerDownlineInfo = require('./downlineinfo'); |
15 | +const handlerAddDownline = require('./adddownline'); | |
15 | 16 | |
16 | 17 | function execute(msg, params, cb) { |
17 | 18 | |
... | ... | @@ -39,6 +40,9 @@ function execute(msg, params, cb) { |
39 | 40 | else if (commandGroup === 'downlineinfo') { |
40 | 41 | handlerDownlineInfo(tokens, params, cb); |
41 | 42 | } |
43 | + else if (commandGroup === 'adddownline') { | |
44 | + handlerAddDownline(tokens, params, cb); | |
45 | + } | |
42 | 46 | else if (commandGroup === 'help') { |
43 | 47 | handlerHelp(cb) |
44 | 48 | } |
lib/default-command.js
... | ... | @@ -43,6 +43,25 @@ module.exports = { |
43 | 43 | "dllist", |
44 | 44 | "ldl" |
45 | 45 | ], |
46 | + adddownline: [ | |
47 | + "adddownline", | |
48 | + "createdownlne", | |
49 | + "registerdownline", | |
50 | + "regdownline", | |
51 | + "adddl", | |
52 | + "createdl", | |
53 | + "registerdl", | |
54 | + "regdl", | |
55 | + "tambahdownline", | |
56 | + "tambahdl", | |
57 | + "buatdownline", | |
58 | + "buatdl", | |
59 | + "tambahmitra", | |
60 | + "addmitra", | |
61 | + "createmitra", | |
62 | + "registermitra", | |
63 | + "regmitra" | |
64 | + ], | |
46 | 65 | downlineinfo: [ |
47 | 66 | "downline", |
48 | 67 | "dl", |