Changeset 3a783f2 for pages/api/postgre
- Timestamp:
- 07/05/22 16:36:24 (2 years ago)
- Branches:
- main
- Children:
- 189cd8f
- Parents:
- b13f93b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pages/api/postgre/index.js
rb13f93b r3a783f2 82 82 } 83 83 } 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 } 84 96 } 85 97 }); … … 110 122 const session = sessions.find(session => session.id === session_id) 111 123 124 let takeWhatYouCan = false; 125 if (req.query?.takeWhatYouCan === "true") takeWhatYouCan = true; 126 112 127 if (session) { 113 128 session.lastActivity = Date.now(); 114 129 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 } 116 145 117 146 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.