From e0d159ad8d4280fb000281fecd26c018d10ab38c Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 31 Mar 2026 01:15:57 -0700 Subject: [PATCH] fix: remove logging from prisma client and fix users API routes --- scripts/recalculate-elo.js | 53 ++++++++++++++++++++++++++++ src/app/api/users/[id]/role/route.ts | 2 +- src/app/api/users/[id]/route.ts | 4 +-- src/lib/prisma.ts | 9 ----- 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 scripts/recalculate-elo.js diff --git a/scripts/recalculate-elo.js b/scripts/recalculate-elo.js new file mode 100644 index 0000000..8923f3e --- /dev/null +++ b/scripts/recalculate-elo.js @@ -0,0 +1,53 @@ +#!/usr/bin/env node + +/** + * Recalculate all ELO ratings and partnership stats + * + * This script rebuilds all player stats and partnership stats from scratch + * by processing all matches in chronological order. + */ + +const { PrismaClient } = require('@prisma/client'); +const { recalculateAllElo } = require('../src/lib/elo-utils'); + +const prisma = new PrismaClient(); + +async function main() { + console.log('Starting ELO recalculation...'); + console.log('This will delete all existing stats and rebuild them from match history.'); + console.log(''); + + try { + // Confirm before proceeding + const readline = require('readline').createInterface({ + input: process.stdin, + output: process.stdout + }); + + const confirm = await new Promise(resolve => { + readline.question('Are you sure you want to proceed? (yes/no): ', resolve); + }); + readline.close(); + + if (confirm.toLowerCase() !== 'yes') { + console.log('Operation cancelled.'); + return; + } + + console.log('Recalculating stats...'); + const result = await recalculateAllElo(prisma); + + console.log('\nRecalculation complete!'); + console.log(`- Matches processed: ${result.matchesProcessed}`); + console.log(`- Players updated: ${result.playersUpdated}`); + console.log(`- Partnerships updated: ${result.partnershipsUpdated}`); + + } catch (error) { + console.error('Error during recalculation:', error); + process.exit(1); + } finally { + await prisma.$disconnect(); + } +} + +main(); diff --git a/src/app/api/users/[id]/role/route.ts b/src/app/api/users/[id]/role/route.ts index 69b47b7..69f72b9 100644 --- a/src/app/api/users/[id]/role/route.ts +++ b/src/app/api/users/[id]/role/route.ts @@ -73,7 +73,7 @@ export async function PATCH( // Update the user's role const updatedUser = await prisma.user.update({ - where: { id: params.id }, + where: { id }, data: { role } }); diff --git a/src/app/api/users/[id]/route.ts b/src/app/api/users/[id]/route.ts index 263fa27..63bb8b7 100644 --- a/src/app/api/users/[id]/route.ts +++ b/src/app/api/users/[id]/route.ts @@ -84,7 +84,7 @@ export async function PATCH( // Check if user exists const user = await prisma.user.findUnique({ - where: { id: params.id }, + where: { id }, include: { player: true } }); @@ -106,7 +106,7 @@ export async function PATCH( } const updatedUser = await prisma.user.update({ - where: { id: params.id }, + where: { id }, data: updateData, include: { player: true } }); diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index ffa962e..e62fcf4 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -11,15 +11,6 @@ const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) // Create PrismaClient with adapter const createPrismaClient = () => { const client = new PrismaClient({ adapter }) - - // Add logging if in development - if (process.env.NODE_ENV !== 'production') { - client.$on('query', (e) => { - console.log('Query:', e.query) - console.log('Duration:', e.duration, 'ms') - }) - } - return client }