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) {
|
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,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user