From 4caf6216de58794c585fc87b0b894428a167fbda Mon Sep 17 00:00:00 2001 From: enlineawork Date: Mon, 7 Sep 2026 21:45:09 -0300 Subject: [PATCH] F4 WEB: add Inventory function API client --- web-v2/src/lib/inventoryFunctionApi.ts | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 web-v2/src/lib/inventoryFunctionApi.ts 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), + }); +}