Commit b3109e7a authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: chess moves/resign silently failing — non-existent columns

The `matches` table has no `last_activity` or `ended_at` columns.
PostgREST rejects the entire PATCH when ANY column doesn't exist,
causing every move update and resignation to silently fail.

- Remove `last_activity` from handleGameMove (column doesn't exist)
- Change `ended_at` to `completed_at` in handleResign, handleDraw,
  handleComplete (correct column name per DB schema)

This was the root cause of zero sync in multiplayer chess.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 1c145579
......@@ -109,7 +109,7 @@ function handleGameMove($db, string $userId, array $input): void {
if (!$matchId) jsonError('match_id required');
$sdb = supabaseService();
$update = ['updated_at' => date('c'), 'last_activity' => date('c')];
$update = ['updated_at' => date('c')];
if (!empty($input['fen'])) $update['current_fen'] = $input['fen'];
if (!empty($input['move'])) {
......@@ -163,7 +163,8 @@ function handleResign($db, string $userId, array $input): void {
$sdb->update('matches', [
'status' => 'completed',
'result' => $result,
'ended_at' => date('c')
'completed_at' => date('c'),
'updated_at' => date('c')
], ['id' => 'eq.' . $matchId]);
jsonResponse(['result' => $result]);
......@@ -182,7 +183,8 @@ function handleDraw($db, string $userId, array $input): void {
$sdb->update('matches', [
'status' => 'completed',
'result' => 'draw',
'ended_at' => date('c'),
'completed_at' => date('c'),
'updated_at' => date('c'),
'game_state' => ['draw_accepted' => true]
], ['id' => 'eq.' . $matchId]);
......@@ -205,7 +207,8 @@ function handleComplete($db, string $userId, array $input): void {
'result' => $result,
'current_fen' => $fen,
'pgn' => $pgn,
'ended_at' => date('c')
'completed_at' => date('c'),
'updated_at' => date('c')
], ['id' => 'eq.' . $matchId]);
// Use universal rewards function
......@@ -380,7 +383,7 @@ function handleChessLeave(string $userId, array $input): void {
$sdb->update('matches', [
'game_state' => $gameState,
'last_activity' => date('c')
'updated_at' => date('c')
], ['id' => 'eq.' . $matchId]);
jsonResponse(['success' => true, 'bot_replaced' => true]);
......
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