fix: remove logging from prisma client and fix users API routes

This commit is contained in:
2026-03-31 01:15:57 -07:00
parent 492a18aa1b
commit e0d159ad8d
4 changed files with 56 additions and 12 deletions
+53
View File
@@ -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();
+1 -1
View File
@@ -73,7 +73,7 @@ export async function PATCH(
// Update the user's role // Update the user's role
const updatedUser = await prisma.user.update({ const updatedUser = await prisma.user.update({
where: { id: params.id }, where: { id },
data: { role } data: { role }
}); });
+2 -2
View File
@@ -84,7 +84,7 @@ export async function PATCH(
// Check if user exists // Check if user exists
const user = await prisma.user.findUnique({ const user = await prisma.user.findUnique({
where: { id: params.id }, where: { id },
include: { player: true } include: { player: true }
}); });
@@ -106,7 +106,7 @@ export async function PATCH(
} }
const updatedUser = await prisma.user.update({ const updatedUser = await prisma.user.update({
where: { id: params.id }, where: { id },
data: updateData, data: updateData,
include: { player: true } include: { player: true }
}); });
-9
View File
@@ -11,15 +11,6 @@ const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
// Create PrismaClient with adapter // Create PrismaClient with adapter
const createPrismaClient = () => { const createPrismaClient = () => {
const client = new PrismaClient({ adapter }) 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 return client
} }