Follow-up to a7609ff for the whole frontend: all 30 API helpers in
src/lib now pass path values through encodeURIComponent, so an id taken
from the URL can never leave its own path segment and make the page call
another endpoint with the viewer's token.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { apiFetch } from "@/lib/auth/api-client";
|
|
import { CreateOptions, idempotencyHeaders } from "@/lib/offline/idempotency";
|
|
import {
|
|
CreateTreatmentInput,
|
|
Treatment,
|
|
UpdateTreatmentInput,
|
|
WithdrawalStatus,
|
|
} from "./types";
|
|
|
|
export function fetchColonyTreatments(colonyId: string): Promise<Treatment[]> {
|
|
return apiFetch<Treatment[]>(`/colonies/${encodeURIComponent(colonyId)}/treatments`);
|
|
}
|
|
|
|
export function fetchWithdrawalStatus(
|
|
colonyIds: string[],
|
|
): Promise<WithdrawalStatus[]> {
|
|
if (colonyIds.length === 0) {
|
|
return Promise.resolve([]);
|
|
}
|
|
return apiFetch<WithdrawalStatus[]>(
|
|
`/treatments/withdrawal-status?colonyIds=${colonyIds.join(",")}`,
|
|
);
|
|
}
|
|
|
|
export function createTreatment(
|
|
input: CreateTreatmentInput,
|
|
options: CreateOptions = {},
|
|
): Promise<Treatment> {
|
|
return apiFetch<Treatment>("/treatments", {
|
|
method: "POST",
|
|
headers: idempotencyHeaders(options),
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function updateTreatment(
|
|
id: string,
|
|
input: UpdateTreatmentInput,
|
|
): Promise<Treatment> {
|
|
return apiFetch<Treatment>(`/treatments/${encodeURIComponent(id)}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|