save-product.js 823 Bytes
const MODULE_NAME = 'CONFIG.SAVE-PREPAID-PRODUCT';

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

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

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

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

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