Commit 8a8888ce32cee6f1e79fbf5262da4f2d35b771fc
1 parent
c5ce14d558
Exists in
master
USSD code tanpa trim
Showing 2 changed files with 7 additions and 6 deletions Side-by-side Diff
lib/http-command-server/router-ussd.js
... | ... | @@ -9,7 +9,7 @@ module.exports = router; |
9 | 9 | |
10 | 10 | |
11 | 11 | async function handlerIndex(req, res) { |
12 | - if (!req.query || !req.query.code || typeof req.query.code !== 'string' || !req.query.code.trim()) { | |
12 | + if (!req.query || !req.query.code || typeof req.query.code !== 'string') { | |
13 | 13 | res.json({ |
14 | 14 | status: 'NOT-OK', |
15 | 15 | error: 'INVALID-PARAMETER', |
... | ... | @@ -17,12 +17,13 @@ async function handlerIndex(req, res) { |
17 | 17 | }); |
18 | 18 | } |
19 | 19 | |
20 | - const reply = await modem.executeUSSD(req.query.code.trim()); | |
20 | + const reply = await modem.executeUSSD(req.query.code); | |
21 | 21 | res.json({ |
22 | 22 | status: 'OK', |
23 | 23 | error: false, |
24 | - message: 'USSD executed', | |
24 | + code: req.query.code, | |
25 | 25 | result: reply, |
26 | + message: 'USSD executed', | |
26 | 27 | }); |
27 | 28 | } |
28 | 29 |
lib/modem.js
... | ... | @@ -309,9 +309,9 @@ async function sendSMS(destination, msg) { |
309 | 309 | /** |
310 | 310 | * Ekseksusi kode USSD. |
311 | 311 | * |
312 | - * @param {string} cmd - Kode USSD | |
312 | + * @param {string} code - Kode USSD | |
313 | 313 | */ |
314 | -function executeUSSD(cmd) { | |
314 | +function executeUSSD(code) { | |
315 | 315 | return new Promise(async (resolve) => { |
316 | 316 | const parser = new ParserRegex({ regex: REGEX_WAIT_FOR_OK_OR_ERROR }); |
317 | 317 | parser.on('data', (data) => { |
... | ... | @@ -324,7 +324,7 @@ function executeUSSD(cmd) { |
324 | 324 | await mutex.setLockWaitForCommand(); |
325 | 325 | |
326 | 326 | await mutex.setLockWaitForSubCommand(); |
327 | - await writeToPort(`AT+CUSD=1,"${cmd.trim()}",15\r`); | |
327 | + await writeToPort(`AT+CUSD=1,"${code.trim()}",15\r`); | |
328 | 328 | |
329 | 329 | await mutex.setLockWaitForSubCommand(); |
330 | 330 | mutex.releaseLockWaitForSubCommand(); |