listdeposit.js 1.13 KB
const config = require('komodo-sdk/config');

const coreEndpoint = '/histories/mutations/deposit-and-transfer';

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

function help(keyword) {
    return `
Format perintah utk list deposit dan transfer:

${keyword.toUpperCase()}.<PIN> atau ${keyword.toUpperCase()}.<TANGGAL>.<PIN>.

<TANGGAL> dlm format YYYY-MM-DD, contoh 2018-12-31 untuk tanggal 31 Desember 2018.
    `.trim();
}

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],
        ascending: (config.ascending_mutation || config.ascending_deposit) ? 'true' : 'false',
    };

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

module.exports = execute;