- Timestamp:
- 07/12/22 17:03:03 (2 years ago)
- Branches:
- main
- Children:
- 1df3fde
- Parents:
- d0ef259
- Location:
- pages/api
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pages/api/poker/index.js
rd0ef259 re9f11ac 274 274 table.lastActivity = Date.now(); 275 275 setNextPlayerIdx(table.id); 276 277 update_tables_to_database(); 276 278 } 277 279 } -
pages/api/postgre/index.js
rd0ef259 re9f11ac 468 468 469 469 export function update_sessions_to_database() { 470 471 472 470 pool.query('UPDATE sessions SET data = $1 WHERE identifier = $2', [JSON.stringify(sessions), 'sessions_data'], (error, results) => { 471 if (error) throw error; 472 }); 473 473 } 474 474 475 475 export function load_sessions_from_database() { 476 477 478 479 480 476 pool.query('SELECT data FROM sessions WHERE identifier = $1', ['sessions_data'], (error, results) => { 477 if (error) throw error; 478 479 sessions = JSON.parse(results?.rows[0]?.data || []); 480 }); 481 481 } 482 482 load_sessions_from_database(); 483 483 484 485 *Poker game data486 484 /** 485 * Poker game data 486 */ 487 487 export var tables = [] 488 488 … … 492 492 493 493 export function update_tables_to_database() { 494 495 496 497 498 494 tables = tables.map(table => ({...table, turnTimeout: null})); 495 496 pool.query('UPDATE poker SET data = $1 WHERE identifier = $2', [JSON.stringify(tables), 'poker_data'], (error, results) => { 497 if (error) throw error; 498 }); 499 499 } 500 500 501 501 export async function load_tables_from_database() { 502 pool.query('SELECT data FROM poker WHERE identifier = $1', ['poker_data'], (error, results) => { 503 if (error) throw error; 502 pool.query('SELECT data FROM poker WHERE identifier = $1', ['poker_data'], (error, results) => { 503 if (error) throw error; 504 505 tables = JSON.parse(results?.rows[0]?.data || []); 506 507 tables.forEach(table => { 508 if (table.started) { 509 progressRoundTillTheEnd(table.id); 510 } 511 }) 512 513 cleanTables(); 514 515 update_tables_to_database(); 516 }); 517 } 518 load_tables_from_database(); 519 520 /** 521 * Roulette game data 522 */ 523 export var game = {} 524 525 export function update_game_to_database() { 526 pool.query('UPDATE roulette SET data = $1 WHERE identifier = $2', [JSON.stringify(game), 'roulette_data'], (error, results) => { 527 if (error) throw error; 528 }); 529 } 530 531 export async function load_game_from_database() { 532 pool.query('SELECT data FROM roulette WHERE identifier = $1', ['roulette_data'], (error, results) => { 533 if (error) throw error; 534 535 game = JSON.parse(results?.rows[0]?.data || []); 536 537 game.loaded = true; 538 console.log(game); 539 }); 540 } 541 load_game_from_database(); 504 542 505 tables = JSON.parse(results?.rows[0]?.data || []);506 507 tables.forEach(table => {508 if (table.started) {509 progressRoundTillTheEnd(table.id);510 }511 })512 513 cleanTables();514 515 update_tables_to_database();516 });517 }518 load_tables_from_database(); -
pages/api/roulette/index.js
rd0ef259 re9f11ac 1 1 import axios from 'axios'; 2 3 import { game, update_game_to_database } from '../postgre/index' 2 4 3 5 require('dotenv').config(); … … 141 143 })(); 142 144 143 let game ={144 status: '_1_ongoing_timer', // statuses: _1_ongoing_timer, _2_spinning,145 timeToStart: 30,// in seconds146 COUNTDOWN_FROM: 30,147 WAIT_BEFORE: 20,148 magicNumber: -1,149 winningBets: [],150 players: [],145 if (game.status === undefined) { 146 game.status = '_1_ongoing_timer'; // statuses: _1_ongoing_timer, _2_spinning 147 game.timeToStart = 30; // in seconds 148 game.COUNTDOWN_FROM = 30; 149 game.WAIT_BEFORE = 20; 150 game.magicNumber = -1; 151 game.winningBets = []; 152 game.players = []; 151 153 } 152 154 … … 262 264 } 263 265 266 if (game.loaded !== undefined && game.loaded) { 267 update_game_to_database(); 268 } 269 264 270 res.json({ 265 271 success: true,
Note:
See TracChangeset
for help on using the changeset viewer.