Commit c7ca62ff7b062850d11cc7468b45fe2b9be4903f

Authored by Adhidarma Hadiwinoto
1 parent 4f291e9b4f
Exists in master

Supplier balances

Showing 3 changed files with 45 additions and 0 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 handlerAddBalance = require('./addbalance'); 9 const handlerAddBalance = require('./addbalance');
10 const handlerAddDownline = require('./adddownline'); 10 const handlerAddDownline = require('./adddownline');
11 const handlerAddTerminal = require('./addterminal'); 11 const handlerAddTerminal = require('./addterminal');
12 const handlerBalance = require('./balance'); 12 const handlerBalance = require('./balance');
13 const handlerBuy = require('./buy'); 13 const handlerBuy = require('./buy');
14 const handlerChangePin = require('./changepin'); 14 const handlerChangePin = require('./changepin');
15 const handlerDaySummary = require('./daysummary'); 15 const handlerDaySummary = require('./daysummary');
16 const handlerDepositTicket = require('./depositticket'); 16 const handlerDepositTicket = require('./depositticket');
17 const handlerDisableDownline = require('./disabledownline'); 17 const handlerDisableDownline = require('./disabledownline');
18 const handlerDownlineInfo = require('./downlineinfo'); 18 const handlerDownlineInfo = require('./downlineinfo');
19 const handlerEnableDownline = require('./enabledownline'); 19 const handlerEnableDownline = require('./enabledownline');
20 const handlerHelp = require('./help'); 20 const handlerHelp = require('./help');
21 const handlerListDownline = require('./listdownline'); 21 const handlerListDownline = require('./listdownline');
22 const handlerListTerminal = require('./listterminal'); 22 const handlerListTerminal = require('./listterminal');
23 const handlerPrice = require('./price'); 23 const handlerPrice = require('./price');
24 const handlerSupplierBalances = require('./supplierbalances');
24 const handlerTransferBalance = require('./transferbalance'); 25 const handlerTransferBalance = require('./transferbalance');
25 26
26 function execute(msg, params, cb) { 27 function execute(msg, params, cb) {
27 28
28 if ( typeof msg !== 'string' || !msg.trim() ) { 29 if ( typeof msg !== 'string' || !msg.trim() ) {
29 cb(commandError.ERR_EMPTY_MESSAGE); 30 cb(commandError.ERR_EMPTY_MESSAGE);
30 return; 31 return;
31 } 32 }
32 33
33 const tokens = commandParser.splitToken(msg); 34 const tokens = commandParser.splitToken(msg);
34 const commandGroup = commandParser.extractCommandGroup(tokens); 35 const commandGroup = commandParser.extractCommandGroup(tokens);
35 logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup}); 36 logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup});
36 37
37 if (!commandGroup || commandGroup === 'buy') { 38 if (!commandGroup || commandGroup === 'buy') {
38 handlerBuy(tokens, params, cb); 39 handlerBuy(tokens, params, cb);
39 } 40 }
40 else if (commandGroup === 'balance') { 41 else if (commandGroup === 'balance') {
41 handlerBalance(tokens, params, cb); 42 handlerBalance(tokens, params, cb);
42 } 43 }
43 else if (commandGroup === 'addbalance') { 44 else if (commandGroup === 'addbalance') {
44 handlerAddBalance(tokens, params, cb); 45 handlerAddBalance(tokens, params, cb);
45 } 46 }
46 else if (commandGroup === 'transferbalance') { 47 else if (commandGroup === 'transferbalance') {
47 handlerTransferBalance(tokens, params, cb); 48 handlerTransferBalance(tokens, params, cb);
48 } 49 }
49 else if (commandGroup === 'price') { 50 else if (commandGroup === 'price') {
50 handlerPrice(tokens, params, cb); 51 handlerPrice(tokens, params, cb);
51 } 52 }
52 else if (commandGroup === 'listdownline') { 53 else if (commandGroup === 'listdownline') {
53 handlerListDownline(tokens, params, cb); 54 handlerListDownline(tokens, params, cb);
54 } 55 }
55 else if (commandGroup === 'downlineinfo') { 56 else if (commandGroup === 'downlineinfo') {
56 handlerDownlineInfo(tokens, params, cb); 57 handlerDownlineInfo(tokens, params, cb);
57 } 58 }
58 else if (commandGroup === 'adddownline') { 59 else if (commandGroup === 'adddownline') {
59 handlerAddDownline(tokens, params, cb); 60 handlerAddDownline(tokens, params, cb);
60 } 61 }
61 else if (commandGroup === 'listterminal') { 62 else if (commandGroup === 'listterminal') {
62 handlerListTerminal(tokens, params, cb); 63 handlerListTerminal(tokens, params, cb);
63 } 64 }
64 else if (commandGroup === 'addterminal') { 65 else if (commandGroup === 'addterminal') {
65 handlerAddTerminal(tokens, params, cb); 66 handlerAddTerminal(tokens, params, cb);
66 } 67 }
67 else if (commandGroup === 'changepin') { 68 else if (commandGroup === 'changepin') {
68 handlerChangePin(tokens, params, cb); 69 handlerChangePin(tokens, params, cb);
69 } 70 }
70 else if (commandGroup === 'enabledownline') { 71 else if (commandGroup === 'enabledownline') {
71 handlerEnableDownline(tokens, params, cb); 72 handlerEnableDownline(tokens, params, cb);
72 } 73 }
73 else if (commandGroup === 'daysummary') { 74 else if (commandGroup === 'daysummary') {
74 handlerDaySummary(tokens, params, cb); 75 handlerDaySummary(tokens, params, cb);
75 } 76 }
76 else if (commandGroup === 'depositticket') { 77 else if (commandGroup === 'depositticket') {
77 handlerDepositTicket(tokens, params, cb); 78 handlerDepositTicket(tokens, params, cb);
78 } 79 }
79 else if (commandGroup === 'disabledownline') { 80 else if (commandGroup === 'disabledownline') {
80 handlerDisableDownline(tokens, params, cb); 81 handlerDisableDownline(tokens, params, cb);
81 } 82 }
83 else if (commandGroup === 'supplierbalances') {
84 handlerSupplierBalances(tokens, params, cb);
85 }
82 else if (commandGroup === 'help') { 86 else if (commandGroup === 'help') {
83 handlerHelp(cb) 87 handlerHelp(cb)
84 } 88 }
85 else { 89 else {
86 cb(commandError.ERR_NOT_IMPLEMENTED); 90 cb(commandError.ERR_NOT_IMPLEMENTED);
87 } 91 }
88 } 92 }
89 93
90 module.exports = execute; 94 module.exports = execute;
lib/command-handler/supplierbalances.js
File was created 1 "use strict";
2
3 const commandError = require('./error');
4 const coreapi = require('../coreapi');
5
6 const coreEndpoint = '/services/suppliers/balances';
7
8 function help(keyword) {
9 return `Untuk melihat sisa saldo terkini di supplier, 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 asker_terminal_name: params.from,
25 asker_terminal_password: tokens[1],
26 };
27
28 coreapi(coreEndpoint, coreParams, 'GET', cb);
29 }
30
31 module.exports = execute;
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 "dlls", 40 "dlls",
41 "downlinelist", 41 "downlinelist",
42 "downlinels", 42 "downlinels",
43 "ldl", 43 "ldl",
44 "listdl", 44 "listdl",
45 "listdownline", 45 "listdownline",
46 "listmitra", 46 "listmitra",
47 "lsdl", 47 "lsdl",
48 "lsdownline", 48 "lsdownline",
49 "lsmitra", 49 "lsmitra",
50 "mitrals", 50 "mitrals",
51 ], 51 ],
52 adddownline: [ 52 adddownline: [
53 "adddl", 53 "adddl",
54 "adddownline", 54 "adddownline",
55 "addmitra", 55 "addmitra",
56 "buatdl", 56 "buatdl",
57 "buatdownline", 57 "buatdownline",
58 "createdl", 58 "createdl",
59 "createdownlne", 59 "createdownlne",
60 "createmitra", 60 "createmitra",
61 "regdl", 61 "regdl",
62 "regdownline", 62 "regdownline",
63 "registerdl", 63 "registerdl",
64 "registerdownline", 64 "registerdownline",
65 "registermitra", 65 "registermitra",
66 "regmitra", 66 "regmitra",
67 "tambahdl", 67 "tambahdl",
68 "tambahdownline", 68 "tambahdownline",
69 "tambahmitra", 69 "tambahmitra",
70 ], 70 ],
71 downlineinfo: [ 71 downlineinfo: [
72 "dl", 72 "dl",
73 "downline", 73 "downline",
74 "mitra", 74 "mitra",
75 "saldodownline", 75 "saldodownline",
76 "saldomitra", 76 "saldomitra",
77 "sd", 77 "sd",
78 "sdl", 78 "sdl",
79 ], 79 ],
80 disabledownline: [ 80 disabledownline: [
81 "disabledl", 81 "disabledl",
82 "disabledownline", 82 "disabledownline",
83 "disablemitra", 83 "disablemitra",
84 "nonaktifdl", 84 "nonaktifdl",
85 "nonaktifdownline", 85 "nonaktifdownline",
86 "nonaktifkandl", 86 "nonaktifkandl",
87 "nonaktifkandownline", 87 "nonaktifkandownline",
88 "nonaktifkanmitra", 88 "nonaktifkanmitra",
89 "nonaktifmitra", 89 "nonaktifmitra",
90 ], 90 ],
91 enabledownline: [ 91 enabledownline: [
92 "aktifkandl", 92 "aktifkandl",
93 "aktifkandownline", 93 "aktifkandownline",
94 "aktifkanmitra", 94 "aktifkanmitra",
95 "aktivasidl", 95 "aktivasidl",
96 "aktivasidownline", 96 "aktivasidownline",
97 "aktivasimitra", 97 "aktivasimitra",
98 "enabledl", 98 "enabledl",
99 "enabledownline", 99 "enabledownline",
100 "enablemitra", 100 "enablemitra",
101 ], 101 ],
102 daysummary: [ 102 daysummary: [
103 "lap", 103 "lap",
104 "laporan", 104 "laporan",
105 "rekap", 105 "rekap",
106 ], 106 ],
107 price: [ 107 price: [
108 "cekharga", 108 "cekharga",
109 "ch", 109 "ch",
110 "checkharga", 110 "checkharga",
111 "h", 111 "h",
112 "harga", 112 "harga",
113 "hargaproduct", 113 "hargaproduct",
114 "hargaproduk", 114 "hargaproduk",
115 "price", 115 "price",
116 ], 116 ],
117 changepin: [ 117 changepin: [
118 "changepin", 118 "changepin",
119 "gantipin", 119 "gantipin",
120 "pin", 120 "pin",
121 "setpin", 121 "setpin",
122 "ubahpin", 122 "ubahpin",
123 ], 123 ],
124 depositticket: [ 124 depositticket: [
125 'depo', 125 'depo',
126 'depositticket', 126 'depositticket',
127 'depoticket', 127 'depoticket',
128 'tiket', 128 'tiket',
129 'tiketdeposit', 129 'tiketdeposit',
130 ], 130 ],
131 listterminal: [ 131 listterminal: [
132 'listmsisdn', 132 'listmsisdn',
133 'listterminal', 133 'listterminal',
134 'lsmsisdn', 134 'lsmsisdn',
135 'lsterminal', 135 'lsterminal',
136 'msisdn', 136 'msisdn',
137 'msisdnlist', 137 'msisdnlist',
138 'msisdnls', 138 'msisdnls',
139 'terminal', 139 'terminal',
140 'terminallist', 140 'terminallist',
141 'terminalls', 141 'terminalls',
142 'terminalterdaftar', 142 'terminalterdaftar',
143 ], 143 ],
144 addterminal: [ 144 addterminal: [
145 'addmsisdn', 145 'addmsisdn',
146 'addterminal', 146 'addterminal',
147 'createmsisdn', 147 'createmsisdn',
148 'createterminal', 148 'createterminal',
149 'msisdnadd', 149 'msisdnadd',
150 'newmsisdn', 150 'newmsisdn',
151 'newterminal', 151 'newterminal',
152 'registerterminal', 152 'registerterminal',
153 'regmsisdn', 153 'regmsisdn',
154 'regterminal', 154 'regterminal',
155 'tambahmsisdn', 155 'tambahmsisdn',
156 'tambahterminal', 156 'tambahterminal',
157 'terminaladd', 157 'terminaladd',
158 ], 158 ],
159 supplierbalances: [
160 'supplier',
161 'supplierbal',
162 'supplierbalance',
163 'supplierbalances',
164 'suppliers',
165 'suppliersbal',
166 'suppliersbalance',
167 'suppliersbalances',
168 ],
159 _setmarkup: [ 169 _setmarkup: [
160 'markup' 170 'markup'
161 ] 171 ]
162 } 172 }
163 173