simplify game service: remove dish persistence, update prediction columns

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 15:12:43 +01:00
parent 2ba74a8773
commit 19bbd225b2

View File

@@ -1,6 +1,6 @@
import { eq, and } from "drizzle-orm"
import type { Database } from "../db/client"
import { predictions, dishes, dishGuesses } from "../db/schema"
import { predictions } from "../db/schema"
export class GameService {
constructor(private db: Database) {}
@@ -8,9 +8,10 @@ export class GameService {
async persistPrediction(data: {
playerId: string
roomId: string
predictedWinner: string
top3: string[]
nulPointsPick: string
first: string
second: string
third: string
last: string
}) {
// Delete existing prediction for this player+room, then insert
await this.db
@@ -19,46 +20,10 @@ export class GameService {
await this.db.insert(predictions).values({
playerId: data.playerId,
roomId: data.roomId,
predictedWinner: data.predictedWinner,
top3: data.top3,
nulPointsPick: data.nulPointsPick,
first: data.first,
second: data.second,
third: data.third,
last: data.last,
})
}
async persistDish(data: {
id: string
roomId: string
name: string
correctCountry: string
}) {
await this.db.insert(dishes).values({
id: data.id,
roomId: data.roomId,
name: data.name,
correctCountry: data.correctCountry,
})
}
async persistDishGuess(data: {
playerId: string
dishId: string
guessedCountry: string
}) {
// Delete existing guess for this player+dish, then insert
await this.db
.delete(dishGuesses)
.where(and(eq(dishGuesses.playerId, data.playerId), eq(dishGuesses.dishId, data.dishId)))
await this.db.insert(dishGuesses).values({
playerId: data.playerId,
dishId: data.dishId,
guessedCountry: data.guessedCountry,
})
}
async markDishesRevealed(roomId: string) {
await this.db
.update(dishes)
.set({ revealed: true })
.where(eq(dishes.roomId, roomId))
}
}