mirror of
https://github.com/System-End/scraps.git
synced 2026-04-19 19:45:14 +00:00
fix balance check for transaction
This commit is contained in:
parent
91c49cf2ee
commit
03131c6eb9
1 changed files with 0 additions and 7 deletions
|
|
@ -406,13 +406,6 @@ shop.post('/items/:id/try-luck', async ({ params, headers }) => {
|
|||
// Lock the user row to serialize spend operations and prevent race conditions
|
||||
await tx.execute(sql`SELECT 1 FROM users WHERE id = ${user.id} FOR UPDATE`)
|
||||
|
||||
// Re-check affordability inside the transaction
|
||||
const affordable = await canAfford(user.id, item.price, tx)
|
||||
if (!affordable) {
|
||||
const { balance } = await getUserScrapsBalance(user.id, tx)
|
||||
throw { type: 'insufficient_funds', balance }
|
||||
}
|
||||
|
||||
// Re-check stock inside transaction
|
||||
const currentItem = await tx
|
||||
.select()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue