122 lines
3.1 KiB
TypeScript
122 lines
3.1 KiB
TypeScript
import { apiRequest } from './api';
|
|
|
|
export type InventoryStructureKind = 'AREA' | 'YACIMIENTO' | 'INSTALACION' | 'SUBINSTALACION';
|
|
|
|
export interface InventoryFamily {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
level: 'INSTALLATION' | 'SUBINSTALLATION';
|
|
legacyTypeCode: string | null;
|
|
informationLabels: string[];
|
|
parentFamilyId: string | null;
|
|
parentFamilyCode: string | null;
|
|
parentFamilyName: string | null;
|
|
}
|
|
|
|
export interface InventoryStructureLevel {
|
|
kind: InventoryStructureKind;
|
|
label: string;
|
|
type: { id: string; code: string; name: string };
|
|
parentKind: InventoryStructureKind | null;
|
|
requiresFamily: boolean;
|
|
}
|
|
|
|
export interface InventoryStructureOptions {
|
|
levels: InventoryStructureLevel[];
|
|
installationFamilies: InventoryFamily[];
|
|
subinstallationFamilies: InventoryFamily[];
|
|
}
|
|
|
|
export interface InventoryStructureParent {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
commonName: string | null;
|
|
type: { id: string; code: string; name: string };
|
|
inventoryFamily: null | {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
level: 'INSTALLATION' | 'SUBINSTALLATION';
|
|
informationLabels: string[];
|
|
};
|
|
parent: null | { id: string; code: string; name: string };
|
|
}
|
|
|
|
export interface InventoryFamilyFinding {
|
|
id: string;
|
|
code: string;
|
|
sourceNumber: number;
|
|
title: string;
|
|
legalBasis: string | null;
|
|
glossary: string | null;
|
|
suggestedSeverity: number | null;
|
|
categoryId: string;
|
|
categoryCode: string;
|
|
categoryName: string;
|
|
}
|
|
|
|
export interface InventoryFamilyFindings {
|
|
family: {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
level: string;
|
|
informationLabels: string[];
|
|
};
|
|
items: InventoryFamilyFinding[];
|
|
count: number;
|
|
}
|
|
|
|
export interface CreatedInventoryStructure {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
commonName: string | null;
|
|
description: string | null;
|
|
informationStatus: string;
|
|
operationalStatus: string;
|
|
type: { id: string; code: string; name: string };
|
|
parent: null | { id: string; code: string; name: string };
|
|
inventoryFamily: null | {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
level: string;
|
|
informationLabels: string[];
|
|
};
|
|
}
|
|
|
|
export function getInventoryStructureOptions() {
|
|
return apiRequest<InventoryStructureOptions>('/inventory-structure');
|
|
}
|
|
|
|
export async function listInventoryStructureParents(kind: InventoryStructureKind, search = '') {
|
|
const query = new URLSearchParams();
|
|
if (search.trim()) query.set('search', search.trim());
|
|
const suffix = query.size ? `?${query}` : '';
|
|
return (await apiRequest<{ data: InventoryStructureParent[] }>(
|
|
`/inventory-structure/parents/${kind}${suffix}`,
|
|
)).data;
|
|
}
|
|
|
|
export function getInventoryFamilyFindings(familyId: string) {
|
|
return apiRequest<InventoryFamilyFindings>(`/inventory-families/${familyId}/findings`);
|
|
}
|
|
|
|
export function createInventoryStructure(input: {
|
|
kind: InventoryStructureKind;
|
|
code?: string | null;
|
|
name: string;
|
|
commonName?: string | null;
|
|
parentId?: string | null;
|
|
familyId?: string | null;
|
|
description?: string | null;
|
|
}) {
|
|
return apiRequest<CreatedInventoryStructure>('/inventory-structure', {
|
|
method: 'POST',
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|