metis-desk/modules/assets/src/web/shared/api/inventory-request.ts
David 91f1d07e97 Add tests for current operating systems and workplace asset management
- Implement `current-operating-systems-ui.test.py` to validate the functionality of current operating systems in the UI, including tests for source and states, computer changes, responsive design, error handling, and version saving.
- Create `workplace-add-asset.test.py` to test the addition of assets to workstations, covering scenarios such as conflict resolution, responsive design on mobile, error handling during asset creation, and HTTP guards for asset management.
2026-10-25 13:46:06 +01:00

27 lines
808 B
TypeScript

import { csrfFetch } from "@metis/core/client";
import { z } from "zod/v4";
import { InventoryApiError } from "./inventory-api-error";
export async function inventoryRequest(
path: string,
body?: unknown,
headers?: Record<string, string>
) {
const response = await csrfFetch(`/api/assets/${path}`, {
method: body === undefined ? "GET" : "POST",
credentials: "same-origin",
headers: { ...(body === undefined ? {} : { "content-type": "application/json" }), ...headers },
...(body === undefined ? {} : { body: JSON.stringify(body) }),
});
const data: unknown = await response.json();
if (!response.ok) {
const error = z.object({ code: z.string() }).safeParse(data);
throw new InventoryApiError(error.success ? error.data.code : "INTERNAL_ERROR");
}
return data;
}