Changeset 3a783f2 for pages/api/postgre


Ignore:
Timestamp:
07/05/22 16:36:24 (2 years ago)
Author:
anastasovv <simon@…>
Branches:
main
Children:
189cd8f
Parents:
b13f93b
Message:

Finished poker and added ball to roulette

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pages/api/postgre/index.js

    rb13f93b r3a783f2  
    8282                }
    8383              }
     84              else if (req.query?.game === 'poker') {
     85                if (req.query?.outcome === 'lost') {
     86                  pool.query('UPDATE stats SET poker_games = $1 WHERE username = $2', [parseInt(stats.poker_games) + 1, session.username], (error, results) => {
     87                    if (error) throw error;
     88                  });
     89                }
     90                else if (req.query?.outcome === 'won') {
     91                  pool.query('UPDATE stats SET poker_games = $1, poker_won_games = $2 WHERE username = $3', [parseInt(stats.poker_games) + 1, parseInt(stats.poker_won_games) + 1, session.username], (error, results) => {
     92                    if (error) throw error;
     93                  });
     94                }
     95              }
    8496            }
    8597          });
     
    110122      const session = sessions.find(session => session.id === session_id)
    111123
     124      let takeWhatYouCan = false;
     125      if (req.query?.takeWhatYouCan === "true") takeWhatYouCan = true;
     126
    112127      if (session) {
    113128        session.lastActivity = Date.now();
    114129
    115         session.credits = session.credits - parseInt(req.query.credits)
     130        if (session.credits < parseInt(req.query.credits)) {
     131          if (takeWhatYouCan) {
     132            session.credits = 0;
     133          }
     134          else {
     135            res.json({
     136              success: false,
     137            });
     138
     139            return ;
     140          }
     141        }
     142        else {
     143          session.credits = session.credits - parseInt(req.query.credits)
     144        }
    116145
    117146        pool.query('UPDATE players SET credits = $1 WHERE username = $2', [session.credits, session.username], (error, results) => {
Note: See TracChangeset for help on using the changeset viewer.