From d834c1f0fc3be8f2e15cad56266c243ccd75cd55 Mon Sep 17 00:00:00 2001 From: Szymon Potrzebowski <105052198+sormys@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:24:27 +0200 Subject: [PATCH] Fixed raise request (#69) Raise request didn't include player's already bet amount. --- src/utils/commonRequest.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/utils/commonRequest.ts b/src/utils/commonRequest.ts index 8d905a0..85df054 100644 --- a/src/utils/commonRequest.ts +++ b/src/utils/commonRequest.ts @@ -375,21 +375,20 @@ export async function playerCanBetAmount( amount: string, client: PoolClient ): Promise { - const smallBlindValue = await getSmallBlindValue(gameId, client) - const playerSize = (await getPlayersInGame(gameId, client)).length - const smallBlind = await getSmallBlindToken(gameId, playerSize, client) - const smallBlindState = await getPlayerState(smallBlind, client) - const bigBlind = await getBigBlindToken(gameId, playerSize, client) - const bigBlindState = await getPlayerState(bigBlind, client) - - if (playerToken === smallBlind && smallBlindState == null) { - amount = (+amount - +smallBlindValue).toString() - } else if (playerToken === bigBlind && bigBlindState == null) { - amount = (+amount - +smallBlindValue * 2).toString() - } + const bet = await getPlayerBet(playerToken, client) + const funds = await getPlayerFunds(playerToken, client) + + return +amount <= +funds + +bet +} + +export async function getPlayerBet(playerToken: string, client: PoolClient) { + const query = 'SELECT bet FROM Players WHERE token=$1' + return (await client.query(query, [playerToken])).rows[0].bet +} - const query = 'SELECT 1 FROM Players WHERE token=$1 AND funds>=$2' - return (await client.query(query, [playerToken, amount])).rowCount !== 0 +export async function getPlayerFunds(playerToken: string, client: PoolClient) { + const query = 'SELECT funds FROM Players WHERE token=$1' + return (await client.query(query, [playerToken])).rows[0].funds } export async function isAmountRaise(