import assert from "node:assert/strict"; import { InventoryResponseSchema } from "@metis/assets/common"; type Request = (path: string, body?: unknown) => Promise; export async function unlinkAssetFromWorkstations( request: Request, companyId: string, assetId: string ) { const inventory = InventoryResponseSchema.parse( await (await request(`/assets/${companyId}`)).json() ); for (const station of inventory.workstations.filter( (item) => item.values.active && item.values.assetIds.includes(assetId) )) { const response = await request(`/assets/${companyId}/workstations/${station.id}/update`, { values: { ...station.values, computerAssetId: station.values.computerAssetId === assetId ? null : station.values.computerAssetId, assetIds: station.values.assetIds.filter((id) => id !== assetId), }, }); assert.equal(response.status, 200, await response.clone().text()); } }