Commit b1987100c4aeea4768985d86c544f040c198784b

Authored by Adhidarma Hadiwinoto
1 parent e04a9e4aa3
Exists in master

Add direct response and xid on report

Showing 1 changed file with 23 additions and 6 deletions Inline Diff

1 const moment = require('moment'); 1 const moment = require('moment');
2 2
3 const logger = require('tektrans-logger'); 3 const logger = require('tektrans-logger');
4 const config = require('komodo-sdk/config'); 4 const config = require('komodo-sdk/config');
5 const pull = require('komodo-sdk/gateway/pull'); 5 const pull = require('komodo-sdk/gateway/pull');
6 6
7 function buy(task, xid) { 7 function buy(task, xid) {
8 logger.verbose('Got task from CORE', { xid, task }); 8 logger.verbose('Got task from CORE', { xid, task });
9 const [remoteProduct, amount] = task.remote_product.split(/ *, */); 9 const [remoteProduct, amount] = task.remote_product.split(/ *, */);
10 pull.report({
11 trx_id: task.trx_id,
12 rc: '68',
13 message: {
14 xid,
15 msg: 'Waiting for result',
16 },
17 }, xid);
10 18
11 setTimeout( 19 setTimeout(
12 () => { 20 () => {
13 const destination = task.destination.toString(); 21 const destination = task.destination.toString();
14 22
15 if ((destination % 10) === 0) { 23 if ((destination % 10) === 0) {
16 pull.report({ 24 pull.report({
17 trx_id: task.trx_id, 25 trx_id: task.trx_id,
18 rc: '68', 26 rc: '68',
19 message: `PENDING karena nomor tujuan ${task.destination} diakhiri 0`,
20 balance: config.supplier_ending_balance, 27 balance: config.supplier_ending_balance,
21 }); 28 message: {
29 xid,
30 msg: `PENDING karena nomor tujuan ${task.destination} diakhiri 0`,
31 },
32 }, xid);
22 } else if (destination % 2) { 33 } else if (destination % 2) {
23 pull.report({ 34 pull.report({
24 trx_id: task.trx_id, 35 trx_id: task.trx_id,
25 rc: '14', 36 rc: '14',
26 message: `GAGAL karena nomor tujuan ${task.destination} adalah nomor ganjil`,
27 balance: config.supplier_ending_balance, 37 balance: config.supplier_ending_balance,
28 }); 38 message: {
39 xid,
40 msg: `GAGAL karena nomor tujuan ${task.destination} adalah nomor ganjil`,
41 },
42 }, xid);
29 } else { 43 } else {
30 pull.report({ 44 pull.report({
31 trx_id: task.trx_id, 45 trx_id: task.trx_id,
32 rc: '00', 46 rc: '00',
33 sn: moment().format('YYYYMMDDHHmmssSSS'), 47 sn: moment().format('YYYYMMDDHHmmssSSS'),
34 amount, 48 amount,
35 remote_product: remoteProduct, 49 remote_product: remoteProduct,
36 message: `BERHASIL karena nomor tujuan ${task.destination} adalah nomor genap`,
37 balance: config.supplier_ending_balance, 50 balance: config.supplier_ending_balance,
38 }); 51 message: {
52 xid,
53 msg: `BERHASIL karena nomor tujuan ${task.destination} adalah nomor genap`,
54 },
55 }, xid);
39 } 56 }
40 }, 57 },
41 (config.max_result_timeout_ms || 2000) * Math.random(), 58 (config.max_result_timeout_ms || 2000) * Math.random(),
42 ); 59 );
43 } 60 }