From 8e3a1cb0d93b5851475ccdeced9d3271e08d5bb2 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <me@adhisimon.org>
Date: Fri, 21 Jun 2019 21:57:33 +0700
Subject: [PATCH] Info downline

---
 lib/command-handler/downlineinfo.js | 33 +++++++++++++++++++++++++++++++++
 lib/command-handler/index.js        |  4 ++++
 lib/default-command.js              |  4 +++-
 3 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 lib/command-handler/downlineinfo.js

diff --git a/lib/command-handler/downlineinfo.js b/lib/command-handler/downlineinfo.js
new file mode 100644
index 0000000..4fb35a2
--- /dev/null
+++ b/lib/command-handler/downlineinfo.js
@@ -0,0 +1,33 @@
+"use strict";
+
+const commandError = require('./error');
+const coreapi = require('../coreapi');
+
+const coreEndpoint = '/stores/view';
+
+function help(keyword) {
+    return `Untuk info sebuah downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN>`;
+}
+
+function execute(tokens, params, cb) {
+    
+    if (!tokens || tokens.length < 3) {
+        const responseParams = {
+            body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`
+        }
+
+        cb(null, null, responseParams);
+        return;
+    }
+
+    const coreParams = {
+        terminal_name: params.from,
+        downline_store_id: tokens[1].replace(/^#/, ''),
+        password: tokens[2],
+        postpaid: 0
+    };
+
+    coreapi(coreEndpoint, coreParams, 'GET', cb);
+}
+
+module.exports = execute;
\ No newline at end of file
diff --git a/lib/command-handler/index.js b/lib/command-handler/index.js
index e095c25..90cc9fa 100644
--- a/lib/command-handler/index.js
+++ b/lib/command-handler/index.js
@@ -11,6 +11,7 @@ const handlerBuy = require('./buy');
 const handlerBalance = require('./balance');
 const handlerPrice = require('./price');
 const handlerListDownline = require('./listdownline');
+const handlerDownlineInfo = require('./downlineinfo');
 
 function execute(msg, params, cb) {
 
@@ -35,6 +36,9 @@ function execute(msg, params, cb) {
     else if (commandGroup === 'listdownline') {
         handlerListDownline(tokens, params, cb);
     }
+    else if (commandGroup === 'downlineinfo') {
+        handlerDownlineInfo(tokens, params, cb);
+    }
     else if (commandGroup === 'help') {
         handlerHelp(cb)
     }
diff --git a/lib/default-command.js b/lib/default-command.js
index 7d3aef9..69ce0f5 100644
--- a/lib/default-command.js
+++ b/lib/default-command.js
@@ -43,9 +43,11 @@ module.exports = {
         "dllist",
         "ldl"
     ],
-    _downlineinfo: [
+    downlineinfo: [
         "downline",
+        "dl",
         "sd",
+        "sdl",
         "saldodownline",
         "mitra",
         "saldomitra"
-- 
1.9.0