'use strict'; const express = require('express'); const modem = require('../modem'); const router = express.Router(); module.exports = router; /** * Eksekusi kode USSD * @param {object} req - Objek request Express * @param {object} req.query - Objek query string request Express * @param {string} req.query.code - Kode USSD yang ingin dieksekusi * @param {number} [req.query.include_cusd2=0] - Apakah ingin mengeksekusi CUSD=2 secara otomatis. 0: tidak (DEFAULT), 1: sesudah eksekusi ussd, -1: sebelum ekseksi ussd. * @param {object} res - Objek respon Express */ async function handlerIndex(req, res) { if (!req.query || !req.query.code || typeof req.query.code !== 'string') { res.json({ status: 'NOT-OK', error: 'INVALID-PARAMETER', message: 'Undefined parameter: code', }); return; } const reply = await modem.executeUSSD(req.query.code, req.query.include_cusd2); res.json({ status: 'OK', error: false, code: req.query.code, include_cusd2: req.query.include_cusd2, message: reply, }); } router.get('/', handlerIndex);