Commit 40dfc57ccfc2d514a46df6c1cabb4316644f0788
1 parent
7a59681851
Exists in
master
Complain handler
Showing 3 changed files with 43 additions and 0 deletions Side-by-side Diff
lib/command-handler/complain.js
... | ... | @@ -0,0 +1,33 @@ |
1 | +const CORE_ENDPOINT = '/complains/create'; | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +function help(keyword) { | |
7 | + return `Untuk membuat keluhan, ketik perintah dengan format: ${ keyword.toUpperCase() }.<KELUHAN-ANDA>.<PIN>`; | |
8 | +} | |
9 | + | |
10 | +function execute(tokens, params, cb) { | |
11 | + | |
12 | + if (!tokens || tokens.length < 3) { | |
13 | + const responseParams = { | |
14 | + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` | |
15 | + } | |
16 | + | |
17 | + cb(null, null, responseParams); | |
18 | + return; | |
19 | + } | |
20 | + | |
21 | + const coreParams = { | |
22 | + asker_terminal_name: params.from, | |
23 | + asker_terminal_password: tokens[2], | |
24 | + message: tokens[1], | |
25 | + origin: params.origin, | |
26 | + report_ip: params.report_ip, | |
27 | + report_port: params.report_port, | |
28 | + }; | |
29 | + | |
30 | + coreapi(CORE_ENDPOINT, coreParams, 'GET', cb); | |
31 | +} | |
32 | + | |
33 | +module.exports = execute; | |
0 | 34 | \ No newline at end of file |
lib/command-handler/index.js
... | ... | @@ -13,6 +13,7 @@ const handlerBalance = require('./balance'); |
13 | 13 | const handlerBuy = require('./buy'); |
14 | 14 | const handlerChangePin = require('./changepin'); |
15 | 15 | const handlerClaimBonus = require('./claimbonus'); |
16 | +const handlerComplain = require('./complain'); | |
16 | 17 | const handlerDaySummary = require('./daysummary'); |
17 | 18 | const handlerDepositTicket = require('./depositticket'); |
18 | 19 | const handlerDisableDownline = require('./disabledownline'); |
... | ... | @@ -108,6 +109,9 @@ function execute(msg, params, cb) { |
108 | 109 | else if (commandGroup === 'pay') { |
109 | 110 | handlerPay(tokens, params, cb); |
110 | 111 | } |
112 | + else if (commandGroup === 'complain') { | |
113 | + handlerComplain(tokens, params, cb); | |
114 | + } | |
111 | 115 | else if (commandGroup === 'help') { |
112 | 116 | handlerHelp(tokens, params, cb) |
113 | 117 | } |
lib/default-command.js