From a961b2438674b147ebcfdf50ef3a0a0b1eca12e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81ctor=20Falco=CC=81n?= Date: Tue, 30 Dec 2025 07:44:11 +0100 Subject: [PATCH] recover idempotent transaction sync --- .../Sync/TransactionSyncController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Http/Controllers/Sync/TransactionSyncController.php b/app/Http/Controllers/Sync/TransactionSyncController.php index 537f585b..60e484b3 100644 --- a/app/Http/Controllers/Sync/TransactionSyncController.php +++ b/app/Http/Controllers/Sync/TransactionSyncController.php @@ -42,6 +42,21 @@ class TransactionSyncController extends Controller 'user_id' => $request->user()->id, ]); + // If ID is provided, check if transaction already exists (idempotent create) + if (isset($data['id'])) { + $existing = Transaction::query() + ->where('id', $data['id']) + ->where('user_id', $request->user()->id) + ->first(); + + if ($existing) { + // Transaction already exists, return it as success (idempotent) + return response()->json([ + 'data' => $existing->load('labels:id,name,color'), + ], 200); + } + } + // If ID is provided, use it; otherwise Laravel will generate UUID v7 if (isset($data['id'])) { $transaction->id = $data['id'];