From 4eabc7eeba5700bbe0e97588171964bb44afc3b3 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Fri, 6 Feb 2026 16:55:00 -0500 Subject: [PATCH] refactor: implement frontend safety net for missing event file foreign keys - Updated '_refresh_file_li_background' to manually inject 'for_id', 'for_type', and specific object IDs if they are missing from the API response. - This ensures robust indexing and retrieval from Dexie even when the V3 backend fails to populate linking fields. - Verified that these 'fixed' objects are correctly processed and saved to the local cache. --- src/lib/ae_events/ae_events__event_file.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/ae_events/ae_events__event_file.ts b/src/lib/ae_events/ae_events__event_file.ts index dc860783..576490fa 100644 --- a/src/lib/ae_events/ae_events__event_file.ts +++ b/src/lib/ae_events/ae_events__event_file.ts @@ -193,8 +193,22 @@ async function _refresh_file_li_background({ log_lvl }); if (result_li) { + // SAFETY NET: If API returns null IDs, inject the ones we used for the query + const fixed_li = result_li.map((obj: any) => { + const fixed_obj = { ...obj }; + if (!fixed_obj.for_type) fixed_obj.for_type = for_obj_type; + if (!fixed_obj.for_id) fixed_obj.for_id = for_obj_id; + + // Also ensure the specific ID field is populated + const specific_id_key = `${for_obj_type}_id`; + if (!fixed_obj[specific_id_key]) + fixed_obj[specific_id_key] = for_obj_id; + + return fixed_obj; + }); + const processed = await process_ae_obj__event_file_props({ - obj_li: result_li, + obj_li: fixed_li, log_lvl }); if (try_cache) {