daysummary.js 1.03 KB
const coreEndpoint = '/stores/summary';

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

function help(keyword) {
    return `Untuk melihat laporan harian, ketik perintah dengan format: ${keyword.toUpperCase()}.<PIN> atau ${keyword.toUpperCase()}.<TANGGAL>.<PIN>. Format tanggal YYYY-MM-DD, contoh 2018-12-31 untuk tanggal 31 Desember 2018.`;
}

function execute(tokens, params, cb) {
    if (!tokens || tokens.length < 2) {
        const responseParams = {
            body: `${commandError.ERR_INVALID_FORMAT}. ${help(tokens[0])}`,
        };

        cb(null, null, responseParams);
        return;
    }

    const idxPin = tokens.length < 3 ? 1 : 2;

    const coreParams = {
        origin: params.origin,
        asker_terminal_name: params.from,
        asker_terminal_password: tokens[idxPin],
        created_date: tokens.length < 3 ? null : tokens[1],
        include_downline: params.commandGroup === 'daysummaryall',
    };

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

module.exports = execute;