fix: remove logging from prisma client and fix users API routes
This commit is contained in:
@@ -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();
|
||||||
@@ -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 }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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 }
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user