complain.js 873 Bytes
const CORE_ENDPOINT = '/complains/create';

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

function help(keyword) {
    return `Untuk membuat keluhan, ketik perintah dengan format: ${ keyword.toUpperCase() }.<KELUHAN-ANDA>.<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,
        asker_terminal_password: tokens[2],
        message: tokens[1],
        origin: params.origin,
        report_ip: params.report_ip,
        report_port: params.report_port,
    };

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

module.exports = execute;