Blame view

lib/http-command-server/router-ussd.js 1.3 KB
ab4c19eca   Adhidarma Hadiwinoto   router-ussd using...
1
2
3
4
  /**
   * Router USSD
   * @module
   */
c5ce14d55   Adhidarma Hadiwinoto   Uji coba ussd
5
6
  
  const express = require('express');
ab4c19eca   Adhidarma Hadiwinoto   router-ussd using...
7
8
  // const modem = require('../modem');
  const modem = require('../modem-commands');
c5ce14d55   Adhidarma Hadiwinoto   Uji coba ussd
9
10
11
  
  const router = express.Router();
  module.exports = router;
af2522550   Adhidarma Hadiwinoto   JSDOC router-ussd
12
  /**
ab4c19eca   Adhidarma Hadiwinoto   router-ussd using...
13
   * Handler untuk interface eksekusi kode USSD
17ea7e3e9   Adhidarma Hadiwinoto   JSDOC
14
   *
ab4c19eca   Adhidarma Hadiwinoto   router-ussd using...
15
   * @param  {object} req - Objek request Express
af2522550   Adhidarma Hadiwinoto   JSDOC router-ussd
16
17
   * @param  {object} req.query - Objek query string request Express
   * @param  {string} req.query.code - Kode USSD yang ingin dieksekusi
ab4c19eca   Adhidarma Hadiwinoto   router-ussd using...
18
19
20
21
22
   * @param  {number|string} [req.query.include_cusd2=0] - Apakah ingin mengeksekusi CUSD=2.
   * <br>-1: sebelum
   * <br>0: tidak (default)
   * <br>1: sesudah
   * <br>2: sebelum dan sesudah
af2522550   Adhidarma Hadiwinoto   JSDOC router-ussd
23
   * @param  {object} res - Objek respon Express
ab4c19eca   Adhidarma Hadiwinoto   router-ussd using...
24
   * @see module:modem-commands.executeUSSD
af2522550   Adhidarma Hadiwinoto   JSDOC router-ussd
25
   */
c5ce14d55   Adhidarma Hadiwinoto   Uji coba ussd
26
  async function handlerIndex(req, res) {
8a8888ce3   Adhidarma Hadiwinoto   USSD code tanpa trim
27
      if (!req.query || !req.query.code || typeof req.query.code !== 'string') {
c5ce14d55   Adhidarma Hadiwinoto   Uji coba ussd
28
29
30
31
32
          res.json({
              status: 'NOT-OK',
              error: 'INVALID-PARAMETER',
              message: 'Undefined parameter: code',
          });
b21c4fec1   Adhidarma Hadiwinoto   USSD: Return on e...
33
34
  
          return;
c5ce14d55   Adhidarma Hadiwinoto   Uji coba ussd
35
      }
7e137262c   Adhidarma Hadiwinoto   Perbaikan pemangg...
36
      const reply = await modem.executeUSSD(req.query.code, Number(req.query.include_cusd2));
c5ce14d55   Adhidarma Hadiwinoto   Uji coba ussd
37
38
39
      res.json({
          status: 'OK',
          error: false,
8a8888ce3   Adhidarma Hadiwinoto   USSD code tanpa trim
40
          code: req.query.code,
7e137262c   Adhidarma Hadiwinoto   Perbaikan pemangg...
41
          include_cusd2: Number(req.query.include_cusd2) || 0,
af2522550   Adhidarma Hadiwinoto   JSDOC router-ussd
42
          message: reply,
c5ce14d55   Adhidarma Hadiwinoto   Uji coba ussd
43
44
45
46
      });
  }
  
  router.get('/', handlerIndex);