refactor: use centralized player ownership in session-manager
Replace inline ownership building with buildPlayerOwnershipMap() utility. Changes: - Import buildPlayerOwnershipMap and PlayerOwnershipMap types - Replace manual DB query + Object.fromEntries with utility call - Simplify code: 7 lines → 1 line - Use shared type for consistency Part of player ownership centralization plan (Phase 2/7). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import { eq } from 'drizzle-orm'
|
||||
import { db, schema } from '@/db'
|
||||
import { buildPlayerOwnershipMap, type PlayerOwnershipMap } from './player-ownership'
|
||||
import { type GameMove, type GameName, getValidator } from './validation'
|
||||
|
||||
export interface CreateSessionOptions {
|
||||
@@ -215,7 +216,7 @@ export async function applyGameMove(
|
||||
})
|
||||
|
||||
// Fetch player ownership for authorization checks (room-based games)
|
||||
let playerOwnership: Record<string, string> | undefined
|
||||
let playerOwnership: PlayerOwnershipMap | undefined
|
||||
let internalUserId: string | undefined
|
||||
if (session.roomId) {
|
||||
try {
|
||||
@@ -229,13 +230,8 @@ export async function applyGameMove(
|
||||
}
|
||||
}
|
||||
|
||||
const players = await db.query.players.findMany({
|
||||
columns: {
|
||||
id: true,
|
||||
userId: true,
|
||||
},
|
||||
})
|
||||
playerOwnership = Object.fromEntries(players.map((p) => [p.id, p.userId]))
|
||||
// Use centralized ownership utility
|
||||
playerOwnership = await buildPlayerOwnershipMap(session.roomId)
|
||||
console.log('[SessionManager] Player ownership map:', playerOwnership)
|
||||
console.log('[SessionManager] Internal userId for authorization:', internalUserId)
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user