listterminal.js
1.35 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
55
56
57
58
const CORE_ENDPOINT = '/terminals';
const commandError = require('./error');
const coreapi = require('../coreapi');
function help(keyword) {
return `
Untuk list terminal anda, ketik perintah dengan format:
${ keyword.toUpperCase() }.<PIN>
atau
${ keyword.toUpperCase() }.#<IDDOWNLINE>.<PIN>
atau
${ keyword.toUpperCase() }.<TERMINALDOWNLINE>.<PIN>
`.trim();
}
function execute(tokens, params, cb) {
if (!tokens || tokens.length < 2) {
const responseParams = {
body: `
${ commandError.ERR_INVALID_FORMAT }: ${params.msg}
${ help(tokens[0]) }
`.trim(),
}
cb(null, null, responseParams);
return;
}
const idxDownline = (tokens.length <= 2) ? null : 1;
const idxPin = (tokens.length <= 2) ? 1 : 2;
let downline;
let downlineStoreId;
let downlineTerminalName;
if (idxDownline) {
downline = tokens[idxDownline];
if (downline.indexOf('#') === 0) {
downlineStoreId = downline.replace(/^#/, '');
} else {
downlineTerminalName = downline;
}
}
const coreParams = {
asker_terminal_name: params.from,
asker_terminal_password: tokens[ idxPin ],
store_id: downlineStoreId,
terminal_name: downlineTerminalName,
};
coreapi(CORE_ENDPOINT, coreParams, 'GET', cb);
}
module.exports = execute;