From 78b4c84eb85f524add078271d42d35f131bae596 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Mon, 30 Mar 2026 21:30:58 -0700 Subject: [PATCH] feat: implement player deduplication in match upload --- src/app/api/matches/upload/route.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/api/matches/upload/route.ts b/src/app/api/matches/upload/route.ts index a44cf75..fb066bd 100644 --- a/src/app/api/matches/upload/route.ts +++ b/src/app/api/matches/upload/route.ts @@ -194,17 +194,20 @@ export async function POST(request: Request) { } async function findOrCreatePlayer(name: string) { - // Try to find existing player with exact name match + // Normalize the name for deduplication: trim whitespace and convert to lowercase + const normalizedName = name.trim().toLowerCase(); + + // Try to find existing player with matching normalized name let player = await prisma.player.findFirst({ - where: { name }, + where: { normalizedName }, }); if (!player) { - // Create a new player with a unique name - const uniqueName = `${name}-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`; + // Create a new player with the original name and normalized name player = await prisma.player.create({ data: { - name: uniqueName, + name: name.trim(), + normalizedName, rating: 1000, currentElo: 1000, },