adddownline.js 787 Bytes
"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;