Compare View
Commits (5)
Changes
Showing 7 changed files Side-by-side Diff
lib/command-handler/adddownline.js
... | ... | @@ -49,6 +49,7 @@ function execute(tokens, params, cb) { |
49 | 49 | coreParams.generate_password = 1; |
50 | 50 | } |
51 | 51 | |
52 | + /* | |
52 | 53 | if (typeof coreParams.new_terminal_name === 'string' && coreParams.new_terminal_name.indexOf('@') < 0) { |
53 | 54 | let suffix = ''; |
54 | 55 | if (common.isPhoneNumber(coreParams.new_terminal_name)) { |
... | ... | @@ -62,6 +63,11 @@ function execute(tokens, params, cb) { |
62 | 63 | coreParams.new_terminal_name += suffix; |
63 | 64 | } |
64 | 65 | } |
66 | + */ | |
67 | + | |
68 | + if (typeof coreParams.new_terminal_name === 'string' && common.isPhoneNumber(coreParams.new_terminal_name) && coreParams.new_terminal_name.indexOf('0') === 0) { | |
69 | + coreParams.new_terminal_name = coreParams.new_terminal_name.replace(/^0/, '62'); | |
70 | + } | |
65 | 71 | |
66 | 72 | coreapi(coreEndpoint, coreParams, 'GET', cb); |
67 | 73 | } |
lib/command-handler/addterminal.js
1 | 1 | "use strict"; |
2 | 2 | |
3 | +const common = require('../common'); | |
3 | 4 | const commandError = require('./error'); |
4 | 5 | const coreapi = require('../coreapi'); |
5 | 6 | |
... | ... | @@ -30,6 +31,10 @@ function execute(tokens, params, cb) { |
30 | 31 | password: tokens.length < 5 ? tokens[2] : tokens[3] |
31 | 32 | }; |
32 | 33 | |
34 | + if (typeof coreParams.terminal_name === 'string' && common.isPhoneNumber(coreParams.terminal_name) && coreParams.indexOf('0') === 0) { | |
35 | + coreParams.terminal_name = coreParams.terminal_name.replace(/^0/, '62'); | |
36 | + } | |
37 | + | |
33 | 38 | coreapi(coreEndpoint, coreParams, 'GET', cb); |
34 | 39 | } |
35 | 40 |
lib/common.js
lib/default-command.js
package-lock.json
package.json
test/common.js
... | ... | @@ -17,17 +17,22 @@ describe('#common', () => { |
17 | 17 | |
18 | 18 | describe('#isPhoneNumber', () => { |
19 | 19 | it('should detect correctly', () => { |
20 | - common.isPhoneNumber('0818').should.be.ok(); | |
21 | - common.isPhoneNumber('62818').should.be.ok(); | |
22 | - common.isPhoneNumber('+62818').should.be.ok(); | |
20 | + common.isPhoneNumber('0818').should.not.be.ok(); | |
21 | + common.isPhoneNumber('62818').should.not.be.ok(); | |
22 | + common.isPhoneNumber('+62818').should.not.be.ok(); | |
23 | + | |
24 | + common.isPhoneNumber('081808180').should.be.ok(); | |
25 | + common.isPhoneNumber('62818818').should.be.ok(); | |
26 | + common.isPhoneNumber('+62818818').should.be.ok(); | |
27 | + | |
23 | 28 | common.isPhoneNumber('ada').should.not.be.ok(); |
24 | 29 | }); |
25 | 30 | }); |
26 | 31 | |
27 | 32 | describe('#indonesiaIntlNumberToZeroPrefix', () => { |
28 | 33 | it('should transform correctly', () => { |
29 | - common.indonesiaIntlNumberToZeroPrefix('+62818').should.equal('0818'); | |
30 | - common.indonesiaIntlNumberToZeroPrefix('0818').should.equal('0818'); | |
34 | + common.indonesiaIntlNumberToZeroPrefix('+6281812341234').should.equal('081812341234', '+6281812341234'); | |
35 | + common.indonesiaIntlNumberToZeroPrefix('081808180').should.equal('081808180', '081808180'); | |
31 | 36 | common.indonesiaIntlNumberToZeroPrefix('ada').should.equal('ada'); |
32 | 37 | }); |
33 | 38 | }) |