2026-10-13 09:35:31 +00:00
|
|
|
import assert from "node:assert/strict";
|
|
|
|
|
|
|
|
|
|
import { InventoryResponseSchema } from "@metis/assets/common";
|
|
|
|
|
|
|
|
|
|
type Request = (path: string, body?: unknown) => Promise<Response>;
|
|
|
|
|
|
|
|
|
|
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(
|
2026-10-14 17:42:59 +00:00
|
|
|
(item) => item.values.active && item.values.assetIds.includes(assetId)
|
2026-10-13 09:35:31 +00:00
|
|
|
)) {
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|