Commit 5c4cf023bc4bfad2cc0101c57492dd185399c915

Authored by Adhidarma Hadiwinoto
1 parent 8d90a3941f
Exists in master

Fix eslint on buy.js

Showing 1 changed file with 8 additions and 9 deletions Inline Diff

lib/command-handler/buy.js
1 // const moment = require('moment'); 1 // const moment = require('moment');
2 2
3 const config = require('komodo-sdk/config'); 3 const config = require('komodo-sdk/config');
4 const logger = require('tektrans-logger'); 4 const logger = require('tektrans-logger');
5 5
6 const commands = require('../command-group'); 6 const commands = require('../command-group');
7 const commandError = require('./error'); 7 const commandError = require('./error');
8 const destinationCorrector = require('../destination-corrector'); 8 const destinationCorrector = require('../destination-corrector');
9 const coreapi = require('../coreapi'); 9 const coreapi = require('../coreapi');
10 10
11 const coreEndpointAuto = '/buy-or-pay'; 11 const coreEndpointAuto = '/buy-or-pay';
12 const coreEndpointBuy = '/prepaid/buy'; 12 const coreEndpointBuy = '/prepaid/buy';
13 13
14 /* 14 /*
15 function generateRequestId(product, destination) { 15 function generateRequestId(product, destination) {
16 return `AUTO_${ product.toUpperCase() }_${ destination }_${ moment().format('YYYYMMDD') }`; 16 return `AUTO_${ product.toUpperCase() }_${ destination }_${ moment().format('YYYYMMDD') }`;
17 } 17 }
18 */ 18 */
19 19
20 function help() { 20 function help() {
21 return `Untuk pembelian, ketik perintah dengan format: <KODEPRODUK>.<NOMORTUJUAN>.<PIN>`; 21 return 'Untuk pembelian, ketik perintah dengan format: <KODEPRODUK>.<NOMORTUJUAN>.<PIN>';
22 } 22 }
23 23
24 function execute(tokens, params, cb) { 24 function execute(tokens, params, cb) {
25 if (!tokens || tokens.length < 3) { 25 if (!tokens || tokens.length < 3) {
26 const responseParams = { 26 const responseParams = {
27 body: `${ commandError.ERR_INVALID_FORMAT }. ${ help() }` 27 body: `${commandError.ERR_INVALID_FORMAT}. ${help()}`,
28 } 28 };
29 29
30 cb(null, null, responseParams); 30 cb(null, null, responseParams);
31 return; 31 return;
32 } 32 }
33 33
34 if (commands[ tokens[0] ] !== 'buy') { 34 if (commands[tokens[0]] !== 'buy') {
35 tokens.unshift('buy'); 35 tokens.unshift('buy');
36 logger.verbose('Rearrange tokens', {tokens: tokens}); 36 logger.verbose('Rearrange tokens', { tokens });
37 } 37 }
38 38
39 const destination = destinationCorrector((tokens[2] || '').trim()); 39 const destination = destinationCorrector((tokens[2] || '').trim());
40 40
41 const coreParams = { 41 const coreParams = {
42 origin: params.origin, 42 origin: params.origin,
43 report_ip: params.report_ip, 43 report_ip: params.report_ip,
44 report_port: params.report_port, 44 report_port: params.report_port,
45 terminal_name: params.from, 45 terminal_name: params.from,
46 product_name: (tokens[1] || '').trim().toUpperCase(), 46 product_name: (tokens[1] || '').trim().toUpperCase(),
47 destination, 47 destination,
48 password: tokens[3], 48 password: tokens[3],
49 // request_id: `${generateRequestId(tokens[1], destination)}${Number(tokens[4]) ? '_req' + Number(tokens[4]) : ''}`, 49 request_id_suffix: tokens[4] || '',
50 request_id_suffix: tokens[4] || '', 50 postpaid: 0,
51 postpaid: 0
52 }; 51 };
53 52
54 const coreEndpoint = config.buy_only_prepaid ? coreEndpointBuy : coreEndpointAuto; 53 const coreEndpoint = config.buy_only_prepaid ? coreEndpointBuy : coreEndpointAuto;
55 coreapi(coreEndpoint, coreParams, 'GET', cb); 54 coreapi(coreEndpoint, coreParams, 'GET', cb);
56 } 55 }
57 56
58 module.exports = execute;