Case WDP gz

by N

18
Raw
case 'wdp': {
    const nomor = sender.split("@")[0];
    const productData = JSON.parse(
        fs.readFileSync('./db/datagz.json', 'utf8')
    );
    const userData = JSON.parse(fs.readFileSync('./db/users.json'));
    const userProfile = userData.find((user) => user.nomor === nomor);
    if (!userProfile) return m.reply(`Kamu belum terdaftar, silahkan ketik : *Daftar*\nuntuk bisa mengakses`);

    const matchingProducts = productData.filter(item => 
        item.nama_layanan.toLowerCase().includes('weekly')
    );

    if (matchingProducts.length === 0) {
        return m.reply(`Tidak ada produk untuk kategori *Weekly*`);
    }

    matchingProducts.sort((a, b) => parseInt(a.harga) - parseInt(b.harga));

    const { role } = userProfile;
    let formattedResponse = `Hallo *${pushname}* Role Kamu *${role}*\nBerikut LIST *WEEKLY* Untukmu\n\n`;
    formattedResponse += `*Cara Beli :*\nTrx [Kode] [Tujuan]\n`;
    formattedResponse += `*Contoh :*\nTrx MLPHWDP 123456789\n\n`;

    const rupiah = (amount) => `Rp ${parseInt(amount).toLocaleString('id-ID')}`;

    matchingProducts.forEach(product => {
        let markupPercentage = defaultMarkupPercentage;
        if (userProfile.role === "GOLD") {
            markupPercentage = markupConfig.gold;
        } else if (userProfile.role === "PLATINUM") {
            markupPercentage = markupConfig.platinum;
        } else if (userProfile.role === "BRONZE") {
            markupPercentage = markupConfig.bronze;
        } else if (userProfile.role === "OWNER") {
            markupPercentage = markupConfig.owner;
        }

        const originalPrice = parseFloat(product.harga);
        const increasedPrice = originalPrice * (1 + markupPercentage);
        const adjustedPrice = Math.round(increasedPrice);

        formattedResponse += `*🛍️ ${product.nama_layanan}.*
> *Kode :* ${product.kode}
> *Harga :* ${rupiah(adjustedPrice)}
> *Status :* ${product.status === 'available' ? 'Tersedia' : 'Gangguan'} \n`;
    });

    xstbot.sendMessage(m.chat, { text: formattedResponse }, { quoted: m });
}
break;