Commit f77a8568e30a18e3b94eadac525a8244bb955f47
1 parent
ff7894b62a
Exists in
master
Enable/disable downline
Showing 5 changed files with 77 additions and 3 deletions Inline Diff
lib/command-handler/disabledownline.js
File was created | 1 | "use strict"; | |
2 | |||
3 | const coreEndpoint = '/stores/disable'; | ||
4 | |||
5 | const commandError = require('./error'); | ||
6 | const coreapi = require('../coreapi'); | ||
7 | |||
8 | function help(keyword) { | ||
9 | return `Untuk menonaktifkan 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 | origin: params.origin, | ||
25 | asker_terminal_name: params.from, | ||
26 | store_id: tokens[1].replace(/^#/, ''), | ||
27 | asker_terminal_password: tokens[2] | ||
28 | }; | ||
29 | |||
30 | coreapi(coreEndpoint, coreParams, 'GET', cb); | ||
31 | } | ||
32 | |||
33 | module.exports = execute; |
lib/command-handler/enabledownline.js
File was created | 1 | "use strict"; | |
2 | |||
3 | const coreEndpoint = '/stores/enable'; | ||
4 | |||
5 | const commandError = require('./error'); | ||
6 | const coreapi = require('../coreapi'); | ||
7 | |||
8 | function help(keyword) { | ||
9 | return `Untuk mengaktifkan kembali 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 | origin: params.origin, | ||
25 | asker_terminal_name: params.from, | ||
26 | store_id: tokens[1].replace(/^#/, ''), | ||
27 | asker_terminal_password: tokens[2] | ||
28 | }; | ||
29 | |||
30 | coreapi(coreEndpoint, coreParams, 'GET', cb); | ||
31 | } | ||
32 | |||
33 | module.exports = execute; |
lib/command-handler/index.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const logger = require('komodo-sdk/logger'); | 3 | const logger = require('komodo-sdk/logger'); |
4 | 4 | ||
5 | const commandParser = require('../command-parser'); | 5 | const commandParser = require('../command-parser'); |
6 | 6 | ||
7 | const commandError = require('./error'); | 7 | const commandError = require('./error'); |
8 | 8 | ||
9 | const handlerHelp = require('./help'); | 9 | const handlerHelp = require('./help'); |
10 | const handlerBuy = require('./buy'); | 10 | const handlerBuy = require('./buy'); |
11 | const handlerBalance = require('./balance'); | 11 | const handlerBalance = require('./balance'); |
12 | const handlerPrice = require('./price'); | 12 | const handlerPrice = require('./price'); |
13 | const handlerListDownline = require('./listdownline'); | 13 | const handlerListDownline = require('./listdownline'); |
14 | const handlerDownlineInfo = require('./downlineinfo'); | 14 | const handlerDownlineInfo = require('./downlineinfo'); |
15 | const handlerAddDownline = require('./adddownline'); | 15 | const handlerAddDownline = require('./adddownline'); |
16 | const handlerAddBalance = require('./addbalance'); | 16 | const handlerAddBalance = require('./addbalance'); |
17 | const handlerTransferBalance = require('./transferbalance'); | 17 | const handlerTransferBalance = require('./transferbalance'); |
18 | const handlerListTerminal = require('./listterminal'); | 18 | const handlerListTerminal = require('./listterminal'); |
19 | const handlerAddTerminal = require('./addterminal'); | 19 | const handlerAddTerminal = require('./addterminal'); |
20 | const handlerChangePin = require('./changepin'); | 20 | const handlerChangePin = require('./changepin'); |
21 | const handlerEnableDownline = require('./enabledownline'); | ||
22 | const handlerDisableDownline = require('./disabledownline'); | ||
21 | 23 | ||
22 | function execute(msg, params, cb) { | 24 | function execute(msg, params, cb) { |
23 | 25 | ||
24 | if ( typeof msg !== 'string' || !msg.trim() ) { | 26 | if ( typeof msg !== 'string' || !msg.trim() ) { |
25 | cb(commandError.ERR_EMPTY_MESSAGE); | 27 | cb(commandError.ERR_EMPTY_MESSAGE); |
26 | return; | 28 | return; |
27 | } | 29 | } |
28 | 30 | ||
29 | const tokens = commandParser.splitToken(msg); | 31 | const tokens = commandParser.splitToken(msg); |
30 | const commandGroup = commandParser.extractCommandGroup(tokens); | 32 | const commandGroup = commandParser.extractCommandGroup(tokens); |
31 | logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup}); | 33 | logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup}); |
32 | 34 | ||
33 | if (!commandGroup || commandGroup === 'buy') { | 35 | if (!commandGroup || commandGroup === 'buy') { |
34 | handlerBuy(tokens, params, cb); | 36 | handlerBuy(tokens, params, cb); |
35 | } | 37 | } |
36 | else if (commandGroup === 'balance') { | 38 | else if (commandGroup === 'balance') { |
37 | handlerBalance(tokens, params, cb); | 39 | handlerBalance(tokens, params, cb); |
38 | } | 40 | } |
39 | else if (commandGroup === 'addbalance') { | 41 | else if (commandGroup === 'addbalance') { |
40 | handlerAddBalance(tokens, params, cb); | 42 | handlerAddBalance(tokens, params, cb); |
41 | } | 43 | } |
42 | else if (commandGroup === 'transferbalance') { | 44 | else if (commandGroup === 'transferbalance') { |
43 | handlerTransferBalance(tokens, params, cb); | 45 | handlerTransferBalance(tokens, params, cb); |
44 | } | 46 | } |
45 | else if (commandGroup === 'price') { | 47 | else if (commandGroup === 'price') { |
46 | handlerPrice(tokens, params, cb); | 48 | handlerPrice(tokens, params, cb); |
47 | } | 49 | } |
48 | else if (commandGroup === 'listdownline') { | 50 | else if (commandGroup === 'listdownline') { |
49 | handlerListDownline(tokens, params, cb); | 51 | handlerListDownline(tokens, params, cb); |
50 | } | 52 | } |
51 | else if (commandGroup === 'downlineinfo') { | 53 | else if (commandGroup === 'downlineinfo') { |
52 | handlerDownlineInfo(tokens, params, cb); | 54 | handlerDownlineInfo(tokens, params, cb); |
53 | } | 55 | } |
54 | else if (commandGroup === 'adddownline') { | 56 | else if (commandGroup === 'adddownline') { |
55 | handlerAddDownline(tokens, params, cb); | 57 | handlerAddDownline(tokens, params, cb); |
56 | } | 58 | } |
57 | else if (commandGroup === 'listterminal') { | 59 | else if (commandGroup === 'listterminal') { |
58 | handlerListTerminal(tokens, params, cb); | 60 | handlerListTerminal(tokens, params, cb); |
59 | } | 61 | } |
60 | else if (commandGroup === 'addterminal') { | 62 | else if (commandGroup === 'addterminal') { |
61 | handlerAddTerminal(tokens, params, cb); | 63 | handlerAddTerminal(tokens, params, cb); |
62 | } | 64 | } |
63 | else if (commandGroup === 'changepin') { | 65 | else if (commandGroup === 'changepin') { |
64 | handlerChangePin(tokens, params, cb); | 66 | handlerChangePin(tokens, params, cb); |
65 | } | 67 | } |
68 | else if (commandGroup === 'enabledownline') { | ||
69 | handlerEnableDownline(tokens, params, cb); | ||
70 | } | ||
71 | else if (commandGroup === 'disabledownline') { | ||
72 | handlerDisableDownline(tokens, params, cb); | ||
73 | } | ||
66 | else if (commandGroup === 'help') { | 74 | else if (commandGroup === 'help') { |
67 | handlerHelp(cb) | 75 | handlerHelp(cb) |
68 | } | 76 | } |
69 | else { | 77 | else { |
70 | cb(commandError.ERR_NOT_IMPLEMENTED); | 78 | cb(commandError.ERR_NOT_IMPLEMENTED); |
71 | } | 79 | } |
72 | } | 80 | } |
73 | 81 | ||
74 | module.exports = execute; | 82 | module.exports = execute; |
lib/coreapi/core-version.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const MINIMUM_VERSION = 'v1.33.1-29'; | 3 | const MINIMUM_VERSION = 'v1.33.1-30'; |
4 | 4 | ||
5 | const util = require('util'); | 5 | const util = require('util'); |
6 | const naturalCompare = require('natural-compare-lite'); | 6 | const naturalCompare = require('natural-compare-lite'); |
7 | 7 | ||
8 | const logger = require('komodo-sdk/logger'); | 8 | const logger = require('komodo-sdk/logger'); |
9 | const matrix = require('komodo-sdk/matrix'); | 9 | const matrix = require('komodo-sdk/matrix'); |
10 | 10 | ||
11 | const coreMatrixRequest = util.promisify(require('./matrix')); | 11 | const coreMatrixRequest = util.promisify(require('./matrix')); |
12 | 12 | ||
13 | let _isSufficient = false; | 13 | let _isSufficient = false; |
14 | matrix.core_version_is_sufficient = false; | 14 | matrix.core_version_is_sufficient = false; |
15 | matrix.core_version_requirement = MINIMUM_VERSION; | 15 | matrix.core_version_requirement = MINIMUM_VERSION; |
16 | 16 | ||
17 | function logIfDev(...args) { | 17 | function logIfDev(...args) { |
18 | matrix.NODE_ENV !== 'production' && logger.verbose(...args); | 18 | matrix.NODE_ENV !== 'production' && logger.verbose(...args); |
19 | } | 19 | } |
20 | 20 | ||
21 | async function getCoreVersion() { | 21 | async function getCoreVersion() { |
22 | 22 | ||
23 | logIfDev('CORE-VERSION: checking core version'); | 23 | logIfDev('CORE-VERSION: checking core version'); |
24 | 24 | ||
25 | try { | 25 | try { |
26 | var coreMatrix = await coreMatrixRequest(); | 26 | var coreMatrix = await coreMatrixRequest(); |
27 | } | 27 | } |
28 | catch(e) { | 28 | catch(e) { |
29 | logger.verbose('Error requsting CORE version. ' + e.toString()) | 29 | logger.verbose('Error requsting CORE version. ' + e.toString()) |
30 | } | 30 | } |
31 | 31 | ||
32 | if (!coreMatrix || !coreMatrix.version_active) { | 32 | if (!coreMatrix || !coreMatrix.version_active) { |
33 | setTimeout( | 33 | setTimeout( |
34 | function() { | 34 | function() { |
35 | getCoreVersion(); | 35 | getCoreVersion(); |
36 | }, | 36 | }, |
37 | 5000 | 37 | 5000 |
38 | ) | 38 | ) |
39 | return; | 39 | return; |
40 | } | 40 | } |
41 | 41 | ||
42 | _isSufficient = naturalCompare(MINIMUM_VERSION, coreMatrix.version_active) <= 0; | 42 | _isSufficient = naturalCompare(MINIMUM_VERSION, coreMatrix.version_active) <= 0; |
43 | matrix.core_version_is_sufficient = _isSufficient; | 43 | matrix.core_version_is_sufficient = _isSufficient; |
44 | logger.info('CORE-VERSION', {version_active: coreMatrix.version_active, minimum_version: MINIMUM_VERSION, sufficient: _isSufficient}); | 44 | logger.info('CORE-VERSION', {version_active: coreMatrix.version_active, minimum_version: MINIMUM_VERSION, sufficient: _isSufficient}); |
45 | 45 | ||
46 | if (!_isSufficient) { | 46 | if (!_isSufficient) { |
47 | setTimeout( | 47 | setTimeout( |
48 | function() { | 48 | function() { |
49 | getCoreVersion(); | 49 | getCoreVersion(); |
50 | }, | 50 | }, |
51 | 5000 | 51 | 5000 |
52 | ) | 52 | ) |
53 | } | 53 | } |
54 | } | 54 | } |
55 | getCoreVersion(); | 55 | getCoreVersion(); |
56 | 56 | ||
57 | function isSufficient() { | 57 | function isSufficient() { |
58 | return _isSufficient; | 58 | return _isSufficient; |
59 | } | 59 | } |
60 | 60 | ||
61 | module.exports = isSufficient(); | 61 | module.exports = isSufficient(); |
lib/default-command.js
1 | module.exports = { | 1 | module.exports = { |
2 | help: [ | 2 | help: [ |
3 | "bantu", | 3 | "bantu", |
4 | "bantuan", | 4 | "bantuan", |
5 | "format", | 5 | "format", |
6 | "help", | 6 | "help", |
7 | "tolong", | 7 | "tolong", |
8 | ], | 8 | ], |
9 | buy: [ | 9 | buy: [ |
10 | "beli", | 10 | "beli", |
11 | "buy", | 11 | "buy", |
12 | "i", | 12 | "i", |
13 | "isi", | 13 | "isi", |
14 | ], | 14 | ], |
15 | _statuscheck: [ | 15 | _statuscheck: [ |
16 | "cekstatus", | 16 | "cekstatus", |
17 | "checkstatus", | 17 | "checkstatus", |
18 | "status", | 18 | "status", |
19 | ], | 19 | ], |
20 | balance: [ | 20 | balance: [ |
21 | "bal", | 21 | "bal", |
22 | "balance", | 22 | "balance", |
23 | "ceksaldo", | 23 | "ceksaldo", |
24 | "checksaldo", | 24 | "checksaldo", |
25 | "s", | 25 | "s", |
26 | "sal", | 26 | "sal", |
27 | "saldo", | 27 | "saldo", |
28 | ], | 28 | ], |
29 | transferbalance: [ | 29 | transferbalance: [ |
30 | "transfer", | 30 | "transfer", |
31 | "trf", | 31 | "trf", |
32 | ], | 32 | ], |
33 | addbalance: [ | 33 | addbalance: [ |
34 | "addbalance", | 34 | "addbalance", |
35 | "addbal", | 35 | "addbal", |
36 | "tambahsaldo", | 36 | "tambahsaldo", |
37 | ], | 37 | ], |
38 | listdownline: [ | 38 | listdownline: [ |
39 | "dllist", | 39 | "dllist", |
40 | "downlinelist", | 40 | "downlinelist", |
41 | "ldl", | 41 | "ldl", |
42 | "listdl", | 42 | "listdl", |
43 | "listdownline", | 43 | "listdownline", |
44 | "listmitra", | 44 | "listmitra", |
45 | "lsdl", | 45 | "lsdl", |
46 | "lsdownline", | 46 | "lsdownline", |
47 | "lsmitra", | 47 | "lsmitra", |
48 | ], | 48 | ], |
49 | adddownline: [ | 49 | adddownline: [ |
50 | "adddl", | 50 | "adddl", |
51 | "adddownline", | 51 | "adddownline", |
52 | "addmitra", | 52 | "addmitra", |
53 | "buatdl", | 53 | "buatdl", |
54 | "buatdownline", | 54 | "buatdownline", |
55 | "createdl", | 55 | "createdl", |
56 | "createdownlne", | 56 | "createdownlne", |
57 | "createmitra", | 57 | "createmitra", |
58 | "regdl", | 58 | "regdl", |
59 | "regdownline", | 59 | "regdownline", |
60 | "registerdl", | 60 | "registerdl", |
61 | "registerdownline", | 61 | "registerdownline", |
62 | "registermitra", | 62 | "registermitra", |
63 | "regmitra", | 63 | "regmitra", |
64 | "tambahdl", | 64 | "tambahdl", |
65 | "tambahdownline", | 65 | "tambahdownline", |
66 | "tambahmitra", | 66 | "tambahmitra", |
67 | ], | 67 | ], |
68 | downlineinfo: [ | 68 | downlineinfo: [ |
69 | "dl", | 69 | "dl", |
70 | "downline", | 70 | "downline", |
71 | "mitra", | 71 | "mitra", |
72 | "saldodownline", | 72 | "saldodownline", |
73 | "saldomitra", | 73 | "saldomitra", |
74 | "sd", | 74 | "sd", |
75 | "sdl", | 75 | "sdl", |
76 | ], | 76 | ], |
77 | _disabledownline: [ | 77 | disabledownline: [ |
78 | "disabledl", | 78 | "disabledl", |
79 | "disabledownline", | 79 | "disabledownline", |
80 | "disablemitra", | 80 | "disablemitra", |
81 | "nonaktifdl", | 81 | "nonaktifdl", |
82 | "nonaktifdownline", | 82 | "nonaktifdownline", |
83 | "nonaktifkandl", | 83 | "nonaktifkandl", |
84 | "nonaktifkandownline", | 84 | "nonaktifkandownline", |
85 | "nonaktifkanmitra", | 85 | "nonaktifkanmitra", |
86 | "nonaktifmitra", | 86 | "nonaktifmitra", |
87 | ], | 87 | ], |
88 | _enabledownline: [ | 88 | enabledownline: [ |
89 | "aktifkandl", | 89 | "aktifkandl", |
90 | "aktifkandownline", | 90 | "aktifkandownline", |
91 | "aktifkanmitra", | 91 | "aktifkanmitra", |
92 | "aktivasidl", | 92 | "aktivasidl", |
93 | "aktivasidownline", | 93 | "aktivasidownline", |
94 | "aktivasimitra", | 94 | "aktivasimitra", |
95 | "enabledl", | 95 | "enabledl", |
96 | "enabledownline", | 96 | "enabledownline", |
97 | "enablemitra", | 97 | "enablemitra", |
98 | ], | 98 | ], |
99 | _daysummary: [ | 99 | _daysummary: [ |
100 | "lap", | 100 | "lap", |
101 | "laporan", | 101 | "laporan", |
102 | "rekap", | 102 | "rekap", |
103 | ], | 103 | ], |
104 | price: [ | 104 | price: [ |
105 | "cekharga", | 105 | "cekharga", |
106 | "ch", | 106 | "ch", |
107 | "checkharga", | 107 | "checkharga", |
108 | "h", | 108 | "h", |
109 | "harga", | 109 | "harga", |
110 | "hargaproduct", | 110 | "hargaproduct", |
111 | "hargaproduk", | 111 | "hargaproduk", |
112 | "price", | 112 | "price", |
113 | ], | 113 | ], |
114 | changepin: [ | 114 | changepin: [ |
115 | "changepin", | 115 | "changepin", |
116 | "gantipin", | 116 | "gantipin", |
117 | "pin", | 117 | "pin", |
118 | "setpin", | 118 | "setpin", |
119 | "ubahpin", | 119 | "ubahpin", |
120 | ], | 120 | ], |
121 | _depositticket: [ | 121 | _depositticket: [ |
122 | 'depo', | 122 | 'depo', |
123 | 'depositticket', | 123 | 'depositticket', |
124 | 'depoticket', | 124 | 'depoticket', |
125 | 'tiket', | 125 | 'tiket', |
126 | 'tiketdeposit', | 126 | 'tiketdeposit', |
127 | ], | 127 | ], |
128 | listterminal: [ | 128 | listterminal: [ |
129 | 'listmsisdn', | 129 | 'listmsisdn', |
130 | 'listterminal', | 130 | 'listterminal', |
131 | 'lsmsisdn', | 131 | 'lsmsisdn', |
132 | 'lsterminal', | 132 | 'lsterminal', |
133 | 'msisdn', | 133 | 'msisdn', |
134 | 'msisdnlist', | 134 | 'msisdnlist', |
135 | 'msisdnls', | 135 | 'msisdnls', |
136 | 'terminal', | 136 | 'terminal', |
137 | 'terminallist', | 137 | 'terminallist', |
138 | 'terminalls', | 138 | 'terminalls', |
139 | 'terminalterdaftar', | 139 | 'terminalterdaftar', |
140 | ], | 140 | ], |
141 | addterminal: [ | 141 | addterminal: [ |
142 | 'addmsisdn', | 142 | 'addmsisdn', |
143 | 'addterminal', | 143 | 'addterminal', |
144 | 'createmsisdn', | 144 | 'createmsisdn', |
145 | 'createterminal', | 145 | 'createterminal', |
146 | 'msisdnadd', | 146 | 'msisdnadd', |
147 | 'newmsisdn', | 147 | 'newmsisdn', |
148 | 'newterminal', | 148 | 'newterminal', |
149 | 'registerterminal', | 149 | 'registerterminal', |
150 | 'regmsisdn', | 150 | 'regmsisdn', |
151 | 'regterminal', | 151 | 'regterminal', |
152 | 'tambahmsisdn', | 152 | 'tambahmsisdn', |
153 | 'tambahterminal', | 153 | 'tambahterminal', |
154 | 'terminaladd', | 154 | 'terminaladd', |
155 | ] | 155 | ] |
156 | } | 156 | } |
157 | 157 |