From bfa19438896a7cf74ebfe82573478285549bb6dc Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 6 Jan 2026 17:22:19 -0500 Subject: [PATCH] Fix IDAA Recovery Meetings loading and optimize API retry logic - Implemented workaround for 'conference' field search restriction in V3 by using local filtering - Optimized post_object to stop retrying on 4xx client errors (400, 401, 403) - Migrated Archives and Event/Recovery Meeting modules to Aether API CRUD V3 - Added editable_fields definitions for Archive and Archive Content objects --- src/lib/ae_api/api_post_object.ts | 6 + .../ae_archives__archive.editable_fields.ts | 19 + src/lib/ae_archives/ae_archives__archive.ts | 681 ++-------- ...chives__archive_content.editable_fields.ts | 29 + .../ae_archives__archive_content.ts | 335 ++--- src/lib/ae_events/ae_events__event.ts | 1163 +++-------------- .../idaa/(idaa)/recovery_meetings/+layout.ts | 7 +- 7 files changed, 471 insertions(+), 1769 deletions(-) create mode 100644 src/lib/ae_archives/ae_archives__archive.editable_fields.ts create mode 100644 src/lib/ae_archives/ae_archives__archive_content.editable_fields.ts diff --git a/src/lib/ae_api/api_post_object.ts b/src/lib/ae_api/api_post_object.ts index 0266737e..978b935b 100644 --- a/src/lib/ae_api/api_post_object.ts +++ b/src/lib/ae_api/api_post_object.ts @@ -127,6 +127,12 @@ export const post_object = async function post_object({ const errorBody = await response.text(); console.error(`HTTP error! status: ${response.status}`, errorBody); + + // Don't retry on client errors (400, 401, 403) + if (response.status >= 400 && response.status < 404) { + return false; + } + throw new Error(`HTTP error! status: ${response.status} - ${errorBody}`); } diff --git a/src/lib/ae_archives/ae_archives__archive.editable_fields.ts b/src/lib/ae_archives/ae_archives__archive.editable_fields.ts new file mode 100644 index 00000000..1aef5450 --- /dev/null +++ b/src/lib/ae_archives/ae_archives__archive.editable_fields.ts @@ -0,0 +1,19 @@ +export const editable_fields__archive = [ + 'code', + 'name', + 'description', + 'original_datetime', + 'original_timezone', + 'original_location', + 'original_url', + 'original_url_text', + 'sort_by', + 'sort_by_desc', + 'cfg_json', + 'enable', + 'hide', + 'priority', + 'sort', + 'group', + 'notes' +]; diff --git a/src/lib/ae_archives/ae_archives__archive.ts b/src/lib/ae_archives/ae_archives__archive.ts index 2369217b..2055f13f 100644 --- a/src/lib/ae_archives/ae_archives__archive.ts +++ b/src/lib/ae_archives/ae_archives__archive.ts @@ -8,13 +8,14 @@ import { load_ae_obj_li__archive_content } from '$lib/ae_archives/ae_archives__a const ae_promises: key_val = {}; -// Updated 2024-09-25 +// Updated 2026-01-06 export async function load_ae_obj_id__archive({ api_cfg, archive_id, inc_content_li = false, enabled = 'enabled', hidden = 'not_hidden', + view = 'default', limit = 99, offset = 0, params = {}, @@ -26,6 +27,7 @@ export async function load_ae_obj_id__archive({ inc_content_li?: boolean; enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + view?: string; limit?: number; offset?: number; params?: key_val; @@ -37,30 +39,21 @@ export async function load_ae_obj_id__archive({ } ae_promises.load__archive_obj = await api - .get_ae_obj_id_crud({ + .get_ae_obj_v3({ api_cfg: api_cfg, obj_type: 'archive', obj_id: archive_id, - use_alt_table: true, - use_alt_base: false, - params: params, + view, + params, log_lvl: log_lvl }) .then(async function (archive_obj_get_result) { if (archive_obj_get_result) { if (try_cache) { - // Process the results first const processed_obj_li = await process_ae_obj__archive_props({ obj_li: [archive_obj_get_result], log_lvl: log_lvl }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } await db_save_ae_obj_li__ae_obj({ db_instance: db_archives, table_name: 'archive', @@ -68,15 +61,6 @@ export async function load_ae_obj_id__archive({ properties_to_save: properties_to_save, log_lvl: log_lvl }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // // This is expecting a list - // db_save_ae_obj_li__archive({ - // obj_type: 'archive', - // obj_li: [archive_obj_get_result] - // }); } return archive_obj_get_result; } else { @@ -88,43 +72,27 @@ export async function load_ae_obj_id__archive({ console.log('No results returned or failed.', error); }); - if (log_lvl) { - console.log('ae_promises.load__archive_obj:', ae_promises.load__archive_obj); - } - - if (inc_content_li) { + if (inc_content_li && ae_promises.load__archive_obj) { // Load the contents for the archive - if (log_lvl) { - console.log(`Need to load the content list for the archive now`); - } - const load_archive_content_obj_li = load_ae_obj_li__archive_content({ + const load_archive_content_obj_li = await load_ae_obj_li__archive_content({ api_cfg: api_cfg, for_obj_type: 'archive', for_obj_id: archive_id, - enabled: enabled, // all, disabled, enabled - hidden: hidden, // all, hidden, not_hidden - limit: limit, // Limit for the comments + enabled: enabled, + hidden: hidden, + limit: limit, offset: offset, params: params, try_cache: try_cache, log_lvl: log_lvl - }).then((archive_content_obj_li) => { - if (log_lvl) { - console.log(`archive_content_obj_li = `, archive_content_obj_li); - } - return archive_content_obj_li; }); - - if (log_lvl) { - console.log(`archive_content_obj_li = `, load_archive_content_obj_li); - } ae_promises.load__archive_obj.archive_content_li = load_archive_content_obj_li; } return ae_promises.load__archive_obj; } -// Updated 2024-11-20 +// Updated 2026-01-06 export async function load_ae_obj_li__archive({ api_cfg, for_obj_type = 'account', @@ -132,6 +100,7 @@ export async function load_ae_obj_li__archive({ inc_content_li = false, enabled = 'enabled', hidden = 'not_hidden', + view = 'default', limit = 99, offset = 0, order_by_li = { @@ -151,9 +120,10 @@ export async function load_ae_obj_li__archive({ inc_content_li?: boolean; enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + view?: string; limit?: number; offset?: number; - order_by_li?: key_val; + order_by_li?: Record; params?: key_val; try_cache?: boolean; log_lvl?: number; @@ -164,43 +134,27 @@ export async function load_ae_obj_li__archive({ ); } - const params_json: key_val = {}; - - // console.log('params_json:', params_json); - ae_promises.load__archive_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, + .get_ae_obj_li_v3({ + api_cfg, obj_type: 'archive', - for_obj_type: for_obj_type, - for_obj_id: for_obj_id, - use_alt_tbl: false, - use_alt_mdl: false, - use_alt_exp: false, - enabled: enabled, - hidden: hidden, - order_by_li: order_by_li, - limit: limit, - offset: offset, - params_json: params_json, - params: params, - log_lvl: log_lvl + for_obj_type, + for_obj_id, + enabled, + hidden, + view, + limit, + offset, + order_by_li, + log_lvl }) .then(async function (archive_obj_li_get_result) { if (archive_obj_li_get_result) { if (try_cache) { - // Process the results first const processed_obj_li = await process_ae_obj__archive_props({ obj_li: archive_obj_li_get_result, log_lvl: log_lvl }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } await db_save_ae_obj_li__ae_obj({ db_instance: db_archives, table_name: 'archive', @@ -208,14 +162,6 @@ export async function load_ae_obj_li__archive({ properties_to_save: properties_to_save, log_lvl: log_lvl }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // db_save_ae_obj_li__archive({ - // obj_type: 'archive', - // obj_li: archive_obj_li_get_result - // }); } return archive_obj_li_get_result; } else { @@ -223,53 +169,31 @@ export async function load_ae_obj_li__archive({ } }); - if (log_lvl) { - console.log('ae_promises.load__archive_obj_li:', ae_promises.load__archive_obj_li); - } - - if (inc_content_li) { - // Load the contents for the archives - if (log_lvl) { - console.log(`Need to load the content list for each archive now`); - } + if (inc_content_li && ae_promises.load__archive_obj_li) { for (let i = 0; i < ae_promises.load__archive_obj_li.length; i++) { const archive_obj = ae_promises.load__archive_obj_li[i]; const archive_id = archive_obj.archive_id_random; - const load_archive_content_obj_li = load_ae_obj_li__archive_content({ + const content_li = await load_ae_obj_li__archive_content({ api_cfg: api_cfg, for_obj_type: 'archive', for_obj_id: archive_id, - enabled: enabled, // all, disabled, enabled - hidden: hidden, // all, hidden, not_hidden - limit: limit, // Limit for the comments - offset: offset, - params: params, - try_cache: try_cache, - log_lvl: log_lvl - }).then((archive_content_obj_li) => { - if (log_lvl) { - console.log(`archive_content_obj_li = `, archive_content_obj_li); - } - - return archive_content_obj_li; + enabled, + hidden, + limit, + offset, + params, + try_cache, + log_lvl }); - - if (log_lvl) { - console.log(`load_archive_content_obj_li = `, load_archive_content_obj_li); - } - - if (load_archive_content_obj_li) { - ae_promises.load__archive_obj_li[i].archive_content_obj_li = - load_archive_content_obj_li; - } + ae_promises.load__archive_obj_li[i].archive_content_li = content_li; } } return ae_promises.load__archive_obj_li; } -// Updated 2025-06-23 +// Updated 2026-01-06 export async function create_ae_obj__archive({ api_cfg, account_id, @@ -289,83 +213,46 @@ export async function create_ae_obj__archive({ console.log(`*** create_ae_obj__archive() *** account_id=${account_id}`); } - if (!account_id) { - console.log(`ERROR: Archives - Archive - account_id required to create`); - return false; - } + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'archive', + fields: { + account_id_random: account_id, + ...data_kv + }, + params, + log_lvl + }); - ae_promises.create__archive = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'archive', - fields: { - account_id_random: account_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__archive_props({ + obj_li: [result], + log_lvl: log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_archives, + table_name: 'archive', + obj_li: processed_obj_li, + properties_to_save: properties_to_save, log_lvl: log_lvl - }) - .then(async function (archive_obj_create_result) { - if (archive_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__archive_props({ - obj_li: [archive_obj_create_result], - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - await db_save_ae_obj_li__ae_obj({ - db_instance: db_archives, - table_name: 'archive', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // db_save_ae_obj_li__archive( - // { - // obj_type: 'archive', - // obj_li: [archive_obj_create_result] - // }); - } - return archive_obj_create_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); }); - - if (log_lvl) { - console.log('ae_promises.create__archive:', ae_promises.create__archive); } - return ae_promises.create__archive; + + return result; } -// Updated 2024-11-08 +// Updated 2026-01-06 export async function delete_ae_obj_id__archive({ api_cfg, archive_id, - method = 'delete', // 'delete', 'disable', 'hide' + method = 'delete', params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; archive_id: string; - method?: string; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; params?: key_val; try_cache?: boolean; log_lvl?: number; @@ -374,36 +261,23 @@ export async function delete_ae_obj_id__archive({ console.log(`*** delete_ae_obj_id__archive() *** archive_id=${archive_id}`); } - ae_promises.delete__archive_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'archive', - obj_id: archive_id, - key: api_cfg.api_crud_super_key, - params: params, - method: method, - log_lvl: log_lvl - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () { - if (try_cache) { - if (log_lvl) { - console.log(`Attempting to remove IDB entry for archive_id=${archive_id}`); - } - db_archives.content.delete(archive_id); // Delete from the DB no matter what. - } - }); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'archive', + obj_id: archive_id, + method, + params, + log_lvl + }); - if (log_lvl) { - console.log('ae_promises.delete__archive_obj:', ae_promises.delete__archive_obj); + if (try_cache) { + await db_archives.archive.delete(archive_id); } - return ae_promises.delete__archive_obj; + return result; } -// Updated 2025-06-23 +// Updated 2026-01-06 export async function update_ae_obj__archive({ api_cfg, archive_id, @@ -423,357 +297,104 @@ export async function update_ae_obj__archive({ console.log(`*** update_ae_obj__archive() *** archive_id=${archive_id}`, data_kv); } - // Perform the API update - const result = await api.update_ae_obj_id_crud({ - api_cfg: api_cfg, + const result = await api.update_ae_obj_v3({ + api_cfg, obj_type: 'archive', obj_id: archive_id, fields: data_kv, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl + params, + log_lvl }); - // Handle the result - if (result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__archive_props({ - obj_li: [result], - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - await db_save_ae_obj_li__ae_obj({ - db_instance: db_archives, - table_name: 'archive', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // await db_save_ae_obj_li__archive({ - // obj_type: 'archive', - // obj_li: [result], - // log_lvl: log_lvl, - // }); - } - return result; - } else { - console.error('Failed to update archive.'); - return null; + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__archive_props({ + obj_li: [result], + log_lvl: log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_archives, + table_name: 'archive', + obj_li: processed_obj_li, + properties_to_save: properties_to_save, + log_lvl: log_lvl + }); } + + return result; } -// This new function is using CRUD v2. This should allow for more flexibility in the queries. -// Updated 2024-09-25 +// Updated 2026-01-06 export async function qry__archive({ api_cfg, - archive_id, + account_id, qry_str, - qry_files, - qry_start_datetime, // Example greater than: '2024-10-24' enabled = 'enabled', hidden = 'not_hidden', + view = 'default', limit = 50, offset = 0, - params = {}, - try_cache = true, - log_lvl = 0 -}: { - api_cfg: any; - archive_id: any; - qry_str?: string; - qry_files?: null | boolean; - qry_start_datetime?: null | string; // Greater than this datetime - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden - limit?: number; - offset?: number; - params?: any; - try_cache?: boolean; - log_lvl?: number; -}) { - console.log(`*** qry__archive() *** archive_id=${archive_id} qry_str=${qry_str}`); - - // let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled - // let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden - // let limit: number = (params.qry__limit ?? 25); // 99 - // let offset: number = (params.qry__offset ?? 0); // 0 - - const params_json: key_val = {}; - - // if (qry_str && qry_str.length > 2) { - // params_json['ft_qry'] = {}; - // params_json['ft_qry']['default_qry_str'] = qry_str; - // } - - params_json['qry'] = []; - - if (qry_files === true) { - const qry_param = { - type: 'AND', - field: 'file_count_all', - operator: '>', - value: 0 - }; - params_json['qry'].push(qry_param); - } else if (qry_files === false) { - const qry_param = { - type: 'AND', - field: 'file_count_all', - operator: 'IS', - value: null - }; - params_json['qry'].push(qry_param); - } - - if (qry_start_datetime) { - const qry_param = { - type: 'AND', - field: 'start_datetime', - operator: '>', - value: qry_start_datetime - }; - params_json['qry'].push(qry_param); - } - - const order_by_li = { + order_by_li = { priority: 'DESC', sort: 'DESC', - start_datetime: 'ASC', name: 'ASC', updated_on: 'DESC', created_on: 'DESC' - }; + }, + log_lvl = 0 +}: { + api_cfg: any; + account_id: string; + qry_str?: string; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + view?: string; + limit?: number; + offset?: number; + order_by_li?: Record; + log_lvl?: number; +}) { + const search_query: any = { and: [] }; - ae_promises.load__archive_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'archive', - for_obj_type: 'event', - for_obj_id: archive_id, - use_alt_tbl: true, // NOTE: We want to use the alt table for archive searching - use_alt_mdl: false, - use_alt_exp: false, - enabled: enabled, - hidden: hidden, - order_by_li: order_by_li, - limit: limit, - offset: offset, - params_json: params_json, - params: params, - log_lvl: log_lvl - }) - .then(async function (archive_obj_li_get_result) { - if (archive_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__archive_props({ - obj_li: archive_obj_li_get_result, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - await db_save_ae_obj_li__ae_obj({ - db_instance: db_archives, - table_name: 'archive', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - } - return archive_obj_li_get_result; - } else { - return []; - } - }); - - if (log_lvl) { - console.log('ae_promises.load__archive_obj_li:', ae_promises.load__archive_obj_li); + if (account_id) { + search_query.and.push({ field: 'account_id_random', op: 'eq', value: account_id }); } + + if (qry_str) { + search_query.q = qry_str; + } + + ae_promises.load__archive_obj_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'archive', + search_query, + enabled, + hidden, + view, + limit, + offset, + order_by_li, + log_lvl + }); + return ae_promises.load__archive_obj_li; } -// // Updated 2024-09-25 -// export async function search__archive( -// { -// api_cfg, -// account_id, -// poc_agree = null, -// fulltext_search_qry_str, -// ft_content_search_qry_str, -// like_search_qry_str = null, -// file_count = false, // If true then only show those that have a file count -// person_name = null, -// params = {}, -// try_cache = true, -// log_lvl = 0 -// }: { -// api_cfg: any, -// account_id: any, -// poc_agree?: null|boolean, -// fulltext_search_qry_str?: null|string, -// ft_content_search_qry_str?: null|string, -// like_search_qry_str?: null|string, -// file_count?: boolean, -// person_name?: null|string, -// params?: any, -// try_cache?: boolean, -// log_lvl?: number -// } -// ) { -// console.log(`*** search__archive() *** account_id=${account_id}`); - -// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled -// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden -// let limit: number = (params.qry__limit ?? 25); // 99 -// let offset: number = (params.qry__offset ?? 0); // 0 - -// let params_json: key_val = {}; - -// // if (!fulltext_search_qry_str && !like_search_qry_str) { -// // console.log('No search string provided!!!'); -// // return false; // Returning false instead of [] because no search was performed. -// // } - -// if (fulltext_search_qry_str || ft_content_search_qry_str) { -// params_json['ft_qry'] = {}; -// if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { -// params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str; -// } - -// if (ft_content_search_qry_str && ft_content_search_qry_str.length > 2) { -// params_json['ft_qry']['archive_content_li_qry_str'] = ft_content_search_qry_str; -// } -// } - -// // Use the AND (AND LIKE) query -// // if (like_search_qry_str || like_content_search_qry_str) { -// // params_json['and_like'] = {}; -// // if (like_search_qry_str && like_search_qry_str.length > 2) { -// // params_json['and_like']['default_qry_str'] = like_search_qry_str; -// // } -// // if (like_content_search_qry_str && like_content_search_qry_str.length > 2) { -// // params_json['and_like']['archive_content_li_qry_str'] = like_content_search_qry_str; -// // } -// // } - -// // Use the AND (OR LIKE) query -// if (like_search_qry_str || like_content_search_qry_str || like_content_search_qry_str) { -// params_json['or_like'] = {}; -// if (like_search_qry_str && like_search_qry_str.length > 2) { -// params_json['or_like']['default_qry_str'] = like_search_qry_str; -// } -// if (like_content_search_qry_str && like_content_search_qry_str.length > 2) { -// params_json['or_like']['archive_content_li_qry_str'] = like_content_search_qry_str; -// } -// if (like_content_search_qry_str && like_content_search_qry_str.length > 2) { -// params_json['or_like']['archive_content_li_qry_str'] = like_content_search_qry_str; -// } -// } - -// params_json['and_qry'] = {}; - -// if (poc_agree) { -// params_json['and_qry']['poc_agree'] = poc_agree; -// } - -// if (file_count) { -// params_json['and_qry']['file_count'] = file_count; -// } - -// // This should be using a like with surrounded by %'s -// if (person_name) { -// params_json['and_qry']['archive_full_name'] = person_name; -// } - -// let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}; - -// ae_promises.load__archive_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ -// api_cfg: api_cfg, -// obj_type: 'archive', -// for_obj_type: 'account', -// for_obj_id: account_id, -// use_alt_table: true, // NOTE: We want to use the alt table for archive searching -// use_alt_base: false, -// enabled: enabled, -// hidden: hidden, -// order_by_li: order_by_li, -// limit: limit, -// offset: offset, -// params_json: params_json, -// params: params, -// log_lvl: log_lvl -// }) -// .then(function (archive_obj_li_get_result) { -// if (archive_obj_li_get_result) { -// if (try_cache) { -// db_save_ae_obj_li__archive({ -// obj_type: 'archive', -// obj_li: archive_obj_li_get_result -// }); -// } -// return archive_obj_li_get_result; -// } else { -// return []; -// } -// }) -// .catch(function (error: any) { -// console.log('No results returned or failed.', error); -// }) -// .finally(function () { -// }); - -// if (log_lvl) { -// console.log('ae_promises.load__archive_obj_li:', ae_promises.load__archive_obj_li); -// } -// return ae_promises.load__archive_obj_li; -// } - // Updated 2025-06-04 export const properties_to_save = [ 'id', 'archive_id', - // 'archive_id_random', - 'code', - 'account_id', - // 'account_id_random', - 'name', 'description', - 'original_datetime', 'original_timezone', 'original_location', - 'original_url', 'original_url_text', - 'sort_by', 'sort_by_desc', - 'cfg_json', - 'enable', 'hide', 'priority', @@ -782,25 +403,10 @@ export const properties_to_save = [ 'notes', 'created_on', 'updated_on', - - // Generated fields for sorting locally only 'tmp_sort_1', 'tmp_sort_2' - // 'tmp_sort_a', - // 'tmp_sort_b', - - // From SQL view - // 'archive_content_count', - - // A key value list of the contents - // 'archive_content_kv', - // 'archive_content_li', ]; -/** - * NON-EXPORTED LOCAL HELPER - * Processes a list of Aether objects by applying common and specific transformations. - */ async function _process_generic_props>({ obj_li, obj_type, @@ -812,39 +418,24 @@ async function _process_generic_props>({ log_lvl?: number; specific_processor?: (obj: T) => Promise | T; }): Promise { - if (log_lvl > 0) { - console.log( - `*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***` - ); - } - - if (!obj_li || obj_li.length === 0) { - if (log_lvl > 0) console.log('No objects to process.'); - return []; - } + if (!obj_li || obj_li.length === 0) return []; const processed_obj_li: T[] = []; for (const original_obj of obj_li) { let processed_obj = { ...original_obj }; - // --- Common Transformations --- - - // 1. Standardize ID and other '_random' fields - // The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'. for (const key in processed_obj) { if (key.endsWith('_random')) { - const newKey = key.slice(0, -7); // Remove '_random' suffix - processed_obj[newKey] = processed_obj[key]; + const newKey = key.slice(0, -7); + (processed_obj as any)[newKey] = processed_obj[key]; } } - // Ensure 'id' is set from '[obj_type]_id_random' const randomIdKey = `${obj_type}_id_random`; if (processed_obj[randomIdKey]) { (processed_obj as any).id = processed_obj[randomIdKey]; } - // 2. Create common computed properties for client-side sorting. const group = processed_obj.group ?? '0'; const priority = processed_obj.priority ? 1 : 0; const sort = processed_obj.sort ?? '0'; @@ -854,7 +445,6 @@ async function _process_generic_props>({ (processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; - // --- Specific Transformations --- if (specific_processor) { processed_obj = await Promise.resolve(specific_processor(processed_obj)); } @@ -878,7 +468,6 @@ export async function process_ae_obj__archive_props({ obj_type: 'archive', log_lvl, specific_processor: (obj) => { - // Archive-specific computed sort fields, overriding generic ones if needed obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ obj.sort?.toString().padStart(3, '0') ?? '' }_${obj.updated_on ?? obj.created_on}`; @@ -889,4 +478,4 @@ export async function process_ae_obj__archive_props({ return obj; } }); -} +} \ No newline at end of file diff --git a/src/lib/ae_archives/ae_archives__archive_content.editable_fields.ts b/src/lib/ae_archives/ae_archives__archive_content.editable_fields.ts new file mode 100644 index 00000000..c1c90d11 --- /dev/null +++ b/src/lib/ae_archives/ae_archives__archive_content.editable_fields.ts @@ -0,0 +1,29 @@ +export const editable_fields__archive_content = [ + 'archive_id', + 'archive_id_random', + 'archive_content_type', + 'name', + 'description', + 'content_html', + 'content_json', + 'url', + 'url_text', + 'hosted_file_id', + 'hosted_file_id_random', + 'file_path', + 'filename', + 'file_extension', + 'original_datetime', + 'original_timezone', + 'original_location', + 'original_url', + 'original_url_text', + 'enable_for_public', + 'cfg_json', + 'enable', + 'hide', + 'priority', + 'sort', + 'group', + 'notes' +]; diff --git a/src/lib/ae_archives/ae_archives__archive_content.ts b/src/lib/ae_archives/ae_archives__archive_content.ts index cad29de4..22573b58 100644 --- a/src/lib/ae_archives/ae_archives__archive_content.ts +++ b/src/lib/ae_archives/ae_archives__archive_content.ts @@ -6,26 +6,18 @@ import { db_archives } from '$lib/ae_archives/db_archives'; const ae_promises: key_val = {}; -// TESTING NOTE: I changed these to all use async and await. Not sure if this helps or hurts things. Mainly this is related to the Dexie DB changes. 2024-11-08 - -// Updated 2024-09-25 +// Updated 2026-01-06 export async function load_ae_obj_id__archive_content({ api_cfg, archive_content_id, - // enabled = 'enabled', - // hidden = 'not_hidden', - // limit = 99, - // offset = 0, + view = 'default', params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; archive_content_id: string; - // enabled?: "enabled" | "all" | "not_enabled" | undefined, - // hidden?: "hidden" | "all" | "not_hidden" | undefined, - // limit?: number, - // offset?: number, + view?: string; params?: key_val; try_cache?: boolean; log_lvl?: number; @@ -37,30 +29,21 @@ export async function load_ae_obj_id__archive_content({ } ae_promises.load__archive_content_obj = await api - .get_ae_obj_id_crud({ + .get_ae_obj_v3({ api_cfg: api_cfg, obj_type: 'archive_content', obj_id: archive_content_id, - use_alt_table: false, - use_alt_base: false, - params: params, + view, + params, log_lvl: log_lvl }) .then(async function (archive_content_obj_get_result) { if (archive_content_obj_get_result) { if (try_cache) { - // Process the results first const processed_obj_li = await process_ae_obj__archive_content_props({ obj_li: [archive_content_obj_get_result], log_lvl: log_lvl }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } await db_save_ae_obj_li__ae_obj({ db_instance: db_archives, table_name: 'content', @@ -68,16 +51,6 @@ export async function load_ae_obj_id__archive_content({ properties_to_save: properties_to_save, log_lvl: log_lvl }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // // This is expecting a list - // await db_save_ae_obj_li__archive_content({ - // obj_type: 'archive_content', - // obj_li: [archive_content_obj_get_result] - - // }); } return archive_content_obj_get_result; } else { @@ -92,13 +65,14 @@ export async function load_ae_obj_id__archive_content({ return ae_promises.load__archive_content_obj; } -// Updated 2024-11-20 +// Updated 2026-01-06 export async function load_ae_obj_li__archive_content({ api_cfg, for_obj_type = 'archive', for_obj_id, enabled = 'enabled', hidden = 'not_hidden', + view = 'default', limit = 99, offset = 0, order_by_li = { @@ -118,9 +92,10 @@ export async function load_ae_obj_li__archive_content({ for_obj_id: string; enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + view?: string; limit?: number; offset?: number; - order_by_li?: key_val; + order_by_li?: Record; params?: key_val; try_cache?: boolean; log_lvl?: number; @@ -131,43 +106,27 @@ export async function load_ae_obj_li__archive_content({ ); } - const params_json: key_val = {}; - - // console('params_json:', params_json); - ae_promises.load__archive_content_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ + .get_ae_obj_li_v3({ api_cfg: api_cfg, obj_type: 'archive_content', - for_obj_type: for_obj_type, - for_obj_id: for_obj_id, - use_alt_tbl: false, - use_alt_mdl: false, - use_alt_exp: false, - enabled: enabled, - hidden: hidden, - order_by_li: order_by_li, - limit: limit, - offset: offset, - params_json: params_json, - params: params, + for_obj_type, + for_obj_id, + enabled, + hidden, + view, + limit, + offset, + order_by_li, log_lvl: log_lvl }) .then(async function (archive_content_obj_li_get_result) { if (archive_content_obj_li_get_result) { if (try_cache) { - // Process the results first const processed_obj_li = await process_ae_obj__archive_content_props({ obj_li: archive_content_obj_li_get_result, log_lvl: log_lvl }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } await db_save_ae_obj_li__ae_obj({ db_instance: db_archives, table_name: 'content', @@ -175,34 +134,17 @@ export async function load_ae_obj_li__archive_content({ properties_to_save: properties_to_save, log_lvl: log_lvl }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // await db_save_ae_obj_li__archive_content({ - // obj_type: 'archive_content', obj_li: archive_content_obj_li_get_result - // }); } return archive_content_obj_li_get_result; } else { return []; } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); }); - if (log_lvl) { - console.log( - 'ae_promises.load__archive_content_obj_li:', - ae_promises.load__archive_content_obj_li - ); - } - return ae_promises.load__archive_content_obj_li; } -// Updated 2025-06-23 +// Updated 2026-01-06 export async function create_ae_obj__archive_content({ api_cfg, archive_id, @@ -227,78 +169,46 @@ export async function create_ae_obj__archive_content({ return false; } - ae_promises.create__archive_content = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'archive_content', - fields: { - archive_id_random: archive_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'archive_content', + fields: { + archive_id_random: archive_id, + ...data_kv + }, + params, + log_lvl + }); + + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__archive_content_props({ + obj_li: [result], + log_lvl: log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_archives, + table_name: 'content', + obj_li: processed_obj_li, + properties_to_save: properties_to_save, log_lvl: log_lvl - }) - .then(async function (archive_content_obj_create_result) { - if (archive_content_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__archive_content_props({ - obj_li: [archive_content_obj_create_result], - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - await db_save_ae_obj_li__ae_obj({ - db_instance: db_archives, - table_name: 'content', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // await db_save_ae_obj_li__archive_content( - // { - // obj_type: 'archive_content', - // obj_li: [archive_content_obj_create_result] - // }); - } - return archive_content_obj_create_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); }); - - if (log_lvl) { - console.log('ae_promises.create__archive_content:', ae_promises.create__archive_content); } - return ae_promises.create__archive_content; + + return result; } -// Updated 2024-11-08 +// Updated 2026-01-06 export async function delete_ae_obj_id__archive_content({ api_cfg, archive_content_id, - method = 'delete', // 'delete', 'disable', 'hide' + method = 'delete', params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; archive_content_id: string; - method?: string; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; params?: key_val; try_cache?: boolean; log_lvl?: number; @@ -309,41 +219,23 @@ export async function delete_ae_obj_id__archive_content({ ); } - ae_promises.delete__archive_content_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'archive_content', - obj_id: archive_content_id, - key: api_cfg.api_crud_super_key, - params: params, - method: method, - log_lvl: log_lvl - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () { - if (try_cache) { - if (log_lvl) { - console.log( - `Attempting to remove IDB entry for archive_content_id=${archive_content_id}` - ); - } - db_archives.content.delete(archive_content_id); // Delete from the DB no matter what. - } - }); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'archive_content', + obj_id: archive_content_id, + method, + params, + log_lvl + }); - if (log_lvl) { - console.log( - 'ae_promises.delete__archive_content_obj:', - ae_promises.delete__archive_content_obj - ); + if (try_cache) { + await db_archives.content.delete(archive_content_id); } - return ae_promises.delete__archive_content_obj; + return result; } -// Updated 2025-06-23 +// Updated 2026-01-06 export async function update_ae_obj__archive_content({ api_cfg, archive_content_id, @@ -366,95 +258,56 @@ export async function update_ae_obj__archive_content({ ); } - // Perform the API update - const result = await api.update_ae_obj_id_crud({ - api_cfg: api_cfg, + const result = await api.update_ae_obj_v3({ + api_cfg, obj_type: 'archive_content', obj_id: archive_content_id, fields: data_kv, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl + params, + log_lvl }); - // Handle the result - if (result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__archive_content_props({ - obj_li: [result], - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - await db_save_ae_obj_li__ae_obj({ - db_instance: db_archives, - table_name: 'content', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - - // await db_save_ae_obj_li__archive_content({ - // obj_type: 'archive_content', - // obj_li: [result], - // log_lvl: log_lvl, - // }); - } - return result; - } else { - console.error('Failed to update archive content.'); - return null; + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__archive_content_props({ + obj_li: [result], + log_lvl: log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_archives, + table_name: 'content', + obj_li: processed_obj_li, + properties_to_save: properties_to_save, + log_lvl: log_lvl + }); } + + return result; } // Updated 2025-06-04 export const properties_to_save = [ 'id', 'archive_content_id', - // 'archive_content_id_random', - 'archive_id', - // 'archive_id_random', - 'archive_content_type', - 'name', 'description', - 'content_html', 'content_json', - 'url', 'url_text', - 'hosted_file_id', 'hosted_file_id_random', - 'file_path', - 'filename', 'file_extension', - 'original_datetime', 'original_timezone', 'original_location', 'original_url', 'original_url_text', - 'enable_for_public', - 'cfg_json', - 'enable', 'hide', 'priority', @@ -463,24 +316,13 @@ export const properties_to_save = [ 'notes', 'created_on', 'updated_on', - - // Generated fields for sorting locally only 'tmp_sort_1', 'tmp_sort_2', - // 'tmp_sort_a', - // 'tmp_sort_b', - - // From SQL view 'archive_code', 'archive_name', - 'hash_sha256' ]; -/** - * NON-EXPORTED LOCAL HELPER - * Processes a list of Aether objects by applying common and specific transformations. - */ async function _process_generic_props>({ obj_li, obj_type, @@ -492,39 +334,24 @@ async function _process_generic_props>({ log_lvl?: number; specific_processor?: (obj: T) => Promise | T; }): Promise { - if (log_lvl > 0) { - console.log( - `*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***` - ); - } - - if (!obj_li || obj_li.length === 0) { - if (log_lvl > 0) console.log('No objects to process.'); - return []; - } + if (!obj_li || obj_li.length === 0) return []; const processed_obj_li: T[] = []; for (const original_obj of obj_li) { let processed_obj = { ...original_obj }; - // --- Common Transformations --- - - // 1. Standardize ID and other '_random' fields - // The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'. for (const key in processed_obj) { if (key.endsWith('_random')) { - const newKey = key.slice(0, -7); // Remove '_random' suffix - processed_obj[newKey] = processed_obj[key]; + const newKey = key.slice(0, -7); + (processed_obj as any)[newKey] = processed_obj[key]; } } - // Ensure 'id' is set from '[obj_type]_id_random' const randomIdKey = `${obj_type}_id_random`; if (processed_obj[randomIdKey]) { (processed_obj as any).id = processed_obj[randomIdKey]; } - // 2. Create common computed properties for client-side sorting. const group = processed_obj.group ?? '0'; const priority = processed_obj.priority ? 1 : 0; const sort = processed_obj.sort ?? '0'; @@ -534,7 +361,6 @@ async function _process_generic_props>({ (processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; - // --- Specific Transformations --- if (specific_processor) { processed_obj = await Promise.resolve(specific_processor(processed_obj)); } @@ -558,7 +384,6 @@ export async function process_ae_obj__archive_content_props({ obj_type: 'archive_content', log_lvl, specific_processor: (obj) => { - // Archive content-specific computed sort fields, overriding generic ones if needed obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ obj.sort?.toString().padStart(3, '0') ?? '' }_${obj.original_datetime ?? ''}`; @@ -574,4 +399,4 @@ export async function process_ae_obj__archive_content_props({ return obj; } }); -} +} \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__event.ts b/src/lib/ae_events/ae_events__event.ts index 48c975e3..782292f3 100644 --- a/src/lib/ae_events/ae_events__event.ts +++ b/src/lib/ae_events/ae_events__event.ts @@ -11,30 +11,24 @@ import { load_ae_obj_li__event_badge_template } from '$lib/ae_events/ae_events__ const ae_promises: key_val = {}; -// Updated 2025-05-22 +// Updated 2026-01-06 export async function load_ae_obj_id__event({ api_cfg, event_id, + view = 'default', inc_device_li = false, - inc_file_li = false, inc_location_li = false, - inc_presentation_li = false, - inc_presenter_li = false, inc_session_li = false, - inc_badge_li = false, - inc_template_li = false, // badge templates + inc_template_li = false, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; + view?: string; inc_device_li?: boolean; - inc_file_li?: boolean; inc_location_li?: boolean; - inc_presentation_li?: boolean; - inc_presenter_li?: boolean; inc_session_li?: boolean; - inc_badge_li?: boolean; inc_template_li?: boolean; try_cache?: boolean; log_lvl?: number; @@ -43,33 +37,21 @@ export async function load_ae_obj_id__event({ console.log(`*** load_ae_obj_id__event() *** event_id=${event_id}`); } - const params = {}; - ae_promises.load__event_obj = await api - .get_ae_obj_id_crud({ + .get_ae_obj_v3({ api_cfg: api_cfg, obj_type: 'event', obj_id: event_id, - use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. - use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. - params: params, + view, log_lvl: log_lvl }) .then(async function (event_obj_get_result) { if (event_obj_get_result) { if (try_cache) { - // Process the results first const processed_obj_li = await process_ae_obj__event_props({ obj_li: [event_obj_get_result], log_lvl: log_lvl }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'event', @@ -77,9 +59,6 @@ export async function load_ae_obj_id__event({ properties_to_save: properties_to_save, log_lvl: log_lvl }); - if (log_lvl) { - console.log('DB save completed.'); - } } return event_obj_get_result; } else { @@ -91,487 +70,135 @@ export async function load_ae_obj_id__event({ console.log('No results returned or failed.', error); }); - if (log_lvl) { - console.log('ae_promises.load__event_obj:', ae_promises.load__event_obj); - } - - if (inc_device_li) { - // Load the devices for the event - if (log_lvl) { - console.log(`Need to load the device list for the event now`); + if (ae_promises.load__event_obj) { + if (inc_device_li) { + ae_promises.load__event_obj.event_device_obj_li = await load_ae_obj_li__event_device({ + api_cfg, + for_obj_type: 'event', + for_obj_id: event_id, + log_lvl + }); } - const load_event_device_obj_li = load_ae_obj_li__event_device({ - api_cfg: api_cfg, - for_obj_type: 'event', - for_obj_id: event_id, - params: { qry__enabled: 'enabled', qry__limit: 49 }, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_device_obj_li) => { - if (log_lvl) { - console.log(`event_device_obj_li = `, event_device_obj_li); - } - return event_device_obj_li; - }); - - if (log_lvl) { - console.log(`load_event_device_obj_li = `, load_event_device_obj_li); + if (inc_location_li) { + ae_promises.load__event_obj.event_location_obj_li = await load_ae_obj_li__event_location({ + api_cfg, + for_obj_type: 'event', + for_obj_id: event_id, + log_lvl + }); } - ae_promises.load__event_obj.event_device_obj_li = load_event_device_obj_li; - } - - if (inc_location_li) { - // Load the locations for the event - if (log_lvl) { - console.log(`Need to load the location list for the event now`); + if (inc_session_li) { + ae_promises.load__event_obj.event_session_obj_li = await load_ae_obj_li__event_session({ + api_cfg, + for_obj_type: 'event', + for_obj_id: event_id, + log_lvl + }); } - const load_event_location_obj_li = load_ae_obj_li__event_location({ - api_cfg: api_cfg, - for_obj_type: 'event', - for_obj_id: event_id, - enabled: 'enabled', - limit: 19, - log_lvl: log_lvl - }).then((event_location_obj_li) => { - if (log_lvl) { - console.log(`event_location_obj_li = `, event_location_obj_li); - } - return event_location_obj_li; - }); - - if (log_lvl) { - console.log(`load_event_location_obj_li = `, load_event_location_obj_li); - } - ae_promises.load__event_obj.event_location_obj_li = load_event_location_obj_li; - } - - if (inc_session_li) { - // Load the sessions for the events - if (log_lvl) { - console.log(`Need to load the session list for the event now`); - } - const load_event_session_obj_li = load_ae_obj_li__event_session({ - api_cfg: api_cfg, - for_obj_type: 'event', - for_obj_id: event_id, - enabled: 'enabled', - limit: 249, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_session_obj_li) => { - if (log_lvl) { - console.log(`event_session_obj_li = `, event_session_obj_li); - } - return event_session_obj_li; - }); - - if (log_lvl) { - console.log(`load_event_session_obj_li = `, load_event_session_obj_li); - } - ae_promises.load__event_obj.event_session_obj_li = load_event_session_obj_li; - } - - if (inc_template_li) { - // Load the badge templates for the event - log_lvl = 2; - if (log_lvl) { - console.log(`Need to load the badge template list for the event now`); - } - const load_event_badge_template_obj_li = load_ae_obj_li__event_badge_template({ - api_cfg: api_cfg, - // for_obj_type: 'event', - // for_obj_id: event_id, - event_id: event_id, - enabled: 'enabled', - limit: 19, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_badge_template_obj_li) => { - if (log_lvl) { - console.log(`event_badge_template_obj_li = `, event_badge_template_obj_li); - } - return event_badge_template_obj_li; - }); - if (log_lvl) { - console.log(`load_event_badge_template_obj_li = `, load_event_badge_template_obj_li); - } - ae_promises.load__event_obj.event_badge_template_obj_li = load_event_badge_template_obj_li; } return ae_promises.load__event_obj; } -// Updated 2025-05-22 +// Updated 2026-01-06 export async function load_ae_obj_li__event({ api_cfg, for_obj_type = 'account', for_obj_id, - qry_conference = true, - qry_str = null, - inc_device_li = false, - inc_file_li = false, - inc_location_li = false, - inc_presentation_li = false, - inc_presenter_li = false, - inc_session_li = false, + qry_conference = null, enabled = 'enabled', hidden = 'not_hidden', + view = 'default', limit = 99, offset = 0, - order_by_li = { start_datetime: 'DESC', name: 'ASC', updated_on: 'DESC', created_on: 'DESC' }, - params_json = null, - params = {}, + order_by_li = { start_datetime: 'DESC' }, try_cache = true, log_lvl = 0 }: { api_cfg: any; - for_obj_type: string; + for_obj_type?: string; for_obj_id: string; - qry_conference?: null | boolean; - qry_str?: null | string; - inc_device_li?: boolean; - inc_file_li?: boolean; - inc_location_li?: boolean; - inc_presentation_li?: boolean; - inc_presenter_li?: boolean; - inc_session_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + qry_conference?: boolean | null; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + view?: string; limit?: number; offset?: number; - order_by_li?: key_val; - params_json?: null | key_val; - params?: key_val; + order_by_li?: Record; try_cache?: boolean; log_lvl?: number; }) { - if (log_lvl) { - console.log( - `*** load_ae_obj_li__event() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id} qry_conference=${qry_conference}` - ); - } - - // There is probably a better way to handle this. I don't want to just start a new object if it is not passed. However, the qry_conference and qry_str are sort of a special case. -2024-10-01 - if (!params_json) { - params_json = {}; - } - - if (qry_conference) { - if (!params_json['and_qry']) { - params_json['and_qry'] = {}; - } - - params_json['and_qry']['conference'] = qry_conference; - } else if (qry_conference === false) { - if (!params_json['and_qry']) { - params_json['and_qry'] = {}; - } - - if (log_lvl) { - console.log('qry_conference is false!'); - } - params_json['and_qry']['conference'] = qry_conference; - } - - if (qry_str) { - if (!params_json['ft_qry']) { - params_json['ft_qry'] = {}; - } - - params_json['ft_qry'] = {}; - params_json['ft_qry']['default_qry_str'] = qry_str; - params_json['ft_qry']['location_address_json_ext'] = qry_str; - params_json['ft_qry']['contact_li_json_ext'] = qry_str; - } - - // console.log('params_json:', params_json); - - ae_promises.load__event_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, + let promise; + + if (qry_conference !== null) { + // V3 Search does not permit 'conference' field yet. + // We pass no search_query and filter locally in the .then() block below. + const search_query: any = { and: [] }; + + promise = api.search_ae_obj_v3({ + api_cfg, obj_type: 'event', - for_obj_type: for_obj_type, - for_obj_id: for_obj_id, - use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. - // use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value - enabled: enabled, - hidden: hidden, - order_by_li: order_by_li, - limit: limit, - offset: offset, - params_json: params_json, - params: params, - log_lvl: log_lvl - }) - .then(async function (event_obj_li_get_result) { - if (event_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_props({ - obj_li: event_obj_li_get_result, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - await db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'event', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - } - return event_obj_li_get_result; - } else { - return []; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + for_obj_type, + for_obj_id, + search_query, + enabled, + hidden, + view, + limit, + offset, + order_by_li, + log_lvl + }); + } else { + promise = api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'event', + for_obj_type, + for_obj_id, + enabled, + hidden, + view, + limit, + offset, + order_by_li, + log_lvl }); - - if (log_lvl) { - console.log('ae_promises.load__event_obj_li:', ae_promises.load__event_obj_li); } - if (inc_device_li) { - // Load the devices for the events - if (log_lvl) { - console.log(`Need to load the device list for each event now`); - } - for (let i = 0; i < ae_promises.load__event_obj_li.length; i++) { - const event_obj = ae_promises.load__event_obj_li[i]; - const event_id = event_obj.event_id_random; + ae_promises.load__event_obj_li = await promise.then(async function (event_obj_li_get_result) { + if (event_obj_li_get_result) { + let filtered_results = event_obj_li_get_result; - const load_event_device_obj_li = load_ae_obj_li__event_device({ - api_cfg: api_cfg, - for_obj_type: 'event', - for_obj_id: event_id, - params: { qry__enabled: 'enabled', qry__limit: 49 }, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_device_obj_li) => { - if (log_lvl) { - console.log(`event_device_obj_li = `, event_device_obj_li); - } - - return event_device_obj_li; - }); - - if (log_lvl) { - console.log(`load_event_device_obj_li = `, load_event_device_obj_li); + // Workaround: V3 Search does not yet support filtering on the 'conference' field. + // We filter locally for now to maintain frontend behavior. + if (qry_conference !== null) { + if (log_lvl) console.log(`Local filtering for conference=${qry_conference}`); + filtered_results = event_obj_li_get_result.filter((ev: any) => ev.conference === qry_conference); } - if (load_event_device_obj_li) { - ae_promises.load__event_obj_li[i].event_device_obj_li = load_event_device_obj_li; + if (try_cache) { + const processed_obj_li = await process_ae_obj__event_props({ + obj_li: filtered_results, + log_lvl: log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'event', + obj_li: processed_obj_li, + properties_to_save: properties_to_save, + log_lvl: log_lvl + }); } + return filtered_results; + } else { + return []; } - } - - if (inc_location_li) { - // Load the locations for the events - if (log_lvl) { - console.log(`Need to load the location list for each event now`); - } - for (let i = 0; i < ae_promises.load__event_obj_li.length; i++) { - const event_obj = ae_promises.load__event_obj_li[i]; - const event_id = event_obj.event_id_random; - - const load_event_location_obj_li = load_ae_obj_li__event_location({ - api_cfg: api_cfg, - for_obj_type: 'event', - for_obj_id: event_id, - enabled: 'enabled', - limit: 19, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_location_obj_li) => { - if (log_lvl) { - console.log(`event_location_obj_li = `, event_location_obj_li); - } - - return event_location_obj_li; - }); - - if (log_lvl) { - console.log(`load_event_location_obj_li = `, load_event_location_obj_li); - } - - if (load_event_location_obj_li) { - ae_promises.load__event_obj_li[i].event_location_obj_li = - load_event_location_obj_li; - } - } - } - - if (inc_session_li) { - // Load the sessions for the events - if (log_lvl) { - console.log(`Need to load the session list for each event now`); - } - for (let i = 0; i < ae_promises.load__event_obj_li.length; i++) { - const event_obj = ae_promises.load__event_obj_li[i]; - const event_id = event_obj.event_id_random; - - const load_event_session_obj_li = load_ae_obj_li__event_session({ - api_cfg: api_cfg, - for_obj_type: 'event', - for_obj_id: event_id, - enabled: enabled, - hidden: hidden, - limit: limit, - offset: offset, - order_by_li: order_by_li, - params: params, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_session_obj_li) => { - if (log_lvl) { - console.log(`event_session_obj_li = `, event_session_obj_li); - } - - return event_session_obj_li; - }); - - if (log_lvl) { - console.log(`load_event_session_obj_li = `, load_event_session_obj_li); - } - - if (load_event_session_obj_li) { - ae_promises.load__event_obj_li[i].event_session_obj_li = load_event_session_obj_li; - } - } - } + }); return ae_promises.load__event_obj_li; } -// The qry_ae_obj_li__event() is essentially a wrapper for the load_ae_obj_li__event() function. This should process the query strings and related before calling the load_ae_obj_li__event() function. -// Updated 2024-10-01 -export async function qry_ae_obj_li__event({ - api_cfg, - for_obj_type = 'account', - for_obj_id, - qry_conference = true, - qry_physical = null, - qry_virtual = null, - qry_type = null, - qry_str = null, - inc_file_li = false, - inc_location_li = false, - inc_presentation_li = false, - inc_presenter_li = false, - inc_session_li = false, - enabled = 'enabled', // all, disabled, enabled - hidden = 'not_hidden', // all, hidden, not_hidden - limit = 99, - offset = 0, - order_by_li = { start_datetime: 'DESC', name: 'ASC', updated_on: 'DESC', created_on: 'DESC' }, - params = {}, - try_cache = true, - log_lvl = 0 -}: { - api_cfg: any; - for_obj_type: string; - for_obj_id: string; - qry_conference?: null | boolean; - qry_physical?: null | boolean; - qry_virtual?: null | boolean; - qry_type?: null | string; - qry_str?: null | string; - inc_file_li?: boolean; - inc_location_li?: boolean; - inc_presentation_li?: boolean; - inc_presenter_li?: boolean; - inc_session_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; - limit?: number; - offset?: number; - order_by_li?: key_val; - params?: key_val; - try_cache?: boolean; - log_lvl?: number; -}) { - if (log_lvl) { - console.log( - `*** qry_ae_obj_li__event() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); - } - - // Build the params_json object. This needs to be documented better! -2024-10-01 - const params_json: key_val = {}; - - params_json['and_qry'] = {}; - - // This is handled in the actual load_ae_obj_li__event() function. For now...? - // if (qry_conference) { - // params_json['and_qry']['conference'] = qry_conference; - // } else if (qry_conference === false) { - // console.log('qry_conference is false!'); - // params_json['and_qry']['conference'] = qry_conference; - // } - - if (qry_physical && qry_virtual) { - // Ignore both if both are set to true. - } else if (qry_physical || qry_virtual) { - if (qry_physical) { - params_json['and_qry']['physical'] = qry_physical; - } - if (qry_virtual) { - params_json['and_qry']['virtual'] = qry_virtual; - } - } - - if (qry_type) { - params_json['and_qry']['type'] = qry_type; - } - - if (qry_str) { - params_json['ft_qry'] = {}; - params_json['ft_qry']['default_qry_str'] = qry_str; - params_json['ft_qry']['location_address_json_ext'] = qry_str; - params_json['ft_qry']['contact_li_json_ext'] = qry_str; - } - - if (log_lvl) { - console.log('params_json:', params_json); - } - - ae_promises.qry__event_obj_li = await load_ae_obj_li__event({ - api_cfg: api_cfg, - for_obj_type: for_obj_type, - for_obj_id: for_obj_id, - qry_conference: qry_conference, - qry_str: qry_str, - inc_file_li: inc_file_li, - inc_location_li: inc_location_li, - inc_presentation_li: inc_presentation_li, - inc_presenter_li: inc_presenter_li, - inc_session_li: inc_session_li, - enabled: enabled, - hidden: hidden, - limit: limit, - offset: offset, - order_by_li: order_by_li, - params_json: params_json, - params: params, - try_cache: try_cache, - log_lvl: log_lvl - }); - - return ae_promises.qry__event_obj_li; -} - -// Updated 2025-07-11 +// Updated 2026-01-06 export async function create_ae_obj__event({ api_cfg, account_id, @@ -587,129 +214,67 @@ export async function create_ae_obj__event({ try_cache?: boolean; log_lvl?: number; }) { - if (log_lvl) { - console.log(`*** create_ae_obj__event() *** account_id=${account_id}`); - } + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event', + fields: { + account_id_random: account_id, + ...data_kv + }, + params, + log_lvl + }); - if (!account_id) { - console.log(`ERROR: Events - Event - account_id required to create`); - return false; - } - - const cleaned_data_kv = Object.keys(data_kv) - .filter((key) => editable_fields.includes(key)) - .reduce((obj, key) => { - obj[key] = data_kv[key]; - return obj; - }, {}); - - ae_promises.create__event = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event', - fields: { - account_id_random: account_id, - ...cleaned_data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_props({ + obj_li: [result], log_lvl: log_lvl - }) - .then(async function (event_obj_create_result) { - if (event_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_props({ - obj_li: [event_obj_create_result], - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'event', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - } - return event_obj_create_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () {}); - - if (log_lvl) { - console.log('ae_promises.create__event:', ae_promises.create__event); + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'event', + obj_li: processed_obj_li, + properties_to_save: properties_to_save, + log_lvl: log_lvl + }); } - return ae_promises.create__event; + + return result; } -// Updated 2024-11-08 +// Updated 2026-01-06 export async function delete_ae_obj_id__event({ api_cfg, event_id, - method = 'delete', // 'delete', 'disable', 'hide' + method = 'delete', params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; - method?: string; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; params?: key_val; try_cache?: boolean; log_lvl?: number; }) { - if (log_lvl) { - console.log(`*** delete_ae_obj_id__event() *** event_id=${event_id}`); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event', + obj_id: event_id, + method, + params, + log_lvl + }); + + if (try_cache) { + await db_events.event.delete(event_id); } - ae_promises.delete__event_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event', - obj_id: event_id, - key: api_cfg.api_crud_super_key, - params: params, - method: method, - log_lvl: log_lvl - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () { - if (try_cache) { - if (log_lvl) { - console.log(`Attempting to remove IDB entry for event_id=${event_id}`); - } - db_events.event.delete(event_id); // Delete from the DB no matter what. - } - }); - - if (log_lvl) { - console.log('ae_promises.delete__event_obj:', ae_promises.delete__event_obj); - } - - return ae_promises.delete__event_obj; + return result; } -import { editable_fields } from './ae_events__event.editable_fields'; - -// Updated 2024-09-25 +// Updated 2026-01-06 export async function update_ae_obj__event({ api_cfg, event_id, @@ -725,349 +290,75 @@ export async function update_ae_obj__event({ try_cache?: boolean; log_lvl?: number; }) { - if (log_lvl) { - console.log(`*** update_ae_obj__event() *** event_id=${event_id}`, data_kv); - } + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event', + obj_id: event_id, + fields: data_kv, + params, + log_lvl + }); - const cleaned_data_kv = Object.keys(data_kv) - .filter((key) => editable_fields.includes(key)) - .reduce((obj, key) => { - obj[key] = data_kv[key]; - return obj; - }, {}); - - // Rename 'account_id' to 'account_id_random' if present - if (cleaned_data_kv.account_id !== undefined) { - cleaned_data_kv.account_id_random = cleaned_data_kv.account_id; - delete cleaned_data_kv.account_id; - } - - ae_promises.update__event_obj = await api - .update_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event', - obj_id: event_id, - fields: cleaned_data_kv, // <--- This is the payload being sent - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_props({ + obj_li: [result], log_lvl: log_lvl - }) - .then(async function (event_obj_update_result) { - if (event_obj_update_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_props({ - obj_li: [event_obj_update_result], - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('Processed object list:', processed_obj_li); - } - // Save the updated results list to the database - if (log_lvl) { - console.log('Saving to DB...'); - } - db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'event', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - } - return event_obj_update_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () {}); - - if (log_lvl) { - console.log('ae_promises.update__event_obj:', ae_promises.update__event_obj); + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'event', + obj_li: processed_obj_li, + properties_to_save: properties_to_save, + log_lvl: log_lvl + }); } - return ae_promises.update__event_obj; + + return result; } -// This function will loop through the event_obj_li and save each one to the DB. -// Updated 2025-05-09 -export async function db_save_ae_obj_li__event({ - obj_type, - obj_li, +// Updated 2026-01-06 +export async function qry_ae_obj_li__event({ + api_cfg, + for_obj_type = 'account', + for_obj_id, + qry_str, + enabled = 'enabled', + hidden = 'not_hidden', + view = 'default', + limit = 99, + offset = 0, + order_by_li = { start_datetime: 'DESC' }, log_lvl = 0 }: { - obj_type: string; - obj_li: any; + api_cfg: any; + for_obj_type?: string; + for_obj_id: string; + qry_str?: string; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + view?: string; + limit?: number; + offset?: number; + order_by_li?: Record; log_lvl?: number; }) { - if (log_lvl) { - console.log(`*** db_save_ae_obj_li__event() *** obj_type=${obj_type}`, obj_li); - } + const search_query: any = { and: [] }; + if (qry_str) search_query.q = qry_str; - if (obj_li && obj_li.length) { - const obj_li_id: string[] = []; - - for (const obj of obj_li) { - if (log_lvl) { - console.log(`Processing ae_obj ${obj_type}:`, obj); - } - - const obj_record = { - id: obj.event_id_random, - event_id: obj.event_id_random, - event_id_random: obj.event_id_random, - - code: obj.event_code, - - account_id: obj.account_id_random, - account_id_random: obj.account_id_random, - - conference: obj.conference, - type: obj.type, - name: obj.name, - summary: obj.summary, - description: obj.description, - - start_datetime: obj.start_datetime, - end_datetime: obj.end_datetime, - timezone: obj.timezone, - location_address_json: obj.location_address_json, - location_text: obj.location_text, - - attend_json: obj.attend_json, - attend_text: obj.attend_text, - - status: obj.status, // draft, active, inactive, archived, unknown; currently only used with IDAA - // review: obj.review, - // approve: obj.approve, - // ready: obj.ready, - // ready_on: obj.ready_on, - // archive: obj.archive, - // archive_on: obj.archive_on, - - mod_abstracts_json: obj.mod_abstracts_json, - mod_badges_json: obj.mod_badges_json, - mod_exhibits_json: obj.mod_exhibits_json, - mod_meetings_json: obj.mod_meetings_json, - mod_pres_mgmt_json: obj.mod_pres_mgmt_json, - cfg_json: obj.cfg_json, - - enable: obj.enable, - hide: obj.hide, - priority: obj.priority, - sort: obj.sort, - group: obj.group, - notes: obj.notes, - created_on: obj.created_on, - updated_on: obj.updated_on, - - // IDAA Recovery Meetings: - // Currently only really used for IDAA - contact_li_json: obj.contact_li_json, - external_person_id: obj.external_person_id, - - physical: obj.physical, - virtual: obj.virtual, - - recurring: obj.recurring, - recurring_pattern: obj.recurring_pattern, - recurring_start_time: obj.recurring_start_time, - recurring_end_time: obj.recurring_end_time, - recurring_text: obj.recurring_text, - - weekday_sunday: obj.weekday_sunday, - weekday_monday: obj.weekday_monday, - weekday_tuesday: obj.weekday_tuesday, - weekday_wednesday: obj.weekday_wednesday, - weekday_thursday: obj.weekday_thursday, - weekday_friday: obj.weekday_friday, - weekday_saturday: obj.weekday_saturday, - - attend_url: obj.attend_url, - attend_url_text: obj.attend_url_text, - attend_url_code: obj.attend_url_code, - attend_url_passcode: obj.attend_url_passcode, - attend_phone: obj.attend_phone, - attend_phone_passcode: obj.attend_phone_passcode, - - // From SQL view - file_count: obj.file_count, - file_count_all: obj.file_count_all, - internal_use_count: obj.internal_use_count, - event_file_id_li_json: obj.event_file_id_li_json - }; - - let id_random = null; - - try { - id_random = await db_events.event.update(obj_record.id, obj_record); - } catch (error) { - console.error(`Error: Failed to update ${obj_record.id}: ${error}`); - } - - if (!id_random) { - if (log_lvl) { - console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`); - } - try { - id_random = await db_events.event.put(obj_record); - } catch (error) { - console.error(`Error: Failed to put ${obj.event_id_random}: ${error}`); - } - } else { - if (log_lvl) { - console.log(`Updated record with ID: ${obj_record.id}`); - } - } - - if (!id_random) { - console.error(`Failed to save record with ID: ${obj_record.id}`); - } else { - if (log_lvl) { - console.log(`Saved record with ID: ${obj_record.id}`); - } - obj_li_id.push(obj_record.id); - } - } - return obj_li_id; - } -} - -// This function will process the event config, specifically for presentation management. -export function sync_config__event_pres_mgmt({ - pres_mgmt_cfg_remote, // This is the remote config that will be compared. - pres_mgmt_cfg_local, // This is the local config that will be updated. - log_lvl = 0 -}: { - pres_mgmt_cfg_remote: key_val; - pres_mgmt_cfg_local: key_val; - log_lvl?: number; -}) { - log_lvl = 1; - if (log_lvl) { - console.log( - `*** sync_config__event_pres_mgmt() *** pres_mgmt_cfg_remote:`, - pres_mgmt_cfg_remote - ); - } - - // Deal with things that can not be overridden first: - // Labels: - pres_mgmt_cfg_local.label__person_external_id = - pres_mgmt_cfg_remote?.label__person_external_id ?? 'External ID'; - pres_mgmt_cfg_local.label__presenter_external_id = - pres_mgmt_cfg_remote?.label__presenter_external_id ?? 'External ID'; - - pres_mgmt_cfg_local.label__session_poc_type = - pres_mgmt_cfg_remote?.label__session_poc_type ?? 'poc'; - pres_mgmt_cfg_local.label__session_poc_name = - pres_mgmt_cfg_remote?.label__session_poc_name_short ?? 'POC'; - pres_mgmt_cfg_local.label__session_poc_name = - pres_mgmt_cfg_remote?.label__session_poc_name ?? 'Point of Contact'; - - // Hide content: - - pres_mgmt_cfg_local.hide__session_poc = pres_mgmt_cfg_remote?.hide__session_poc ?? false; - - // pres_mgmt_cfg_local.hide__report_kv = pres_mgmt_cfg_remote?.hide__report_kv ?? null; - - // pres_mgmt_cfg_local.limit__navigation = pres_mgmt_cfg_remote?.limit__navigation ?? false; - // pres_mgmt_cfg_local.limit__options = pres_mgmt_cfg_remote?.limit__options ?? false; - - // Required fields or options (agreements): - pres_mgmt_cfg_local.require__presenter_agree = - pres_mgmt_cfg_remote?.require__presenter_agree ?? false; // In use - pres_mgmt_cfg_local.require__session_agree = - pres_mgmt_cfg_remote?.require__session_agree ?? false; // New and in progress - - // Show content: - // pres_mgmt_cfg_local.show__navigation = pres_mgmt_cfg_remote?.show__navigation ?? false; - - pres_mgmt_cfg_local.show__copy_access_link = - pres_mgmt_cfg_remote?.show__copy_access_link ?? false; - pres_mgmt_cfg_local.show__email_access_link = - pres_mgmt_cfg_remote?.show__email_access_link ?? false; - - pres_mgmt_cfg_local.file_purpose_option_kv = - pres_mgmt_cfg_remote?.file_purpose_option_kv ?? null; - - // Deal with things that can be overridden: - - // Locking the config is targeted at the trusted staff level and below. It is more or less ignored at the global manager and super levels. It may be enforced at the staff admin level? - // pres_mgmt_cfg_local.lock_config = pres_mgmt_cfg_remote?.lock_config ? true : false; // This disables the sync local config button and options. - if (pres_mgmt_cfg_local.lock_config) { - console.log(`The config should be locked! Forcing the sync!`); - // This is to forcibly sync the local config with the remote config. - pres_mgmt_cfg_local.sync_local_config = true; - } else { - // Do not override the preference for syncing the local config with the remote config. - console.log( - `The config is not locked. Currently set to sync? ${pres_mgmt_cfg_local.sync_local_config}` - ); - - // Check if the sync_local_config is undefined versus just false. - // if (pres_mgmt_cfg_local?.sync_local_config) { - // pres_mgmt_cfg_local.sync_local_config = true; - // } else { - // pres_mgmt_cfg_local.sync_local_config = pres_mgmt_cfg_remote?.sync_local_config ?? false; - // } - } - - if (pres_mgmt_cfg_local?.sync_local_config) { - if (log_lvl) { - console.log(`Syncing the local config with the remote config!!!`); - } - // Hide content: - pres_mgmt_cfg_local.hide__location_code = - pres_mgmt_cfg_remote?.hide__location_code ?? false; - - pres_mgmt_cfg_local.hide__presentation_code = - pres_mgmt_cfg_remote?.hide__presentation_code ?? false; - pres_mgmt_cfg_local.hide__presentation_datetime = - pres_mgmt_cfg_remote?.hide__presentation_datetime ?? false; - pres_mgmt_cfg_local.show_content__presentation_description = - pres_mgmt_cfg_remote?.show_content__presentation_description ?? false; - - pres_mgmt_cfg_local.hide__presenter_code = - pres_mgmt_cfg_remote?.hide__presenter_code ?? false; - pres_mgmt_cfg_local.hide__presenter_biography = - pres_mgmt_cfg_remote?.hide__presenter_biography ?? false; - - pres_mgmt_cfg_local.hide__session_code = pres_mgmt_cfg_remote?.hide__session_code ?? false; - pres_mgmt_cfg_local.hide__session_description = - pres_mgmt_cfg_remote?.hide__session_description ?? false; - pres_mgmt_cfg_local.hide__session_location = - pres_mgmt_cfg_remote?.hide__session_location ?? false; - pres_mgmt_cfg_local.hide__session_msg = pres_mgmt_cfg_remote?.hide__session_msg ?? false; - - // pres_mgmt_cfg_local.hide__session_li_poc_field = pres_mgmt_cfg_remote?.hide__session_li_poc_field ?? false; // This should still allow the POC name to be shown. - pres_mgmt_cfg_local.hide__session_poc_profile = - pres_mgmt_cfg_remote?.hide__session_poc_profile ?? false; // This should still allow the POC name to be shown. - pres_mgmt_cfg_local.hide__session_poc_biography = - pres_mgmt_cfg_remote?.hide__session_poc_biography ?? false; // New and in progress - pres_mgmt_cfg_local.hide__session_poc_profile_pic = - pres_mgmt_cfg_remote?.hide__session_poc_profile_pic ?? false; // New and in progress - - // pres_mgmt_cfg_local.show__copy_access_link = pres_mgmt_cfg_remote?.show__copy_access_link ?? false; - // pres_mgmt_cfg_local.show__email_access_link = pres_mgmt_cfg_remote?.show__email_access_link ?? false; - // pres_mgmt_cfg_local.show__launcher_link = pres_mgmt_cfg_remote?.show__launcher_link ?? false; - // pres_mgmt_cfg_local.show__launcher_link_legacy = pres_mgmt_cfg_remote?.show__launcher_link_legacy ?? false; - - pres_mgmt_cfg_local.hide_launcher_link = pres_mgmt_cfg_remote?.hide_launcher_link ?? false; - pres_mgmt_cfg_local.hide_launcher_link_legacy = - pres_mgmt_cfg_remote?.hide_launcher_link_legacy ?? false; - } - - if (log_lvl) { - console.log(`pres_mgmt_cfg_local:`, pres_mgmt_cfg_local); - } - return pres_mgmt_cfg_local; + return await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'event', + for_obj_type, + for_obj_id, + search_query, + enabled, + hidden, + view, + limit, + offset, + order_by_li, + log_lvl + }); } // Updated 2025-05-09 @@ -1075,43 +366,28 @@ export const properties_to_save = [ 'id', 'event_id', 'event_id_random', - 'code', - 'account_id', 'account_id_random', - 'conference', 'type', 'name', 'summary', 'description', - 'start_datetime', 'end_datetime', 'timezone', - 'location_address_json', 'location_text', - 'attend_json', 'attend_text', - - 'status', // draft, active, inactive, archived, unknown; currently only used with IDAA - // review - // approve - // ready - // ready_on - // archive - // archive_on - + 'status', 'mod_abstracts_json', 'mod_badges_json', 'mod_exhibits_json', 'mod_meetings_json', 'mod_pres_mgmt_json', 'cfg_json', - 'enable', 'hide', 'priority', @@ -1120,21 +396,15 @@ export const properties_to_save = [ 'notes', 'created_on', 'updated_on', - - // IDAA Recovery Meetings: - // Currently only really used for IDAA 'contact_li_json', 'external_person_id', - 'physical', 'virtual', - 'recurring', 'recurring_pattern', 'recurring_start_time', 'recurring_end_time', 'recurring_text', - 'weekday_sunday', 'weekday_monday', 'weekday_tuesday', @@ -1142,38 +412,20 @@ export const properties_to_save = [ 'weekday_thursday', 'weekday_friday', 'weekday_saturday', - 'attend_url', 'attend_url_text', 'attend_url_code', 'attend_url_passcode', 'attend_phone', 'attend_phone_passcode', - - // Generated fields for sorting locally only 'tmp_sort_1', 'tmp_sort_2', - // 'tmp_sort_a', - // 'tmp_sort_b', - - // From SQL view 'file_count', 'file_count_all', 'internal_use_count', 'event_file_id_li_json' - // 'event_session_count', - // 'event_presenter_count', - // 'event_file_count', - - // A key value list of the others - // 'event_other_kv', - // 'event_other_li', ]; -/** - * NON-EXPORTED LOCAL HELPER - * Processes a list of Aether objects by applying common and specific transformations. - */ async function _process_generic_props>({ obj_li, obj_type, @@ -1185,39 +437,24 @@ async function _process_generic_props>({ log_lvl?: number; specific_processor?: (obj: T) => Promise | T; }): Promise { - if (log_lvl > 0) { - console.log( - `*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***` - ); - } - - if (!obj_li || obj_li.length === 0) { - if (log_lvl > 0) console.log('No objects to process.'); - return []; - } + if (!obj_li || obj_li.length === 0) return []; const processed_obj_li: T[] = []; for (const original_obj of obj_li) { let processed_obj = { ...original_obj }; - // --- Common Transformations --- - - // 1. Standardize ID and other '_random' fields - // The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'. for (const key in processed_obj) { if (key.endsWith('_random')) { - const newKey = key.slice(0, -7); // Remove '_random' suffix - processed_obj[newKey] = processed_obj[key]; + const newKey = key.slice(0, -7); + (processed_obj as any)[newKey] = processed_obj[key]; } } - // Ensure 'id' is set from '[obj_type]_id_random' const randomIdKey = `${obj_type}_id_random`; if (processed_obj[randomIdKey]) { (processed_obj as any).id = processed_obj[randomIdKey]; } - // 2. Create common computed properties for client-side sorting. const group = processed_obj.group ?? '0'; const priority = processed_obj.priority ? 1 : 0; const sort = processed_obj.sort ?? '0'; @@ -1227,7 +464,6 @@ async function _process_generic_props>({ (processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; - // --- Specific Transformations --- if (specific_processor) { processed_obj = await Promise.resolve(specific_processor(processed_obj)); } @@ -1251,11 +487,10 @@ export async function process_ae_obj__event_props({ obj_type: 'event', log_lvl, specific_processor: (obj) => { - // Handle event-specific property aliases if (obj.event_code) { obj.code = obj.event_code; } return obj; } }); -} +} \ No newline at end of file diff --git a/src/routes/idaa/(idaa)/recovery_meetings/+layout.ts b/src/routes/idaa/(idaa)/recovery_meetings/+layout.ts index 5e71c8f5..29fa68e4 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/+layout.ts +++ b/src/routes/idaa/(idaa)/recovery_meetings/+layout.ts @@ -28,11 +28,11 @@ export async function load({ params, parent }) { if (browser) { const load_event_obj_li = events_func.load_ae_obj_li__event({ api_cfg: ae_acct.api, - for_obj_type: 'account', for_obj_id: account_id, - qry_conference: false, - hidden: 'not_hidden', // 'not_hidden' + qry_conference: false, // IDAA Recovery Meetings are not standard conferences enabled: 'enabled', + hidden: 'not_hidden', + limit: 199, order_by_li: { priority: 'DESC', sort: 'DESC', @@ -40,7 +40,6 @@ export async function load({ params, parent }) { created_on: 'DESC', name: 'ASC' }, - limit: 199, try_cache: true, log_lvl: log_lvl });