From 636431f9367f37026af1ef345e000aabb1a41391 Mon Sep 17 00:00:00 2001 From: enlineawork Date: Mon, 7 Sep 2026 14:22:28 -0300 Subject: [PATCH] =?UTF-8?q?F3.1=20WEB:=20agregar=20contrato=20de=20merge?= =?UTF-8?q?=20cronol=C3=B3gico?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web-v2/src/lib/inventoryMergeApi.ts | 86 +++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 web-v2/src/lib/inventoryMergeApi.ts diff --git a/web-v2/src/lib/inventoryMergeApi.ts b/web-v2/src/lib/inventoryMergeApi.ts new file mode 100644 index 0000000..cbab709 --- /dev/null +++ b/web-v2/src/lib/inventoryMergeApi.ts @@ -0,0 +1,86 @@ +import { apiRequest, listAssets } from './api'; +import type { AssetDetail, AssetListItem } from './api'; + +export interface InventoryMergeAlias { + id: string; + code: string; + name: string; + reason: string; + mergedAt: string; + depth: number; +} + +export interface InventoryMergeStatus { + requested: { + id: string; + code: string; + name: string; + typeCode: string; + }; + isMerged: boolean; + canonical: { + id: string; + code: string; + name: string; + typeCode: string; + }; + chain: Array<{ + id: string; + sourceAssetId: string; + canonicalAssetId: string; + reason: string; + mergedAt: string; + mergedBy: string | null; + source: string; + }>; + aliases: InventoryMergeAlias[]; +} + +export interface InventoryMergeResult { + merge: { + id: string; + sourceAssetId: string; + canonicalAssetId: string; + reason: string; + mergedAt: string; + }; + source: { id: string; code: string; name: string }; + canonical: { id: string; code: string; name: string }; + sourceVersionNumber: number; + reparentedChildIds: string[]; + historyPolicy: 'HISTORICAL_REFERENCES_PRESERVED'; +} + +export function getInventoryMergeStatus(assetId: string) { + return apiRequest(`/assets/${assetId}/merge-status`); +} + +export function mergeInventoryAsset( + sourceAssetId: string, + canonicalAssetId: string, + reason: string, +) { + return apiRequest(`/assets/${sourceAssetId}/merge`, { + method: 'POST', + body: JSON.stringify({ canonicalAssetId, reason }), + }); +} + +export async function searchInventoryMergeCandidates( + source: AssetDetail, + search = '', +): Promise { + if (!source.parent?.id || !source.operationalArea?.id || !source.operatorCompany?.id) return []; + const page = await listAssets({ + page: 1, + pageSize: 80, + search: search.trim() || undefined, + typeId: source.type.id, + parentId: source.parent.id, + operationalAreaId: source.operationalArea.id, + operatorCompanyId: source.operatorCompany.id, + }); + return page.data.filter((candidate) => + candidate.id !== source.id && candidate.informationStatus !== 'INACTIVE', + ); +}