price.js 757 Bytes
const CORE_ENDPOINT = '/services/pricelist';

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

function help(keyword) {
    return `Untuk cek harga, ketik perintah dengan format: ${ keyword.toUpperCase() }.<KODEPRODUK>.<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,
        keyword: tokens[1],
        password: tokens[2],
        postpaid: 0
    };

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

module.exports = execute;