Commit 90fbdbf1de0776b8f2535e37ef4cc410b68c306d

Authored by Adhidarma Hadiwinoto
1 parent e8bf179ec4
Exists in master

Handler list downline

Showing 2 changed files with 36 additions and 1 deletions Inline Diff

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 handlerBuy = require('./buy'); 10 const handlerBuy = require('./buy');
10 const handlerBalance = require('./balance'); 11 const handlerBalance = require('./balance');
11 const handlerPrice = require('./price'); 12 const handlerPrice = require('./price');
12 const handlerHelp = require('./help'); 13 const handlerListDownline = require('./listdownline');
13 14
14 function execute(msg, params, cb) { 15 function execute(msg, params, cb) {
15 16
16 if ( typeof msg !== 'string' || !msg.trim() ) { 17 if ( typeof msg !== 'string' || !msg.trim() ) {
17 cb(commandError.ERR_EMPTY_MESSAGE); 18 cb(commandError.ERR_EMPTY_MESSAGE);
18 return; 19 return;
19 } 20 }
20 21
21 const tokens = commandParser.splitToken(msg); 22 const tokens = commandParser.splitToken(msg);
22 const commandGroup = commandParser.extractCommandGroup(tokens); 23 const commandGroup = commandParser.extractCommandGroup(tokens);
23 logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup}); 24 logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup});
24 25
25 if (!commandGroup || commandGroup === 'buy') { 26 if (!commandGroup || commandGroup === 'buy') {
26 handlerBuy(tokens, params, cb); 27 handlerBuy(tokens, params, cb);
27 } 28 }
28 else if (commandGroup === 'balance') { 29 else if (commandGroup === 'balance') {
29 handlerBalance(tokens, params, cb); 30 handlerBalance(tokens, params, cb);
30 } 31 }
31 else if (commandGroup === 'price') { 32 else if (commandGroup === 'price') {
32 handlerPrice(tokens, params, cb); 33 handlerPrice(tokens, params, cb);
33 } 34 }
35 else if (commandGroup === 'listdownline') {
36 handlerListDownline(tokens, params, cb);
37 }
34 else if (commandGroup === 'help') { 38 else if (commandGroup === 'help') {
35 handlerHelp(cb) 39 handlerHelp(cb)
36 } 40 }
37 else { 41 else {
38 cb(commandError.ERR_NOT_IMPLEMENTED); 42 cb(commandError.ERR_NOT_IMPLEMENTED);
39 } 43 }
40 } 44 }
41 45
42 module.exports = execute; 46 module.exports = execute;
lib/command-handler/listdownline.js
File was created 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;