From 5e2ec81d0c5830a2c8a9794cd20a5be7e781de8d Mon Sep 17 00:00:00 2001 From: ZareMate <0.zaremate@gmail.com> Date: Tue, 30 Dec 2025 18:21:16 +0100 Subject: [PATCH] fix bug for /api/shop/items/buy --- public/js/index.js | 1 + users-api.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/public/js/index.js b/public/js/index.js index 522f9ac1..2d9fcb1a 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -643,6 +643,7 @@ document.getElementById("addressForm").onsubmit = function (e) { const items = cart.map((item) => ({ id: item.name, quantity: item.qty, + sellQuantity: getItemSellQuantity(item.name), })); const request = { userId: user.username, diff --git a/users-api.js b/users-api.js index f9e3a793..45259faa 100644 --- a/users-api.js +++ b/users-api.js @@ -379,7 +379,7 @@ module.exports = function (app, wss, pool) { ); if (!userRow) return res.status(404).json({ ok: false, error: "User not found" }); - if (userRow.balance < price * item.quantity) + if (userRow.balance < price * (item.quantity / item.sellQuantity)) return res.status(400).json({ ok: false, error: `Insufficient balance for item ${item.id}`,