From 3c37ce8af531dccd7c7d5d8849263cb35a0e5171 Mon Sep 17 00:00:00 2001 From: Parsa Yazdani <3parsa3@gmail.com> Date: Thu, 4 Jul 2024 20:24:10 +1000 Subject: [PATCH] more simple --- Server/src/server.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Server/src/server.ts b/Server/src/server.ts index da7f9ec..9ec4556 100644 --- a/Server/src/server.ts +++ b/Server/src/server.ts @@ -70,6 +70,10 @@ function placeBet (userShares: UserShare[], userId: number, team: number, shares } userBalances[userId] -= transactionCost + if (dollarsBet[userId] === undefined) dollarsBet[userId] = 0 + dollarsBet[userId] += transactionCost + + console.log('Paid $' + (transactionCost as unknown as string) + ' for ' + (sharesBought as unknown as string) + ' shares on team ' + (team as unknown as string) + ' by user ' + (userId as unknown as string)) return newUserShares } @@ -77,6 +81,7 @@ function placeBet (userShares: UserShare[], userId: number, team: number, shares interface UserShare { [key: number]: number } const userBalances: UserShare = { 1: 1000, 2: 1000, 3: 1000, 4: 1000 } +const dollarsBet: UserShare = { 0: 2 } let userShares: UserShare[] = [{ 0: 1 }, { 0: 1 }] // app.get('/bets', (_, res) => { @@ -92,6 +97,7 @@ let userShares: UserShare[] = [{ 0: 1 }, { 0: 1 }] // }) app.get('/bets', (req, res) => { + res.header('Content-Type', 'application/json') const userId: number = parseInt(req.query.userId as unknown as string) const team: number = parseInt(req.query.team as unknown as string) const sharesBought: number = parseInt(req.query.sharesBought as unknown as string) @@ -119,7 +125,8 @@ app.get('/bets', (req, res) => { const userBets = shares[userId] ?? 0 return { shares: userBets, - winPayout: liquidity * Math.floor(100 * (userBets / bets[team])) / 100 + winPayout: liquidity * Math.floor(100 * (userBets / bets[team])) / 100, + dollarsBet: dollarsBet[userId] ?? 0 } }) }))