feat(web): add real inventory list client
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { apiRequest } from './api';
|
||||
import type { AssetInformationStatus, AssetOperationalStatus } from './api';
|
||||
import type {
|
||||
AssetDataOrigin,
|
||||
AssetInformationStatus,
|
||||
AssetOperationalStatus,
|
||||
PageMeta,
|
||||
} from './api';
|
||||
|
||||
export interface InventoryBrowserArea {
|
||||
id: string;
|
||||
@@ -30,6 +35,27 @@ export interface InventoryBrowserItem {
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface InventoryListItem {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
commonName: string | null;
|
||||
type: { id: string; code: string; name: string };
|
||||
parent: { id: string; code: string; name: string } | null;
|
||||
operationalArea: { id: string; code: string; name: string } | null;
|
||||
operatorCompany: { id: string; code: string; name: string } | null;
|
||||
informationStatus: AssetInformationStatus;
|
||||
operationalStatus: AssetOperationalStatus;
|
||||
childrenCount: number;
|
||||
hasGeometry: boolean;
|
||||
geometryType: string | null;
|
||||
mediaCount: number;
|
||||
dataOrigin: AssetDataOrigin;
|
||||
provenanceVerified: boolean;
|
||||
currentVersion: number;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface InventoryBrowserParent {
|
||||
id: string;
|
||||
code: string;
|
||||
@@ -37,25 +63,44 @@ export interface InventoryBrowserParent {
|
||||
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 interface InventoryQuery {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
search?: string;
|
||||
typeId?: string;
|
||||
status?: AssetInformationStatus | '';
|
||||
operationalStatus?: AssetOperationalStatus | '';
|
||||
operationalAreaId?: string;
|
||||
operatorCompanyId?: string;
|
||||
needsValidation?: boolean;
|
||||
hasGeometry?: boolean;
|
||||
}
|
||||
|
||||
export function listInventoryChildren(
|
||||
parentId: string,
|
||||
params: { search?: string; operatorCompanyId?: string } = {},
|
||||
) {
|
||||
function queryString(params: InventoryQuery): 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}` : '';
|
||||
Object.entries(params).forEach(([key,value]) => {
|
||||
if (value === undefined || value === null || value === '') return;
|
||||
query.set(key,String(value));
|
||||
});
|
||||
return query.size ? `?${query}` : '';
|
||||
}
|
||||
|
||||
export function listRealInventory(params: InventoryQuery = {}) {
|
||||
return apiRequest<{ data: InventoryListItem[]; meta: PageMeta }>(
|
||||
`/inventory-browser/items${queryString(params)}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function listInventoryAreas(params: InventoryQuery = {}) {
|
||||
return apiRequest<{ data: InventoryBrowserArea[]; meta: { count: number } }>(
|
||||
`/inventory-browser/areas${queryString(params)}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function listInventoryChildren(parentId: string, params: InventoryQuery = {}) {
|
||||
return apiRequest<{
|
||||
parent: InventoryBrowserParent;
|
||||
data: InventoryBrowserItem[];
|
||||
meta: { count: number; hasMore: boolean };
|
||||
}>(`/inventory-browser/${parentId}/children${suffix}`);
|
||||
}>(`/inventory-browser/${parentId}/children${queryString(params)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user