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]>
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { apiFetch } from "@/lib/auth/api-client";
|
|
import { CreateOptions, idempotencyHeaders } from "@/lib/offline/idempotency";
|
|
import {
|
|
CreateFeedingInput,
|
|
Feeding,
|
|
FeedingSummaryEntry,
|
|
UpdateFeedingInput,
|
|
} from "./types";
|
|
|
|
export function fetchColonyFeedings(colonyId: string): Promise<Feeding[]> {
|
|
return apiFetch<Feeding[]>(`/colonies/${colonyId}/feedings`);
|
|
}
|
|
|
|
export function fetchColonyFeedingsSummary(colonyId: string): Promise<FeedingSummaryEntry[]> {
|
|
return apiFetch<FeedingSummaryEntry[]>(`/colonies/${colonyId}/feedings/summary`);
|
|
}
|
|
|
|
export function createFeeding(
|
|
input: CreateFeedingInput,
|
|
options: CreateOptions = {},
|
|
): Promise<Feeding> {
|
|
return apiFetch<Feeding>("/feedings", {
|
|
method: "POST",
|
|
headers: idempotencyHeaders(options),
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function updateFeeding(
|
|
id: string,
|
|
input: UpdateFeedingInput,
|
|
): Promise<Feeding> {
|
|
return apiFetch<Feeding>(`/feedings/${id}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|