fix bug for /api/shop/items/buy

This commit is contained in:
ZareMate 2025-12-30 18:21:16 +01:00
parent 84fed4acda
commit 5e2ec81d0c
2 changed files with 2 additions and 1 deletions

View File

@ -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,

View File

@ -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}`,