diff --git a/web-v2/src/lib/inventoryFunctionApi.ts b/web-v2/src/lib/inventoryFunctionApi.ts new file mode 100644 index 0000000..1cc8dfa --- /dev/null +++ b/web-v2/src/lib/inventoryFunctionApi.ts @@ -0,0 +1,86 @@ +import { apiRequest } from './api'; + +export interface InventoryFunction { + id: string; + code: string; + name: string; + description: string | null; + isActive: boolean; + sortOrder: number; + createdAt: string; + updatedAt: string; +} + +export interface InventoryFunctionAssignment { + id: string; + assetId: string; + functionId: string; + functionCode: string; + functionName: string; + validFrom: string; + validUntil: string | null; + reason: string | null; + changedBy: string | null; + changedByUsername: string | null; + createdAt: string; +} + +export interface InventoryFunctionHistory { + asset: { + id: string; + code: string; + name: string; + typeCode: string; + typeName: string; + familyCode: string | null; + familyName: string | null; + }; + currentFunction: InventoryFunctionAssignment | null; + history: InventoryFunctionAssignment[]; +} + +export async function listInventoryFunctions(includeInactive = false) { + const query = includeInactive ? '?includeInactive=true' : ''; + return (await apiRequest<{ data: InventoryFunction[] }>(`/inventory-functions${query}`)).data; +} + +export function getInventoryFunctionHistory(assetId: string) { + return apiRequest(`/assets/${assetId}/function-history`); +} + +export function changeInventoryFunction( + assetId: string, + input: { functionId: string; effectiveAt?: string; reason?: string | null }, +) { + return apiRequest(`/assets/${assetId}/function`, { + method: 'POST', + body: JSON.stringify(input), + }); +} + +export function createInventoryFunction(input: { + code: string; + name: string; + description?: string | null; + sortOrder?: number; +}) { + return apiRequest('/inventory-functions', { + method: 'POST', + body: JSON.stringify(input), + }); +} + +export function updateInventoryFunction( + id: string, + input: { + name?: string; + description?: string | null; + isActive?: boolean; + sortOrder?: number; + }, +) { + return apiRequest(`/inventory-functions/${id}`, { + method: 'PATCH', + body: JSON.stringify(input), + }); +}