diff --git a/src/app/api/room/[id]/route.ts b/src/app/api/room/[id]/route.ts index fadc181..8ae8343 100644 --- a/src/app/api/room/[id]/route.ts +++ b/src/app/api/room/[id]/route.ts @@ -30,13 +30,11 @@ export async function GET( if (match) { matchType = "unanimous"; matchLikes = data.users.length; - } else if (allFinished) { + } else if (allFinished && data.restaurants.length > 0) { const best = findBestMatch(data.likes, data.restaurants); - if (best) { - match = best.id; - matchType = "best"; - matchLikes = best.likes; - } + match = best.id; + matchType = "best"; + matchLikes = best.likes; } return NextResponse.json({ @@ -59,14 +57,13 @@ export async function GET( function findBestMatch( likes: Record, restaurants: { id: string; rating: number }[], -): { id: string; likes: number } | null { - let bestId: string | null = null; +): { id: string; likes: number } { + let bestId = restaurants[0].id; let bestLikes = 0; - let bestRating = 0; + let bestRating = restaurants[0].rating; for (const r of restaurants) { const count = likes[r.id]?.length ?? 0; - if (count === 0) continue; if ( count > bestLikes || @@ -78,6 +75,5 @@ function findBestMatch( } } - if (!bestId) return null; return { id: bestId, likes: bestLikes }; } diff --git a/src/app/api/room/[id]/swipe/route.ts b/src/app/api/room/[id]/swipe/route.ts index a7ead13..2caca9e 100644 --- a/src/app/api/room/[id]/swipe/route.ts +++ b/src/app/api/room/[id]/swipe/route.ts @@ -28,10 +28,7 @@ export async function POST( data.likes[rid].push(userId); } - if ( - data.users.length > 1 && - data.likes[rid].length === data.users.length - ) { + if (data.likes[rid].length === data.users.length) { data.match = rid; } }