Compare View
Commits (4)
Changes
Showing 7 changed files 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/downlineinfo.js
... | ... | @@ -0,0 +1,33 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/stores/view'; | |
7 | + | |
8 | +function help(keyword) { | |
9 | + return `Untuk info sebuah downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.#<IDDOWNLINE>.<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 | + terminal_name: params.from, | |
25 | + downline_store_id: tokens[1].replace(/^#/, ''), | |
26 | + password: tokens[2], | |
27 | + postpaid: 0 | |
28 | + }; | |
29 | + | |
30 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
31 | +} | |
32 | + | |
33 | +module.exports = execute; | |
0 | 34 | \ No newline at end of file |
lib/command-handler/help.js
... | ... | @@ -2,8 +2,8 @@ |
2 | 2 | |
3 | 3 | const commands = require('../command-group'); |
4 | 4 | const cmds = []; |
5 | -for (let [key] of Object.entries(commands)) { | |
6 | - cmds.push(key.toUpperCase()); | |
5 | +for (let [key, value] of Object.entries(commands)) { | |
6 | + if (value.indexOf('_') !== 0) cmds.push(key.toUpperCase()); | |
7 | 7 | } |
8 | 8 | cmds.sort(); |
9 | 9 | const msg = 'Perintah tersedia: ' + cmds.join(', ') + '.' |
lib/command-handler/index.js
... | ... | @@ -11,6 +11,8 @@ const handlerBuy = require('./buy'); |
11 | 11 | const handlerBalance = require('./balance'); |
12 | 12 | const handlerPrice = require('./price'); |
13 | 13 | const handlerListDownline = require('./listdownline'); |
14 | +const handlerDownlineInfo = require('./downlineinfo'); | |
15 | +const handlerAddDownline = require('./adddownline'); | |
14 | 16 | |
15 | 17 | function execute(msg, params, cb) { |
16 | 18 | |
... | ... | @@ -35,6 +37,12 @@ function execute(msg, params, cb) { |
35 | 37 | else if (commandGroup === 'listdownline') { |
36 | 38 | handlerListDownline(tokens, params, cb); |
37 | 39 | } |
40 | + else if (commandGroup === 'downlineinfo') { | |
41 | + handlerDownlineInfo(tokens, params, cb); | |
42 | + } | |
43 | + else if (commandGroup === 'adddownline') { | |
44 | + handlerAddDownline(tokens, params, cb); | |
45 | + } | |
38 | 46 | else if (commandGroup === 'help') { |
39 | 47 | handlerHelp(cb) |
40 | 48 | } |
lib/default-command.js
... | ... | @@ -43,9 +43,30 @@ module.exports = { |
43 | 43 | "dllist", |
44 | 44 | "ldl" |
45 | 45 | ], |
46 | - _downlineinfo: [ | |
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 | + ], | |
65 | + downlineinfo: [ | |
47 | 66 | "downline", |
67 | + "dl", | |
48 | 68 | "sd", |
69 | + "sdl", | |
49 | 70 | "saldodownline", |
50 | 71 | "mitra", |
51 | 72 | "saldomitra" |
package-lock.json