Both records could be created but never changed. A water-content reading decides whether a batch may be sold as honey at all, and queen ratings drive breeding decisions - a slipped digit in either is exactly the kind of wrong value that must not be left standing. - New PATCH /honey-batches/measurements/:measurementId behind honey-batches:measure, and PATCH /queens/evaluations/:evaluationId behind queens:evaluate. Both are addressed by the child record's own id, so the routes take two path segments and do not collide with PATCH /:id. - Both log before and after data, like every other correction. - The measurement list on the honey batch page and the rating list on the queen page gained an edit dialog; the rating dialog reuses the existing criteria list rather than restating it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { apiFetch } from "@/lib/auth/api-client";
|
|
import {
|
|
AssignColonyInput,
|
|
CreateQueenEvaluationInput,
|
|
UpdateQueenEvaluationInput,
|
|
CreateQueenInput,
|
|
Queen,
|
|
QueenColonyHistoryEntry,
|
|
QueenEvaluation,
|
|
QueenLineage,
|
|
QueenStatus,
|
|
UpdateQueenInput,
|
|
} from "./types";
|
|
|
|
export interface QueenFilter {
|
|
status?: QueenStatus;
|
|
}
|
|
|
|
export function fetchQueens(filter: QueenFilter = {}): Promise<Queen[]> {
|
|
const params = new URLSearchParams();
|
|
if (filter.status) params.set("status", filter.status);
|
|
const query = params.toString();
|
|
return apiFetch<Queen[]>(`/queens${query ? `?${query}` : ""}`);
|
|
}
|
|
|
|
export function fetchQueen(id: string): Promise<Queen> {
|
|
return apiFetch<Queen>(`/queens/${id}`);
|
|
}
|
|
|
|
export function fetchQueenHistory(id: string): Promise<QueenColonyHistoryEntry[]> {
|
|
return apiFetch<QueenColonyHistoryEntry[]>(`/queens/${id}/history`);
|
|
}
|
|
|
|
export function fetchQueenLineage(id: string): Promise<QueenLineage> {
|
|
return apiFetch<QueenLineage>(`/queens/${id}/lineage`);
|
|
}
|
|
|
|
export function createQueen(input: CreateQueenInput): Promise<Queen> {
|
|
return apiFetch<Queen>("/queens", {
|
|
method: "POST",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function updateQueen(id: string, input: UpdateQueenInput): Promise<Queen> {
|
|
return apiFetch<Queen>(`/queens/${id}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function assignQueenColony(id: string, input: AssignColonyInput): Promise<Queen> {
|
|
return apiFetch<Queen>(`/queens/${id}/assign-colony`, {
|
|
method: "POST",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function fetchQueenEvaluations(id: string): Promise<QueenEvaluation[]> {
|
|
return apiFetch<QueenEvaluation[]>(`/queens/${id}/evaluations`);
|
|
}
|
|
|
|
export function updateQueenEvaluation(
|
|
evaluationId: string,
|
|
input: UpdateQueenEvaluationInput,
|
|
): Promise<QueenEvaluation> {
|
|
return apiFetch<QueenEvaluation>(`/queens/evaluations/${evaluationId}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function addQueenEvaluation(
|
|
id: string,
|
|
input: CreateQueenEvaluationInput,
|
|
): Promise<QueenEvaluation> {
|
|
return apiFetch<QueenEvaluation>(`/queens/${id}/evaluations`, {
|
|
method: "POST",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|