Commit 01c2902ced57a13abcf3ba4e182b2be6c97386de

Authored by Adhidarma Hadiwinoto
1 parent 17dc6e81f7
Exists in master

Buy: replace +62 to 0

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

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