diff --git a/web-v2/src/lib/inventoryBrowserApi.ts b/web-v2/src/lib/inventoryBrowserApi.ts new file mode 100644 index 0000000..701b5b7 --- /dev/null +++ b/web-v2/src/lib/inventoryBrowserApi.ts @@ -0,0 +1,61 @@ +import { apiRequest } from './api'; +import type { AssetInformationStatus, AssetOperationalStatus } from './api'; + +export interface InventoryBrowserArea { + id: string; + code: string; + name: string; + commonName: string | null; + type: { id: string; code: string; name: string }; + informationStatus: AssetInformationStatus; + operationalStatus: AssetOperationalStatus; + currentOperator: { id: string; code: string; name: string } | null; + yacimientoCount: number; + inventoryCount: number; +} + +export interface InventoryBrowserItem { + id: string; + code: string; + name: string; + commonName: string | null; + type: { id: string; code: string; name: string }; + parent: { id: string; code: string; name: string } | null; + informationStatus: AssetInformationStatus; + operationalStatus: AssetOperationalStatus; + isInventoryInstance: boolean; + inventoryFamily: { id: string; code: string; name: string; level: string } | null; + childrenCount: number; + hasGeometry: boolean; + updatedAt: string; +} + +export interface InventoryBrowserParent { + id: string; + code: string; + name: string; + typeCode: string; +} + +export function listInventoryAreas(params: { search?: string; operatorCompanyId?: string } = {}) { + const query = new URLSearchParams(); + if (params.search?.trim()) query.set('search', params.search.trim()); + if (params.operatorCompanyId) query.set('operatorCompanyId', params.operatorCompanyId); + const suffix = query.size ? `?${query}` : ''; + return apiRequest<{ data: InventoryBrowserArea[]; meta: { count: number } }>(`/inventory-browser/areas${suffix}`); +} + +export function listInventoryChildren( + parentId: string, + params: { search?: string; operatorCompanyId?: string } = {}, +) { + const query = new URLSearchParams(); + if (params.search?.trim()) query.set('search', params.search.trim()); + if (params.operatorCompanyId) query.set('operatorCompanyId', params.operatorCompanyId); + const suffix = query.size ? `?${query}` : ''; + return apiRequest<{ + parent: InventoryBrowserParent; + data: InventoryBrowserItem[]; + meta: { count: number; hasMore: boolean }; + }>(`/inventory-browser/${parentId}/children${suffix}`); +}