listtrx.js
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const coreEndpoint = '/histories/trx';
const config = require('komodo-sdk/config');
const commandError = require('./error');
const coreapi = require('../coreapi');
function help(keyword, commandGroup) {
return `Untuk melihat list transaksi${
commandGroup === 'listtrxall'
? ' termasuk downline'
: ''
}, 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.`;
}
module.exports = (tokens, params, cb) => {
if (params.commandGroup === 'listtrxall') {
const blacklisted = ((config.blacklist_help_for_origins || []).indexOf(params.origin || '') >= 0)
|| ((config.blacklist_help_for_origin_transports || []).indexOf(params.origin_transport || '') >= 0);
if (blacklisted) {
const body = `Perintah "${tokens[0]}" tdk tersedia pd jalur SMS dan sejenis.`;
const responseParams = { body };
cb(null, null, responseParams);
return;
}
}
if (!tokens || tokens.length < 2) {
const responseParams = {
body: `${commandError.ERR_INVALID_FORMAT}. ${help(tokens[0], params.commandGroup)}`,
};
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],
date: tokens.length < 3 ? null : tokens[1],
include_downlines: params.commandGroup === 'listtrxall',
dont_include_failed: true,
limit: 100,
offset: 0,
order: 'DESC',
};
coreapi(coreEndpoint, coreParams, 'GET', cb);
};