feat: implement player deduplication in match upload
This commit is contained in:
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user