enabledownline.js 843 Bytes
"use strict";

const coreEndpoint = '/stores/enable';

const commandError = require('./error');
const coreapi = require('../coreapi');

function help(keyword) {
    return `Untuk mengaktifkan kembali 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 = {
        origin: params.origin,
        asker_terminal_name: params.from,
        store_id: tokens[1].replace(/^#/, ''),
        asker_terminal_password: tokens[2]
    };

    coreapi(coreEndpoint, coreParams, 'GET', cb);
}

module.exports = execute;