Commit 488a5d70 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: correct time_control + result enum values for matches table

Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent a43f91fe
...@@ -47,12 +47,21 @@ switch ($action) { ...@@ -47,12 +47,21 @@ switch ($action) {
$userRes = supabase_auth('user', [], $token, 'GET'); $userRes = supabase_auth('user', [], $token, 'GET');
$userId = $userRes['data']['id'] ?? null; $userId = $userRes['data']['id'] ?? null;
$tcMap = [
'60_0' => 'bullet_1_0', '60_1' => 'bullet_1_1', '120_1' => 'bullet_2_1',
'180_0' => 'blitz_3_0', '180_2' => 'blitz_3_2', '300_0' => 'blitz_5_0',
'300_3' => 'blitz_5_3', '600_0' => 'rapid_10_0', '600_5' => 'rapid_10_5',
'900_10' => 'rapid_15_10', '1800_0' => 'rapid_30_0',
];
$tcKey = $timeControl . '_' . $increment;
$tcEnum = $tcMap[$tcKey] ?? 'custom';
$matchData = [ $matchData = [
'match_type' => 'bot', 'match_type' => 'bot',
'bot_id' => $botId, 'bot_id' => $botId,
'bot_difficulty' => $botId, 'bot_difficulty' => $botId,
'status' => 'in_progress', 'status' => 'in_progress',
'time_control' => $timeControl <= 180 ? 'bullet' : ($timeControl <= 600 ? 'blitz' : 'rapid'), 'time_control' => $tcEnum,
'initial_time_ms' => $timeControl * 1000, 'initial_time_ms' => $timeControl * 1000,
'increment_ms' => $increment * 1000, 'increment_ms' => $increment * 1000,
'white_time_remaining_ms' => $timeControl * 1000, 'white_time_remaining_ms' => $timeControl * 1000,
...@@ -146,7 +155,7 @@ switch ($action) { ...@@ -146,7 +155,7 @@ switch ($action) {
$finalFen = $input['final_fen'] ?? ''; $finalFen = $input['final_fen'] ?? '';
$moves = $input['moves'] ?? null; $moves = $input['moves'] ?? null;
$resultMap = ['win' => 'white_win', 'loss' => 'black_win', 'draw' => 'draw']; $resultMap = ['win' => 'white_wins', 'loss' => 'black_wins', 'draw' => 'draw'];
if ($gameId && !str_starts_with($gameId, 'game_')) { if ($gameId && !str_starts_with($gameId, 'game_')) {
$update = [ $update = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment