fix: resend offline-queued entries with an idempotency key
When the server saved an inspection, harvest, treatment, feeding, varroa measurement or swarm check but the answer was lost (dead zone at the apiary), the form queued the entry and the sync later created it a second time - including a second automation task. Each opened form now creates one Idempotency-Key, sends it with the request and stores it with the queued entry, so the retry returns the first record. Entries queued before this change still sync without a key. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
5d11756a87
commit
5c2ea7bf1e
16 files changed
+139
-33
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { apiFetch } from "@/lib/auth/api-client";
|
||||
import { CreateOptions, idempotencyHeaders } from "@/lib/offline/idempotency";
|
||||
import { CreateHarvestInput, Harvest, UpdateHarvestInput } from "./types";
|
||||
|
||||
export function fetchHarvests(): Promise<Harvest[]> {
|
||||
@@ -9,9 +10,13 @@ export function fetchHarvest(id: string): Promise<Harvest> {
|
||||
return apiFetch<Harvest>(`/harvests/${id}`);
|
||||
}
|
||||
|
||||
export function createHarvest(input: CreateHarvestInput): Promise<Harvest> {
|
||||
export function createHarvest(
|
||||
input: CreateHarvestInput,
|
||||
options: CreateOptions = {},
|
||||
): Promise<Harvest> {
|
||||
return apiFetch<Harvest>("/harvests", {
|
||||
method: "POST",
|
||||
headers: idempotencyHeaders(options),
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user