Commit 7e137262cf32657d655a66359a768955f3fb1eae
1 parent
cb9312c328
Exists in
master
Perbaikan pemanggilan USSD
Showing 1 changed file with 2 additions and 2 deletions Inline Diff
lib/http-command-server/router-ussd.js
1 | 'use strict'; | 1 | 'use strict'; |
2 | 2 | ||
3 | const express = require('express'); | 3 | const express = require('express'); |
4 | 4 | ||
5 | const modem = require('../modem'); | 5 | const modem = require('../modem'); |
6 | 6 | ||
7 | const router = express.Router(); | 7 | const router = express.Router(); |
8 | module.exports = router; | 8 | module.exports = router; |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Eksekusi kode USSD | 11 | * Eksekusi kode USSD |
12 | * @param {object} req - Objek request Express | 12 | * @param {object} req - Objek request Express |
13 | * | 13 | * |
14 | * Pilihan req.query.include_cusd2: | 14 | * Pilihan req.query.include_cusd2: |
15 | * -1: sebelum | 15 | * -1: sebelum |
16 | * 0: tidak (default) | 16 | * 0: tidak (default) |
17 | * 1: sesudah | 17 | * 1: sesudah |
18 | * 2: sebelum dan sesudah | 18 | * 2: sebelum dan sesudah |
19 | * | 19 | * |
20 | * @param {object} req.query - Objek query string request Express | 20 | * @param {object} req.query - Objek query string request Express |
21 | * @param {string} req.query.code - Kode USSD yang ingin dieksekusi | 21 | * @param {string} req.query.code - Kode USSD yang ingin dieksekusi |
22 | * @param {number} [req.query.include_cusd2=0] - Apakah ingin mengeksekusi CUSD=2 secara otomatis | 22 | * @param {number} [req.query.include_cusd2=0] - Apakah ingin mengeksekusi CUSD=2 secara otomatis |
23 | * @param {object} res - Objek respon Express | 23 | * @param {object} res - Objek respon Express |
24 | */ | 24 | */ |
25 | async function handlerIndex(req, res) { | 25 | async function handlerIndex(req, res) { |
26 | if (!req.query || !req.query.code || typeof req.query.code !== 'string') { | 26 | if (!req.query || !req.query.code || typeof req.query.code !== 'string') { |
27 | res.json({ | 27 | res.json({ |
28 | status: 'NOT-OK', | 28 | status: 'NOT-OK', |
29 | error: 'INVALID-PARAMETER', | 29 | error: 'INVALID-PARAMETER', |
30 | message: 'Undefined parameter: code', | 30 | message: 'Undefined parameter: code', |
31 | }); | 31 | }); |
32 | 32 | ||
33 | return; | 33 | return; |
34 | } | 34 | } |
35 | 35 | ||
36 | const reply = await modem.executeUSSD(req.query.code, req.query.include_cusd2); | 36 | const reply = await modem.executeUSSD(req.query.code, Number(req.query.include_cusd2)); |
37 | res.json({ | 37 | res.json({ |
38 | status: 'OK', | 38 | status: 'OK', |
39 | error: false, | 39 | error: false, |
40 | code: req.query.code, | 40 | code: req.query.code, |
41 | include_cusd2: req.query.include_cusd2, | 41 | include_cusd2: Number(req.query.include_cusd2) || 0, |
42 | message: reply, | 42 | message: reply, |
43 | }); | 43 | }); |
44 | } | 44 | } |
45 | 45 | ||
46 | router.get('/', handlerIndex); | 46 | router.get('/', handlerIndex); |
47 | 47 |