From b39444c35e25a85a04fadf73046a03d6a32e4c51 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <me@adhisimon.org>
Date: Tue, 2 Jul 2019 15:28:17 +0700
Subject: [PATCH] Command adddownline

---
 lib/command-handler/adddownline.js | 32 ++++++++++++++++++++++++++++++++
 lib/command-handler/index.js       |  4 ++++
 lib/default-command.js             | 19 +++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 lib/command-handler/adddownline.js

diff --git a/lib/command-handler/adddownline.js b/lib/command-handler/adddownline.js
new file mode 100644
index 0000000..fca2ded
--- /dev/null
+++ b/lib/command-handler/adddownline.js
@@ -0,0 +1,32 @@
+"use strict";
+
+const commandError = require('./error');
+const coreapi = require('../coreapi');
+
+const coreEndpoint = '/stores/create';
+
+function help(keyword) {
+    return `Untuk membuat downline baru, ketik perintah dengan format: ${ keyword.toUpperCase() }.<NAMADOWNLINE>.<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 = {
+        asker_terminal_name: params.from,
+        new_store_name: tokens[1],
+        asker_terminal_password: tokens[2],
+    };
+
+    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 90cc9fa..f4eb73c 100644
--- a/lib/command-handler/index.js
+++ b/lib/command-handler/index.js
@@ -12,6 +12,7 @@ const handlerBalance = require('./balance');
 const handlerPrice = require('./price');
 const handlerListDownline = require('./listdownline');
 const handlerDownlineInfo = require('./downlineinfo');
+const handlerAddDownline = require('./adddownline');
 
 function execute(msg, params, cb) {
 
@@ -39,6 +40,9 @@ function execute(msg, params, cb) {
     else if (commandGroup === 'downlineinfo') {
         handlerDownlineInfo(tokens, params, cb);
     }
+    else if (commandGroup === 'adddownline') {
+        handlerAddDownline(tokens, params, cb);
+    }
     else if (commandGroup === 'help') {
         handlerHelp(cb)
     }
diff --git a/lib/default-command.js b/lib/default-command.js
index 69ce0f5..136452b 100644
--- a/lib/default-command.js
+++ b/lib/default-command.js
@@ -43,6 +43,25 @@ module.exports = {
         "dllist",
         "ldl"
     ],
+    adddownline: [
+        "adddownline",
+        "createdownlne",
+        "registerdownline",
+        "regdownline",
+        "adddl",
+        "createdl",
+        "registerdl",
+        "regdl",
+        "tambahdownline",
+        "tambahdl",
+        "buatdownline",
+        "buatdl",
+        "tambahmitra",
+        "addmitra",
+        "createmitra",
+        "registermitra",
+        "regmitra"
+    ],
     downlineinfo: [
         "downline",
         "dl",
-- 
1.9.0