feat: implement player deduplication in match upload

This commit is contained in:
2026-03-30 21:30:58 -07:00
parent 6feada4fd8
commit 78b4c84eb8
+8 -5
View File
@@ -194,17 +194,20 @@ export async function POST(request: Request) {
} }
async function findOrCreatePlayer(name: string) { 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({ let player = await prisma.player.findFirst({
where: { name }, where: { normalizedName },
}); });
if (!player) { if (!player) {
// Create a new player with a unique name // Create a new player with the original name and normalized name
const uniqueName = `${name}-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
player = await prisma.player.create({ player = await prisma.player.create({
data: { data: {
name: uniqueName, name: name.trim(),
normalizedName,
rating: 1000, rating: 1000,
currentElo: 1000, currentElo: 1000,
}, },