Commit c7ca62ff7b062850d11cc7468b45fe2b9be4903f

Authored by Adhidarma Hadiwinoto
1 parent 4f291e9b4f
Exists in master

Supplier balances

Showing 3 changed files with 45 additions and 0 deletions Side-by-side Diff

lib/command-handler/index.js
... ... @@ -21,6 +21,7 @@ const handlerHelp = require('./help');
21 21 const handlerListDownline = require('./listdownline');
22 22 const handlerListTerminal = require('./listterminal');
23 23 const handlerPrice = require('./price');
  24 +const handlerSupplierBalances = require('./supplierbalances');
24 25 const handlerTransferBalance = require('./transferbalance');
25 26  
26 27 function execute(msg, params, cb) {
... ... @@ -79,6 +80,9 @@ function execute(msg, params, cb) {
79 80 else if (commandGroup === 'disabledownline') {
80 81 handlerDisableDownline(tokens, params, cb);
81 82 }
  83 + else if (commandGroup === 'supplierbalances') {
  84 + handlerSupplierBalances(tokens, params, cb);
  85 + }
82 86 else if (commandGroup === 'help') {
83 87 handlerHelp(cb)
84 88 }
lib/command-handler/supplierbalances.js
... ... @@ -0,0 +1,31 @@
  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;
0 32 \ No newline at end of file
lib/default-command.js
... ... @@ -156,6 +156,16 @@ module.exports = {
156 156 'tambahterminal',
157 157 'terminaladd',
158 158 ],
  159 + supplierbalances: [
  160 + 'supplier',
  161 + 'supplierbal',
  162 + 'supplierbalance',
  163 + 'supplierbalances',
  164 + 'suppliers',
  165 + 'suppliersbal',
  166 + 'suppliersbalance',
  167 + 'suppliersbalances',
  168 + ],
159 169 _setmarkup: [
160 170 'markup'
161 171 ]