save-postpaid-product.js 835 Bytes
const MODULE_NAME = 'CONFIG.SAVE-POSTPAID-PRODUCT';

const fs = require('fs/promises');
const logger = require('tektrans-logger');

const configData = require('./data');

/**
 * Menyimpan nilai terkini config.products (postpaid)
 *
 */
module.exports = async (xid, key, value) => {
    try {
        logger.verbose(`${MODULE_NAME} 19BB0554: Saving postpaid product to config file`, {
            xid,
            key,
            value,
        });
        const config = await configData.reload();

        config.postpaid_products[key] = value;
        await fs.writeFile('config.json', JSON.stringify(config, null, 4));

        await configData.reload();
    } catch (e) {
        logger.warn(`${MODULE_NAME} D0F796A6: Exception`, {
            xid,
            eCode: e.code,
            eMessage: e.message,
        });
    }
};