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