diff --git a/web-v2/src/lib/inventoryStructureApi.ts b/web-v2/src/lib/inventoryStructureApi.ts index a289e9b..8533f3d 100644 --- a/web-v2/src/lib/inventoryStructureApi.ts +++ b/web-v2/src/lib/inventoryStructureApi.ts @@ -3,213 +3,54 @@ import { apiRequest } from './api'; export type InventoryStructureKind = 'EMPRESA' | 'DEPARTAMENTO' | 'AREA' | 'YACIMIENTO' | 'INSTALACION' | 'SUBINSTALACION'; export type InventoryFamilyAttributeDataType = 'TEXT' | 'NUMBER' | 'BOOLEAN' | 'DATE' | 'DATETIME' | 'SELECT'; -export interface InventoryFamilyParent { - id: string; - code: string; - name: string; -} - +export interface InventoryFamilyParent { id:string; code:string; name:string; } export interface InventoryFamily { - id: string; - code: string; - name: string; - level: 'INSTALLATION' | 'SUBINSTALLATION'; - legacyTypeCode?: string | null; - informationLabels: string[]; - sourceReference?: string | null; - isActive?: boolean; - parentFamilyIds: string[]; - parentFamilies: InventoryFamilyParent[]; - assetCount?: number; - findingCount?: number; - findingItemIds?: string[]; - technicalAttributeCount?: number; + id:string; code:string; name:string; level:'INSTALLATION'|'SUBINSTALLATION'; legacyTypeCode?:string|null; + informationLabels:string[]; sourceReference?:string|null; isActive?:boolean; parentFamilyIds:string[]; + parentFamilies:InventoryFamilyParent[]; assetCount?:number; findingCount?:number; findingItemIds?:string[]; technicalAttributeCount?:number; } - export interface InventoryFamilyAttribute { - id: string; - inventoryFamilyId: string; - code: string; - name: string; - dataType: InventoryFamilyAttributeDataType; - isRequired: boolean; - isActive: boolean; - unit: string | null; - options: string[] | null; - sortOrder: number; + id:string; inventoryFamilyId:string; code:string; name:string; dataType:InventoryFamilyAttributeDataType; + isRequired:boolean; isActive:boolean; unit:string|null; options:string[]|null; sortOrder:number; } - -export interface InventoryFamilyAttributes { - family: InventoryFamily; - items: InventoryFamilyAttribute[]; - count: number; +export interface InventoryFamilyAttributes { family:InventoryFamily; items:InventoryFamilyAttribute[]; count:number; } +export interface InventoryTechnicalValues { + assetId:string; + family:{id:string;code:string;name:string;level:string}; + definitions:InventoryFamilyAttribute[]; + values:Record; } - -export interface InventoryStructureLevel { - kind: InventoryStructureKind; - label: string; - type: { id: string; code: string; name: string }; - parentKind: InventoryStructureKind | null; - requiresFamily: boolean; -} - -export interface InventoryStructureOptions { - independentMasters: InventoryStructureLevel[]; - levels: InventoryStructureLevel[]; - installationFamilies: InventoryFamily[]; - subinstallationFamilies: InventoryFamily[]; -} - +export interface InventoryStructureLevel { kind:InventoryStructureKind; label:string; type:{id:string;code:string;name:string}; parentKind:InventoryStructureKind|null; requiresFamily:boolean; } +export interface InventoryStructureOptions { independentMasters:InventoryStructureLevel[]; 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 }; + 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; + 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: InventoryFamily; - items: InventoryFamilyFinding[]; - count: number; -} - +export interface InventoryFamilyFindings { family:InventoryFamily; 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 }; - operationalArea?: null | { id: string; code: string; name: string }; - inventoryFamily: null | { - id: string; - code: string; - name: string; - level: string; - informationLabels: string[]; - }; + 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}; operationalArea?:null|{id:string;code:string;name:string}; + inventoryFamily:null|{id:string;code:string;name:string;level:string;informationLabels:string[]}; } -export function getInventoryStructureOptions() { - return apiRequest('/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(`/inventory-families/${familyId}/findings`); -} - -export function getInventoryFamilyAttributes(familyId: string) { - return apiRequest(`/inventory-families/${familyId}/attributes`); -} - -export async function listInventoryFamiliesAdmin() { - return (await apiRequest<{ data: InventoryFamily[] }>('/inventory-families/admin')).data; -} - -export function createInventoryFamily(input: { - level: 'INSTALLATION' | 'SUBINSTALLATION'; - name: string; - parentFamilyIds?: string[]; - informationLabels?: string[]; -}) { - return apiRequest('/inventory-families', { - method: 'POST', body: JSON.stringify(input), - }); -} - -export function updateInventoryFamily(familyId: string, input: { - name?: string; - parentFamilyIds?: string[]; - informationLabels?: string[]; - isActive?: boolean; -}) { - return apiRequest(`/inventory-families/${familyId}`, { - method: 'PATCH', body: JSON.stringify(input), - }); -} - -export function createInventoryFamilyAttribute(familyId: string, input: { - code: string; - name: string; - dataType: InventoryFamilyAttributeDataType; - isRequired?: boolean; - unit?: string | null; - options?: string[]; - sortOrder?: number; -}) { - return apiRequest(`/inventory-families/${familyId}/attributes`, { - method: 'POST', body: JSON.stringify(input), - }); -} - -export function updateInventoryFamilyAttribute(familyId: string, attributeId: string, input: { - name?: string; - dataType?: InventoryFamilyAttributeDataType; - isRequired?: boolean; - isActive?: boolean; - unit?: string | null; - options?: string[] | null; - sortOrder?: number; -}) { - return apiRequest(`/inventory-families/${familyId}/attributes/${attributeId}`, { - method: 'PATCH', body: JSON.stringify(input), - }); -} - -export function replaceInventoryFamilyFindings(familyId: string, input: { - itemIds: string[]; - reason: string; -}) { - return apiRequest(`/inventory-families/${familyId}/findings`, { - method: 'PUT', body: JSON.stringify(input), - }); -} - -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('/inventory-structure', { - method: 'POST', - body: JSON.stringify(input), - }); +export function getInventoryStructureOptions(){return apiRequest('/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(`/inventory-families/${familyId}/findings`);} +export function getInventoryFamilyAttributes(familyId:string){return apiRequest(`/inventory-families/${familyId}/attributes`);} +export function getInventoryTechnicalValues(assetId:string){return apiRequest(`/assets/${assetId}/technical-values`);} +export function replaceInventoryTechnicalValues(assetId:string,values:Record){return apiRequest(`/assets/${assetId}/technical-values`,{method:'PUT',body:JSON.stringify({values})});} +export async function listInventoryFamiliesAdmin(){return (await apiRequest<{data:InventoryFamily[]}>('/inventory-families/admin')).data;} +export function createInventoryFamily(input:{level:'INSTALLATION'|'SUBINSTALLATION';name:string;parentFamilyIds?:string[];informationLabels?:string[]}){return apiRequest('/inventory-families',{method:'POST',body:JSON.stringify(input)});} +export function updateInventoryFamily(familyId:string,input:{name?:string;parentFamilyIds?:string[];informationLabels?:string[];isActive?:boolean}){return apiRequest(`/inventory-families/${familyId}`,{method:'PATCH',body:JSON.stringify(input)});} +export function createInventoryFamilyAttribute(familyId:string,input:{code:string;name:string;dataType:InventoryFamilyAttributeDataType;isRequired?:boolean;unit?:string|null;options?:string[];sortOrder?:number}){return apiRequest(`/inventory-families/${familyId}/attributes`,{method:'POST',body:JSON.stringify(input)});} +export function updateInventoryFamilyAttribute(familyId:string,attributeId:string,input:{name?:string;dataType?:InventoryFamilyAttributeDataType;isRequired?:boolean;isActive?:boolean;unit?:string|null;options?:string[]|null;sortOrder?:number}){return apiRequest(`/inventory-families/${familyId}/attributes/${attributeId}`,{method:'PATCH',body:JSON.stringify(input)});} +export function replaceInventoryFamilyFindings(familyId:string,input:{itemIds:string[];reason:string}){return apiRequest(`/inventory-families/${familyId}/findings`,{method:'PUT',body:JSON.stringify(input)});} +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('/inventory-structure',{method:'POST',body:JSON.stringify(input)});}