diff --git a/src/lib/ae_events/ae_events__event.ts b/src/lib/ae_events/ae_events__event.ts index cce3190b..810d81eb 100644 --- a/src/lib/ae_events/ae_events__event.ts +++ b/src/lib/ae_events/ae_events__event.ts @@ -103,7 +103,7 @@ export async function load_ae_obj_id__event({ * Shared logic for loading nested child collections */ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, inc_location_li, inc_session_li, inc_template_li, log_lvl }: any) { - const current_event_id = event_obj.event_id || event_obj.id; + const current_event_id = event_obj.event_id_random || event_obj.event_id || event_obj.id; if (inc_device_li) { event_obj.event_device_obj_li = await load_ae_obj_li__event_device({ diff --git a/src/lib/ae_events/ae_events__event_badge_template.ts b/src/lib/ae_events/ae_events__event_badge_template.ts index 82718e45..8ed63829 100644 --- a/src/lib/ae_events/ae_events__event_badge_template.ts +++ b/src/lib/ae_events/ae_events__event_badge_template.ts @@ -49,7 +49,6 @@ export const properties_to_save = [ /** * NON-EXPORTED LOCAL HELPER - * Processes a list of Aether objects by applying common and specific transformations. */ async function _process_generic_props>({ obj_li, @@ -99,7 +98,6 @@ async function _process_generic_props>({ return processed_obj_li; } -// --- PROCESS FUNCTION --- export async function process_ae_badge_template_props({ obj_li, log_lvl = 0 @@ -110,49 +108,36 @@ export async function process_ae_badge_template_props({ return _process_generic_props({ obj_li, obj_type: 'event_badge_template', - log_lvl, - specific_processor: (obj) => { - obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on ?? obj.created_on}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } + log_lvl }); } -// --- CRUD FUNCTIONS --- +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__event_badge_template({ api_cfg, event_badge_template_id, + view = 'default', try_cache = true, log_lvl = 0 }: { api_cfg: any; event_badge_template_id: string; + view?: string; try_cache?: boolean; log_lvl?: number; }) { if (log_lvl) { - console.log( - `*** load_ae_obj_id__event_badge_template() *** event_badge_template_id=${event_badge_template_id}` - ); + console.log(`*** load_ae_obj_id__event_badge_template() *** [V3] id=${event_badge_template_id}`); } try { - ae_promises.load__event_badge_template_obj = await api - .get_ae_obj_id_crud({ - api_cfg, - obj_type: 'event_badge_template', - obj_id: event_badge_template_id, - use_alt_table: false, - use_alt_base: false, - params: {}, - log_lvl - }); + ae_promises.load__event_badge_template_obj = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'event_badge_template', + obj_id: event_badge_template_id, + view, + log_lvl + }); if (ae_promises.load__event_badge_template_obj) { if (try_cache) { @@ -168,69 +153,58 @@ export async function load_ae_obj_id__event_badge_template({ log_lvl }); } - } else { - if (try_cache) { - ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id); - } + } else if (try_cache) { + ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id); } } catch (error: any) { if (try_cache) { ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id); - } else { - ae_promises.load__event_badge_template_obj = null; } } - return ae_promises.load__event_badge_template_obj; + return ae_promises.load__event_badge_template_obj || null; } +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__event_badge_template({ api_cfg, event_id, enabled = 'enabled', hidden = 'not_hidden', - limit = 49, + limit = 50, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; limit?: number; offset?: number; - order_by_li?: key_val; - params?: key_val; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }) { try { - ae_promises.load__event_badge_template_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg, - obj_type: 'event_badge_template', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: false, - use_alt_mdl: false, - enabled, - hidden, - order_by_li, - limit, - offset, - params_json: {}, - params, - log_lvl - }); + ae_promises.load__event_badge_template_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'event_badge_template', + for_obj_type: 'event', + for_obj_id: event_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl + }); if (ae_promises.load__event_badge_template_obj_li) { if (try_cache) { @@ -246,226 +220,190 @@ export async function load_ae_obj_li__event_badge_template({ log_lvl }); } - } else { - if (try_cache) { - ae_promises.load__event_badge_template_obj_li = await db_events.badge_template - .where('event_id').equals(event_id) - .toArray(); - } else { - ae_promises.load__event_badge_template_obj_li = []; - } + } else if (try_cache) { + ae_promises.load__event_badge_template_obj_li = await db_events.badge_template + .where('event_id').equals(event_id) + .toArray(); } } catch (error: any) { if (try_cache) { ae_promises.load__event_badge_template_obj_li = await db_events.badge_template .where('event_id').equals(event_id) .toArray(); - } else { - ae_promises.load__event_badge_template_obj_li = []; } } - return ae_promises.load__event_badge_template_obj_li; + return ae_promises.load__event_badge_template_obj_li || []; } +// Updated 2026-01-20 to V3 export async function create_ae_obj__event_badge_template({ api_cfg, event_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }) { - ae_promises.create__event_badge_template = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event_badge_template', - fields: { - event_id_random: event_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params, - return_obj: true, + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event_badge_template', + fields: { + event_id_random: event_id, + ...data_kv + }, + log_lvl + }); + + if (result && try_cache) { + const processed_obj_li = await process_ae_badge_template_props({ + obj_li: [result], log_lvl - }) - .then(async function (obj_create_result) { - if (obj_create_result && try_cache) { - const processed_obj_li = await process_ae_badge_template_props({ - obj_li: [obj_create_result], - log_lvl - }); - db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'badge_template', - obj_li: processed_obj_li, - properties_to_save, - log_lvl - }); - } - return obj_create_result; }); - return ae_promises.create__event_badge_template; + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'badge_template', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + return result; } +// Updated 2026-01-20 to V3 export async function delete_ae_obj_id__event_badge_template({ api_cfg, event_badge_template_id, method = 'delete', - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_badge_template_id: string; - method?: string; - params?: key_val; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; try_cache?: boolean; log_lvl?: number; }) { - ae_promises.delete__event_badge_template_obj = await api - .delete_ae_obj_id_crud({ - api_cfg, - obj_type: 'event_badge_template', - obj_id: event_badge_template_id, - key: api_cfg.api_crud_super_key, - params, - method, - log_lvl - }) - .finally(function () { - if (try_cache) { - db_events.badge_template.delete(event_badge_template_id); - } - }); - return ae_promises.delete__event_badge_template_obj; + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event_badge_template', + obj_id: event_badge_template_id, + method, + log_lvl + }); + + if (try_cache) { + await db_events.badge_template.delete(event_badge_template_id); + } + return result; } +// Updated 2026-01-20 to V3 export async function update_ae_obj__event_badge_template({ api_cfg, event_badge_template_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_badge_template_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }) { - ae_promises.update__event_badge_template_obj = await api - .update_ae_obj_id_crud({ - api_cfg, - obj_type: 'event_badge_template', - obj_id: event_badge_template_id, - fields: data_kv, - key: api_cfg.api_crud_super_key, - params, - return_obj: true, + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event_badge_template', + obj_id: event_badge_template_id, + fields: data_kv, + log_lvl + }); + + if (result && try_cache) { + const processed_obj_li = await process_ae_badge_template_props({ + obj_li: [result], log_lvl - }) - .then(async function (obj_update_result) { - if (obj_update_result && try_cache) { - const processed_obj_li = await process_ae_badge_template_props({ - obj_li: [obj_update_result], - log_lvl - }); - db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'badge_template', - obj_li: processed_obj_li, - properties_to_save, - log_lvl - }); - } - return obj_update_result; }); - return ae_promises.update__event_badge_template_obj; + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'badge_template', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + return result; } +// Updated 2026-01-20 to V3 export async function search__event_badge_template({ api_cfg, event_id, - fulltext_search_qry_str, - like_search_qry_str = null, + qry_str = '', enabled = 'enabled', hidden = 'not_hidden', limit = 25, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; - fulltext_search_qry_str?: null | string; - like_search_qry_str?: null | string; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + qry_str?: string; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; limit?: number; offset?: number; - order_by_li?: key_val; - params?: key_val; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }) { - const params_json: key_val = {}; - if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { - params_json['ft_qry'] = { default_qry_str: fulltext_search_qry_str }; - } - if (like_search_qry_str && like_search_qry_str.length > 2) { - params_json['and_like'] = { default_qry_str: like_search_qry_str }; - } - - ae_promises.load__event_badge_template_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg, - obj_type: 'event_badge_template', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: false, - use_alt_mdl: false, - enabled, - hidden, - order_by_li, - limit, - offset, - params_json, - params, + const search_query: any = { + q: qry_str, + and: [{ field: 'event_id_random', op: 'eq', value: event_id }] + }; + + if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true }); + else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false }); + + if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true }); + else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false }); + + const result_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'event_badge_template', + search_query, + order_by_li, + limit, + offset, + log_lvl + }); + + if (result_li && try_cache) { + const processed_obj_li = await process_ae_badge_template_props({ + obj_li: result_li, log_lvl - }) - .then(async function (obj_li_get_result) { - if (obj_li_get_result && try_cache) { - const processed_obj_li = await process_ae_badge_template_props({ - obj_li: obj_li_get_result, - log_lvl - }); - await db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'badge_template', - obj_li: processed_obj_li, - properties_to_save, - log_lvl - }); - } - return obj_li_get_result || []; }); - return ae_promises.load__event_badge_template_obj_li; + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'badge_template', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + return result_li || []; } \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__event_device.ts b/src/lib/ae_events/ae_events__event_device.ts index a5f6e658..75906662 100644 --- a/src/lib/ae_events/ae_events__event_device.ts +++ b/src/lib/ae_events/ae_events__event_device.ts @@ -9,7 +9,7 @@ import { load_ae_obj_id__event_location } from './ae_events__event_location'; const ae_promises: key_val = {}; -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__event_device({ api_cfg, event_device_id, @@ -24,22 +24,16 @@ export async function load_ae_obj_id__event_device({ log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** load_ae_obj_id__event_device() *** event_device_id=${event_device_id}`); + console.log(`*** load_ae_obj_id__event_device() *** [V3] id=${event_device_id}`); } - const params = {}; - try { - ae_promises.load__event_device_obj = await api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_device', - obj_id: event_device_id, // NOTE: This is the FQDN, not normally the 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, - log_lvl: log_lvl - }); + ae_promises.load__event_device_obj = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'event_device', + obj_id: event_device_id, + log_lvl + }); if (ae_promises.load__event_device_obj) { if (try_cache) { @@ -56,39 +50,27 @@ export async function load_ae_obj_id__event_device({ }); } } else { - console.log('No results returned from API.'); if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache...'); ae_promises.load__event_device_obj = await db_events.device.get(event_device_id); } } } catch (error: any) { - console.log('API request failed.', error); + console.log('V3 Request failed.', error); if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache after error...'); ae_promises.load__event_device_obj = await db_events.device.get(event_device_id); - } else { - ae_promises.load__event_device_obj = null; } } - if (log_lvl) { - console.log('ae_promises.load__event_device_obj:', ae_promises.load__event_device_obj); - } - - if (!ae_promises?.load__event_device_obj) { - return null; - } + if (!ae_promises.load__event_device_obj) return null; if (inc_location_id) { - // Load the location linked to this device const current_location_id = ae_promises.load__event_device_obj.event_location_id; if (current_location_id) { ae_promises.load__event_device_obj.event_location_obj = await load_ae_obj_id__event_location({ - api_cfg: api_cfg, + api_cfg, event_location_id: current_location_id, - try_cache: try_cache, - log_lvl: log_lvl + try_cache, + log_lvl }); } } @@ -96,514 +78,306 @@ export async function load_ae_obj_id__event_device({ return ae_promises.load__event_device_obj; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__event_device({ api_cfg, - for_obj_type, + for_obj_type = 'event', for_obj_id, inc_location_id = false, enabled = 'enabled', hidden = 'not_hidden', - limit = 49, + limit = 100, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - name: 'ASC', - code: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - for_obj_type: string; + for_obj_type?: string; for_obj_id: string; inc_location_id?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden - limit?: number; // 99 - offset?: number; // 0 - order_by_li?: Record | Record[]; - params?: key_val; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_li__event_device() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); + console.log(`*** load_ae_obj_li__event_device() *** [V3] for=${for_obj_type}:${for_obj_id}`); } - const params_json: key_val = {}; - try { - ae_promises.load__event_device_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_device', - for_obj_type: for_obj_type, - for_obj_id: for_obj_id, - use_alt_tbl: true, - 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 - }); + ae_promises.load__event_device_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'event_device', + for_obj_type, + for_obj_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl + }); if (ae_promises.load__event_device_obj_li) { if (try_cache) { const processed_obj_li = await process_ae_obj__event_device_props({ obj_li: ae_promises.load__event_device_obj_li, - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'device', obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl + properties_to_save, + log_lvl }); } - } else { - console.log('No results returned from API.'); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache...'); - ae_promises.load__event_device_obj_li = await db_events.device - .where('event_id').equals(for_obj_id) - .toArray(); - } else { - ae_promises.load__event_device_obj_li = []; - } - } - } catch (error: any) { - console.log('API request failed.', error); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache after error...'); + } else if (try_cache) { + ae_promises.load__event_device_obj_li = await db_events.device + .where('event_id').equals(for_obj_id) + .toArray(); + } + } catch (error: any) { + console.log('V3 List Request failed.', error); + if (try_cache) { ae_promises.load__event_device_obj_li = await db_events.device .where('event_id').equals(for_obj_id) .toArray(); - } else { - ae_promises.load__event_device_obj_li = []; } } if (inc_location_id && ae_promises.load__event_device_obj_li) { - for (let i = 0; i < ae_promises.load__event_device_obj_li.length; i++) { - const event_device_obj = ae_promises.load__event_device_obj_li[i]; - if (event_device_obj.event_location_id) { - event_device_obj.event_location_obj = await load_ae_obj_id__event_location({ - api_cfg: api_cfg, - event_location_id: event_device_obj.event_location_id, - try_cache: try_cache, - log_lvl: log_lvl + for (const device of ae_promises.load__event_device_obj_li) { + if (device.event_location_id) { + device.event_location_obj = await load_ae_obj_id__event_location({ + api_cfg, + event_location_id: device.event_location_id, + try_cache, + log_lvl }); } } } - return ae_promises.load__event_device_obj_li; + return ae_promises.load__event_device_obj_li || []; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function create_ae_obj__event_device({ api_cfg, event_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** create_ae_obj__event_device() *** event_id=${event_id}`); + console.log(`*** create_ae_obj__event_device() *** [V3] event_id=${event_id}`); } - ae_promises.create__event_device = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event_device', - fields: { - event_id_random: event_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_device_obj_create_result) { - if (event_device_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_device_props({ - obj_li: [event_device_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: 'device', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event_device', + fields: { + event_id_random: event_id, + ...data_kv + }, + log_lvl + }); - // db_save_ae_obj_li__event_device( - // { - // obj_type: 'event_device', - // obj_li: [event_device_obj_create_result] - // }); - } - return event_device_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_device:', ae_promises.create__event_device); + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_device_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'device', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.create__event_device; + + return result; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function delete_ae_obj_id__event_device({ api_cfg, event_device_id, - method = 'delete', // 'delete', 'disable', 'hide' - params = {}, + method = 'delete', try_cache = true, log_lvl = 0 }: { api_cfg: any; event_device_id: string; - method?: string; - params?: key_val; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; try_cache?: boolean; log_lvl?: number; }) { if (log_lvl) { - console.log(`*** delete_ae_obj_id__event_device() *** event_device_id=${event_device_id}`); + console.log(`*** delete_ae_obj_id__event_device() *** [V3] id=${event_device_id}`); } - ae_promises.delete__event_device_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_device', - obj_id: event_device_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_device_id=${event_device_id}` - ); - } - db_events.device.delete(event_device_id); - } - }); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event_device', + obj_id: event_device_id, + method, + log_lvl + }); - if (log_lvl) { - console.log('ae_promises.delete__event_device_obj:', ae_promises.delete__event_device_obj); + if (try_cache) { + await db_events.device.delete(event_device_id); } - return ae_promises.delete__event_device_obj; + return result; } -// Updated 2024-10-16 +// Updated 2026-01-20 to V3 export async function update_ae_obj__event_device({ api_cfg, event_device_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_device_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** update_ae_obj__event_device() *** event_device_id=${event_device_id}`, - data_kv - ); + console.log(`*** update_ae_obj__event_device() *** [V3] id=${event_device_id}`); } - ae_promises.update__event_device_obj = await api - .update_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_device', - obj_id: event_device_id, - fields: data_kv, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_device_obj_update_result) { - if (event_device_obj_update_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_device_props({ - obj_li: [event_device_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: 'device', - 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__event_device({ - // obj_type: 'event_device', obj_li: [event_device_obj_update_result] - // }); - } - return event_device_obj_update_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () {}); + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event_device', + obj_id: event_device_id, + fields: data_kv, + log_lvl + }); - if (log_lvl) { - console.log('ae_promises.update__event_device_obj:', ae_promises.update__event_device_obj); + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_device_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'device', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.update__event_device_obj; + + return result; } -// Not yet used or tested fully! -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function search__event_device({ api_cfg, event_id, - fulltext_search_qry_str, - ft_presenter_search_qry_str, - like_search_qry_str = null, - like_presentation_search_qry_str = null, - like_presenter_search_qry_str = null, - params = {}, + qry_str = '', + enabled = 'enabled', + hidden = 'not_hidden', + limit = 25, + offset = 0, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - event_id: any; - fulltext_search_qry_str?: null | string; - ft_presenter_search_qry_str?: null | string; - like_search_qry_str?: null | string; - like_presentation_search_qry_str?: null | string; - like_presenter_search_qry_str?: null | string; - params?: any; + event_id: string; + qry_str?: string; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; -}): Promise { +}): Promise { if (log_lvl) { - console.log(`*** search__event_device() *** event_id=${event_id}`); + console.log(`*** search__event_device() *** [V3] event_id=${event_id} qry=${qry_str}`); } - const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; - const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; - const limit: number = params.qry__limit ?? 25; // 99 - const offset: number = params.qry__offset ?? 0; // 0 + const search_query: any = { + q: qry_str, + and: [{ field: 'event_id_random', op: 'eq', value: event_id }] + }; - const params_json: key_val = {}; + // Logical filters + if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true }); + else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false }); - 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 (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true }); + else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false }); + + const result_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'event_device', + search_query, + order_by_li, + limit, + offset, + log_lvl + }); + + if (result_li && try_cache) { + const processed_obj_li = await process_ae_obj__event_device_props({ + obj_li: result_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'device', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - if (fulltext_search_qry_str || ft_presenter_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_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) { - params_json['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str; - } - } - - // Use the AND (AND LIKE) query - // if (like_search_qry_str || like_presenter_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_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) { - // params_json['and_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str; - // } - // } - - // Use the AND (OR LIKE) query - if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_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_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) { - params_json['or_like']['event_presentation_li_qry_str'] = - like_presentation_search_qry_str; - } - if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) { - params_json['or_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str; - } - } - - params_json['and_qry'] = {}; - - // if (device_type_code) { - // params_json['and_qry']['device_type_code'] = device_type_code; - // } - - const order_by_li = { - priority: 'DESC', - sort: 'DESC', - start_datetime: 'ASC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const; - - // ae_promises.load__event_device_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ - ae_promises.load__event_device_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_device', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: true, // NOTE: We want to use the alt table for device searching - // use_alt_mdl: 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 (event_device_obj_li_get_result) { - if (event_device_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_device_props({ - obj_li: event_device_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: 'device', - 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_device_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__event_device_obj_li:', - ae_promises.load__event_device_obj_li - ); - } - return ae_promises.load__event_device_obj_li; + return result_li || []; } -// Updated 2025-05-23 export const properties_to_save = [ 'id', 'event_device_id', - // 'event_device_id_random', - 'event_id', - // 'event_id_random', 'event_location_id', - // 'event_location_id_random', - 'code', 'name', 'description', - 'passcode', - 'local_file_cache_path', 'host_file_temp_path', 'recording_path', - 'record_audio', 'record_video', - 'trigger_open_file_id', 'trigger_open_session_id', 'trigger_recording_start', @@ -611,7 +385,6 @@ export const properties_to_save = [ 'trigger_reset', 'trigger_show_admin', 'trigger_show_hidden', - 'alert', 'alert_msg', 'alert_on', @@ -622,13 +395,10 @@ export const properties_to_save = [ 'record_status_msg', 'record_status_on', 'heartbeat', - 'info_hostname', 'info_ip_list', - 'meta_json', 'other_json', - 'enable', 'hide', 'priority', @@ -637,14 +407,8 @@ 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 'event_name', 'event_location_code', 'event_location_name' @@ -665,39 +429,26 @@ 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 + 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. + // 2. Create common computed properties const group = processed_obj.group ?? '0'; const priority = processed_obj.priority ? 1 : 0; const sort = processed_obj.sort ?? '0'; @@ -707,7 +458,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)); } @@ -718,7 +468,6 @@ async function _process_generic_props>({ return processed_obj_li; } -// Updated 2025-05-23 export async function process_ae_obj__event_device_props({ obj_li, log_lvl = 0 @@ -731,20 +480,10 @@ export async function process_ae_obj__event_device_props({ obj_type: 'event_device', log_lvl, specific_processor: (obj) => { - // Special handling for heartbeat timestamp if (obj.heartbeat) { obj.heartbeat = obj.heartbeat + 'Z'; } - - // Event device-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}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - return obj; } }); -} +} \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__event_file.ts b/src/lib/ae_events/ae_events__event_file.ts index 98828b6d..8e97ce3e 100644 --- a/src/lib/ae_events/ae_events__event_file.ts +++ b/src/lib/ae_events/ae_events__event_file.ts @@ -7,114 +7,92 @@ import type { ae_EventFile } from '$lib/types/ae_types'; const ae_promises: key_val = {}; -// Updated 2025-07-21 +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__event_file({ api_cfg, event_file_id, + view = 'default', try_cache = false, log_lvl = 0 }: { api_cfg: any; event_file_id: string; + view?: string; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** load_ae_obj_id__event_file() *** event_file_id=${event_file_id}`); + console.log(`*** load_ae_obj_id__event_file() *** [V3] id=${event_file_id}`); } - const params = {}; - - ae_promises.load__event_file_obj = await api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, + try { + ae_promises.load__event_file_obj = await api.get_ae_obj_v3({ + api_cfg, obj_type: 'event_file', - obj_id: event_file_id, // NOTE: This is the FQDN, not normally the ID. - use_alt_table: false, // 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 - params: params, - log_lvl: log_lvl - }) - .then(async function (event_file_obj_get_result) { - if (event_file_obj_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_file_props({ - obj_li: [event_file_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: 'file', - obj_li: processed_obj_li, - 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__event_file({obj_type: 'event_file', obj_li: [event_file_obj_get_result]}); - } - return event_file_obj_get_result; - } else { - console.log('No results returned.'); - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + obj_id: event_file_id, + view, + log_lvl }); - return ae_promises.load__event_file_obj; + if (ae_promises.load__event_file_obj) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__event_file_props({ + obj_li: [ae_promises.load__event_file_obj], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'file', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + } else if (try_cache) { + ae_promises.load__event_file_obj = await db_events.file.get(event_file_id); + } + } catch (error: any) { + console.log('V3 Request failed.', error); + if (try_cache) { + ae_promises.load__event_file_obj = await db_events.file.get(event_file_id); + } + } + + return ae_promises.load__event_file_obj || null; } -// Updated 2025-07-21 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__event_file({ api_cfg, for_obj_type, for_obj_id, enabled = 'enabled', hidden = 'not_hidden', - limit = 99, + limit = 100, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; for_obj_type: string; for_obj_id: string; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden - limit?: number; // 99 - offset?: number; // 0 - order_by_li?: key_val; - params?: key_val; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_li__event_file() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); + console.log(`*** load_ae_obj_li__event_file() *** [V3] for=${for_obj_type}:${for_obj_id}`); } - // Check if for_obj_type is in the list of valid Aether object types: const valid_for_obj_types = [ 'event', 'event_session', @@ -129,74 +107,55 @@ export async function load_ae_obj_li__event_file({ return []; } - const params_json: key_val = {}; - - // console.log('params_json:', params_json); - - ae_promises.load__event_file_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, + try { + ae_promises.load__event_file_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, obj_type: 'event_file', - 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 - 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 (event_file_obj_li_get_result) { - if (event_file_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_file_props({ - obj_li: event_file_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: 'file', - 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__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result}); - } - return event_file_obj_li_get_result; - } else { - console.log('No results returned.'); - return []; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + for_obj_type, + for_obj_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl }); - if (log_lvl) { - console.log('ae_promises.load__event_file_obj_li:', ae_promises.load__event_file_obj_li); + if (ae_promises.load__event_file_obj_li) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__event_file_props({ + obj_li: ae_promises.load__event_file_obj_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'file', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + } else if (try_cache) { + // Dexie fallback - search for parent ID across common link fields + ae_promises.load__event_file_obj_li = await db_events.file + .filter((f: any) => f.for_id === for_obj_id || f.event_id === for_obj_id) + .toArray(); + } + } catch (error: any) { + console.log('V3 List Request failed.', error); + if (try_cache) { + ae_promises.load__event_file_obj_li = await db_events.file + .filter((f: any) => f.for_id === for_obj_id || f.event_id === for_obj_id) + .toArray(); + } } - return ae_promises.load__event_file_obj_li; + + return ae_promises.load__event_file_obj_li || []; } -// Updated 2025-07-21 -// This may need to be reviewed again??? +/** + * Legacy wrapper maintained for specific creation logic (link from hosted_file) + */ export async function create_event_file_obj_from_hosted_file_async({ api_cfg, hosted_file_id, @@ -204,7 +163,6 @@ export async function create_event_file_obj_from_hosted_file_async({ data = {}, return_obj = false, inc_hosted_file = false, - return_meta = false, log_lvl = 0 }: { api_cfg: any; @@ -213,57 +171,28 @@ export async function create_event_file_obj_from_hosted_file_async({ data?: key_val; return_obj?: boolean; inc_hosted_file?: boolean; - return_meta?: boolean; log_lvl?: number; }) { - if (log_lvl) { - console.log( - `*** create_event_file_obj_from_hosted_file_async() *** hosted_file_id=${hosted_file_id}` - ); - } - - if (!hosted_file_id) { - console.log(`ERROR: Events Launcher - Event File - hosted_file_id required to create`); - return false; - } + if (!hosted_file_id) return false; const endpoint = `/event/file/from_hosted_file/${hosted_file_id}`; - if (return_obj) { - params['return_obj'] = true; - } - if (inc_hosted_file) { - params['inc_hosted_file'] = true; - } - const event_file_obj_post_promise = await api - .post_object({ - api_cfg: api_cfg, - endpoint: endpoint, - params: params, - data: data, - // return_obj: return_obj, - return_meta: return_meta, - log_lvl: log_lvl - }) - .then(function (result) { - console.log('POST DONE create_event_file_obj_from_hosted_file'); - console.log(result); - return result; - }) - .catch(function (error: any) { - console.log(error); - return false; // Returning false since something may have gone wrong. Also more in line with what the API returns. - // return error; - }); + const query_params = { ...params }; + if (return_obj) query_params['return_obj'] = true; + if (inc_hosted_file) query_params['inc_hosted_file'] = true; - // console.log(event_file_obj_post_promise); - if (return_obj) { - return event_file_obj_post_promise; - } else { - return event_file_obj_post_promise.event_file_id_random; - } + const result = await api.post_object({ + api_cfg, + endpoint, + params: query_params, + data, + log_lvl + }); + + if (return_obj) return result; + return result?.event_file_id_random; } -// Updated 2025-07-21 +// Updated 2026-01-20 to V3 export async function delete_ae_obj_id__event_file({ api_cfg, event_file_id, @@ -277,42 +206,23 @@ export async function delete_ae_obj_id__event_file({ try_cache?: boolean; log_lvl?: number; }) { - if (log_lvl) { - console.log(`*** delete_ae_obj_id__event_file() *** event_file_id=${event_file_id}`); + // V3 delete handles orphans via policy or explicit params + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event_file', + obj_id: event_file_id, + params: { ...params, delete_hosted_file: true, rm_orphan: true }, + log_lvl + }); + + if (try_cache) { + await db_events.file.delete(event_file_id); } - const endpoint = `/event/file/${event_file_id}/v2`; - - params['delete_hosted_file'] = true; // This does not actually delete the hosted file from the server. - params['rm_orphan'] = true; // This is what actually allows the hosted file to be deleted from the server. - - ae_promises.delete__event_file_obj = await api - .delete_object({ - api_cfg: api_cfg, - endpoint: endpoint, - params: params, - // return_meta: return_meta, - log_lvl: log_lvl - }) - .finally(function () { - if (try_cache) { - if (log_lvl) { - console.log( - `Attempting to remove IDB entry for event_file_id=${event_file_id}` - ); - } - db_events.file.delete(event_file_id); // Delete from the DB no matter what. - } - }); - - if (log_lvl) { - console.log('ae_promises.delete__event_file_obj:', ae_promises.delete__event_file_obj); - } - - return ae_promises.delete__event_file_obj; + return result; } -// Updated 2025-07-21 +// Updated 2026-01-20 to V3 export async function update_ae_obj__event_file({ api_cfg, event_file_id, @@ -328,401 +238,116 @@ export async function update_ae_obj__event_file({ try_cache?: boolean; log_lvl?: number; }): Promise { - if (log_lvl) { - console.log(`*** update_ae_obj__event_file() *** event_file_id=${event_file_id}`); - } - - // 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: 'event_file', - obj_id: event_file_id, // NOTE: This is the FQDN, not normally the ID. + obj_id: event_file_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__event_file_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_events, - table_name: 'file', - 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__event_file({ - // obj_type: 'event_file', - // obj_li: [result], - // log_lvl: log_lvl, - // }); - } - return result; - } else { - console.error('Failed to update event file.'); - return null; - } -} - -// This new function is using CRUD v2. This should allow for more flexibility in the queries. -// Updated 2025-07-21 -export async function qry__event_file({ - api_cfg, - event_id, - qry_created_on = null, // Example greater than: '2024-10-24' - qry_min_file_size = null, - qry_file_purpose = null, - enabled = 'enabled', - hidden = 'not_hidden', - limit = 49, - offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - created_on: 'DESC', - updated_on: 'DESC', - filename: 'ASC', - extension: 'ASC', - hosted_file_size: 'ASC' - } as const, - params = {}, - try_cache = true, - log_lvl = 0 -}: { - api_cfg: any; - event_id: any; - qry_created_on?: null | string; - qry_min_file_size?: null | number; - qry_file_purpose?: null | string; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; - limit?: number; - offset?: number; - order_by_li?: key_val; - params?: any; - try_cache?: boolean; - log_lvl?: number; -}): Promise { - if (log_lvl) { - console.log(`*** qry__event_file() *** event_id=${event_id}`); - } - - const params_json: key_val = {}; - - params_json['qry'] = []; - - if (qry_created_on) { - const qry_param = { - type: 'AND', - field: 'created_on', - operator: '>', - value: qry_created_on - }; - params_json['qry'].push(qry_param); - } - - if (qry_min_file_size) { - // console.log('qry_min_file_size:', qry_min_file_size); - const qry_param = { - type: 'AND', - field: 'hosted_file_size', - operator: '>', - value: qry_min_file_size - }; - params_json['qry'].push(qry_param); - } - - if (qry_file_purpose) { - const qry_param = { - type: 'AND', - field: 'file_purpose', - operator: '=', - value: qry_file_purpose - }; - params_json['qry'].push(qry_param); - } - - // if (!limit || limit <= 0) { - // limit = null; - // } - - if (log_lvl) { - console.log('params_json:', params_json); - } - - ae_promises.load__event_file_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_file', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: true, // NOTE: We want to use the alt table for file 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(function (event_file_obj_li_get_result) { - if (event_file_obj_li_get_result) { - if (try_cache) { - // Process the results first - process_ae_obj__event_file_props({ - obj_li: event_file_obj_li_get_result, - log_lvl: log_lvl - }).then(async function (processed_obj_li) { - 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: 'file', - 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__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result}); - return event_file_obj_li_get_result; - } else { - return []; - } + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_file_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'file', + obj_li: processed_obj_li, + properties_to_save, + log_lvl }); - - if (log_lvl) { - console.log('ae_promises.load__event_file_obj_li:', ae_promises.load__event_file_obj_li); } - return ae_promises.load__event_file_obj_li; + + return result; } -// Updated 2025-07-21 +// Updated 2026-01-20 to V3 export async function search__event_file({ api_cfg, event_id, - created_on = null, + qry_str = '', min_file_size = null, - fulltext_search_qry_str, - ft_file_search_qry_str, - like_search_qry_str = null, - like_presentation_search_qry_str = null, - like_file_search_qry_str = null, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - created_on: 'DESC', - updated_on: 'DESC', - filename: 'ASC', - extension: 'ASC', - hosted_file_size: 'ASC' - } as const, - params = {}, + enabled = 'enabled', + hidden = 'not_hidden', + limit = 25, + offset = 0, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - event_id: any; - created_on?: null | string; + event_id: string; + qry_str?: string; min_file_size?: null | number; - fulltext_search_qry_str?: null | string; - ft_file_search_qry_str?: null | string; - like_search_qry_str?: null | string; - like_presentation_search_qry_str?: null | string; - like_file_search_qry_str?: null | string; - order_by_li?: Record | Record[]; - params?: any; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { - if (log_lvl) { - console.log(`*** search__event_file() *** event_id=${event_id}`); - } - - const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; - const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; - const limit: number = params.qry__limit ?? 25; // 99 - const offset: number = params.qry__offset ?? 0; // 0 - - const 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_file_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_file_search_qry_str && ft_file_search_qry_str.length > 2) { - params_json['ft_qry']['event_file_li_qry_str'] = ft_file_search_qry_str; - } - } - - // Use the AND (AND LIKE) query - // if (like_search_qry_str || like_file_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_file_search_qry_str && like_file_search_qry_str.length > 2) { - // params_json['and_like']['event_file_li_qry_str'] = like_file_search_qry_str; - // } - // } - - // Use the AND (OR LIKE) query - // if (like_search_qry_str || like_presentation_search_qry_str || like_file_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_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) { - // params_json['or_like']['event_presentation_li_qry_str'] = like_presentation_search_qry_str; - // } - // if (like_file_search_qry_str && like_file_search_qry_str.length > 2) { - // params_json['or_like']['event_file_li_qry_str'] = like_file_search_qry_str; - // } - // } - - // params_json['and_qry'] = {}; - - // if (created_on) { - // params_json['and_qry']['created_on'] = created_on; - // } + const search_query: any = { + q: qry_str, + and: [{ field: 'event_id_random', op: 'eq', value: event_id }] + }; if (min_file_size) { - params_json['and_qry'] = { hosted_file_size: { '>': min_file_size } }; + search_query.and.push({ field: 'hosted_file_size', op: 'gt', value: min_file_size }); } - ae_promises.load__event_file_obj_li = await api - .get_ae_obj_li_for_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_file', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_table: true, // NOTE: We want to use the alt table for file 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(async function (event_file_obj_li_get_result) { - if (event_file_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_file_props({ - obj_li: event_file_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: 'file', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } + const result_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'event_file', + search_query, + order_by_li, + limit, + offset, + log_lvl + }); - // db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result}); - } - return event_file_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__event_file_obj_li:', ae_promises.load__event_file_obj_li); + if (result_li && try_cache) { + const processed_obj_li = await process_ae_obj__event_file_props({ + obj_li: result_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'file', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.load__event_file_obj_li; + + return result_li || []; } -// Updated 2025-05-23 export const properties_to_save = [ 'id', - // 'id_random', 'event_file_id', - // 'event_file_id_random', - 'hosted_file_id', - // 'hosted_file_id_random', 'hash_sha256', - 'for_type', 'for_id', - // 'for_id_random', - 'event_id', - // 'event_id_random', 'event_session_id', - // 'event_session_id_random', 'event_presentation_id', - // 'event_presentation_id_random', 'event_presenter_id', - // 'event_presenter_id_random', 'event_location_id', - // 'event_location_id_random', - 'filename', 'extension', - 'open_in_os', - 'lu_file_purpose_id', 'lu_event_file_purpose_name', 'file_purpose', - 'enable', 'hide', 'priority', @@ -731,19 +356,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', - 'filename_no_ext', 'filename_w_ext', 'hosted_file_content_type', 'file_size', 'hosted_file_size', - 'event_location_code', 'event_location_name', 'event_session_code', @@ -764,7 +383,6 @@ export const properties_to_save = [ /** * NON-EXPORTED LOCAL HELPER - * Processes a list of Aether objects by applying common and specific transformations. */ async function _process_generic_props>({ obj_li, @@ -777,39 +395,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 + 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'; @@ -819,7 +422,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)); } @@ -830,7 +432,6 @@ async function _process_generic_props>({ return processed_obj_li; } -// Updated 2025-05-23 export async function process_ae_obj__event_file_props({ obj_li, log_lvl = 0 @@ -841,17 +442,6 @@ export async function process_ae_obj__event_file_props({ return _process_generic_props({ obj_li, obj_type: 'event_file', - log_lvl, - specific_processor: (obj) => { - // Event file-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}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } + log_lvl }); -} +} \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__event_location.ts b/src/lib/ae_events/ae_events__event_location.ts index 2ebdc98d..3e788c2d 100644 --- a/src/lib/ae_events/ae_events__event_location.ts +++ b/src/lib/ae_events/ae_events__event_location.ts @@ -11,13 +11,14 @@ import { load_ae_obj_li__event_session } from './ae_events__event_session'; const ae_promises: key_val = {}; -// Updated 2026-01-16 +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__event_location({ api_cfg, event_location_id, inc_device_li = false, inc_file_li = false, inc_session_li = false, + view = 'default', try_cache = true, log_lvl = 0 }: { @@ -26,38 +27,34 @@ export async function load_ae_obj_id__event_location({ inc_device_li?: boolean; inc_file_li?: boolean; inc_session_li?: boolean; + view?: string; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_id__event_location() *** event_location_id=${event_location_id}` - ); + console.log(`*** load_ae_obj_id__event_location() *** [V3] id=${event_location_id}`); } - const params = {}; - // Check if offline if (typeof navigator !== 'undefined' && !navigator.onLine) { if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.'); ae_promises.load__event_location_obj = await db_events.location.get(event_location_id); if (ae_promises.load__event_location_obj) { - return await _handle_nested_loads(ae_promises.load__event_location_obj, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }); + return await _handle_nested_loads(ae_promises.load__event_location_obj, { + api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl + }); } return null; } try { - ae_promises.load__event_location_obj = await api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_location', - obj_id: event_location_id, // NOTE: This is the FQDN, not normally the 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, - log_lvl: log_lvl - }); + ae_promises.load__event_location_obj = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'event_location', + obj_id: event_location_id, + view, + log_lvl + }); if (ae_promises.load__event_location_obj) { if (try_cache) { @@ -73,121 +70,104 @@ export async function load_ae_obj_id__event_location({ log_lvl }); } - } else { - console.log('No results returned from API.'); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache...'); - ae_promises.load__event_location_obj = await db_events.location.get(event_location_id); - } + } else if (try_cache) { + ae_promises.load__event_location_obj = await db_events.location.get(event_location_id); } } catch (error: any) { - console.log('API request failed.', error); + console.log('V3 Request failed.', error); if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache after error...'); ae_promises.load__event_location_obj = await db_events.location.get(event_location_id); - } else { - ae_promises.load__event_location_obj = null; } } - if (!ae_promises?.load__event_location_obj) { - return null; - } + if (!ae_promises.load__event_location_obj) return null; - return await _handle_nested_loads(ae_promises.load__event_location_obj, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }); + return await _handle_nested_loads(ae_promises.load__event_location_obj, { + api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl + }); } /** * Helper to handle nested collection loads for a location */ async function _handle_nested_loads(location_obj: any, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }: any) { - const current_location_id = location_obj.event_location_id || location_obj.id; + const current_location_id = location_obj.event_location_id_random || location_obj.event_location_id || location_obj.id; if (inc_device_li) { location_obj.event_device_obj_li = await load_ae_obj_li__event_device({ - api_cfg: api_cfg, + api_cfg, for_obj_type: 'event_location', for_obj_id: current_location_id, - log_lvl: log_lvl + log_lvl }); } if (inc_file_li) { - // Load the files for the location location_obj.event_file_li = await load_ae_obj_li__event_file({ - api_cfg: api_cfg, + api_cfg, for_obj_type: 'event_location', for_obj_id: current_location_id, enabled: 'all', limit: 15, - try_cache: try_cache, - log_lvl: log_lvl + try_cache, + log_lvl }); } if (inc_session_li) { - // Load the sessions for the location location_obj.event_session_li = await load_ae_obj_li__event_session({ - api_cfg: api_cfg, + api_cfg, for_obj_type: 'event_location', for_obj_id: current_location_id, enabled: 'all', limit: 15, - try_cache: try_cache, - log_lvl: log_lvl + try_cache, + log_lvl }); } return location_obj; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__event_location({ api_cfg, - for_obj_type, + for_obj_type = 'event', for_obj_id, inc_device_li = false, inc_file_li = false, inc_session_li = false, enabled = 'enabled', hidden = 'not_hidden', - limit = 29, + limit = 50, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - name: 'ASC', - code: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - }, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - for_obj_type: string; + for_obj_type?: string; for_obj_id: string; inc_device_li?: boolean; inc_file_li?: boolean; inc_session_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden - limit?: number; // 99 - offset?: number; // 0 - order_by_li?: Record | Record[]; - params?: key_val; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_li__event_location() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); + console.log(`*** load_ae_obj_li__event_location() *** [V3] for=${for_obj_type}:${for_obj_id}`); } - const params_json: key_val = {}; - // Check if offline if (typeof navigator !== 'undefined' && !navigator.onLine) { if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.'); @@ -195,388 +175,256 @@ export async function load_ae_obj_li__event_location({ .where('event_id').equals(for_obj_id) .toArray(); if (ae_promises.load__event_location_obj_li) { - for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) { - await _handle_nested_loads(ae_promises.load__event_location_obj_li[i], { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }); + for (const loc of ae_promises.load__event_location_obj_li) { + await _handle_nested_loads(loc, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }); } } return ae_promises.load__event_location_obj_li || []; } try { - ae_promises.load__event_location_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_location', - 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. - enabled: enabled, - hidden: hidden, - order_by_li: order_by_li, - limit: limit, - offset: offset, - params_json: params_json, - params: params, - log_lvl: log_lvl - }); + ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'event_location', + for_obj_type, + for_obj_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl + }); if (ae_promises.load__event_location_obj_li) { if (try_cache) { const processed_obj_li = await process_ae_obj__event_location_props({ obj_li: ae_promises.load__event_location_obj_li, - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'location', obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl + properties_to_save, + log_lvl }); } - } else { - console.log('No results returned from API.'); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache...'); - ae_promises.load__event_location_obj_li = await db_events.location - .where('event_id').equals(for_obj_id) - .toArray(); - } else { - ae_promises.load__event_location_obj_li = []; - } - } - } catch (error: any) { - console.log('API request failed.', error); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache after error...'); + } else if (try_cache) { + ae_promises.load__event_location_obj_li = await db_events.location + .where('event_id').equals(for_obj_id) + .toArray(); + } + } catch (error: any) { + console.log('V3 List Request failed.', error); + if (try_cache) { ae_promises.load__event_location_obj_li = await db_events.location .where('event_id').equals(for_obj_id) .toArray(); - } else { - ae_promises.load__event_location_obj_li = []; } } if (ae_promises.load__event_location_obj_li) { - for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) { - await _handle_nested_loads(ae_promises.load__event_location_obj_li[i], { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }); + for (const loc of ae_promises.load__event_location_obj_li) { + await _handle_nested_loads(loc, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }); } } - return ae_promises.load__event_location_obj_li; + return ae_promises.load__event_location_obj_li || []; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function create_ae_obj__event_location({ api_cfg, event_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** create_ae_obj__event_location() *** event_id=${event_id}`); + console.log(`*** create_ae_obj__event_location() *** [V3] event_id=${event_id}`); } - ae_promises.create__event_location = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event_location', - fields: { - event_id_random: event_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_location_obj_create_result) { - if (event_location_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_location_props({ - obj_li: [event_location_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: 'location', - 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_location_obj_create_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }); + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event_location', + fields: { + event_id_random: event_id, + ...data_kv + }, + log_lvl + }); - return ae_promises.create__event_location; + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_location_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'location', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + + return result; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function delete_ae_obj_id__event_location({ api_cfg, event_location_id, - method = 'delete', // 'delete', 'disable', 'hide' - params = {}, + method = 'delete', try_cache = true, log_lvl = 0 }: { api_cfg: any; event_location_id: string; - method?: string; - params?: key_val; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; try_cache?: boolean; log_lvl?: number; }) { if (log_lvl) { - console.log( - `*** delete_ae_obj_id__event_location() *** event_location_id=${event_location_id}` - ); + console.log(`*** delete_ae_obj_id__event_location() *** [V3] id=${event_location_id}`); } - ae_promises.delete__event_location_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_location', - obj_id: event_location_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_location_id=${event_location_id}` - ); - } - db_events.location.delete(event_location_id); - } - }); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event_location', + obj_id: event_location_id, + method, + log_lvl + }); - return ae_promises.delete__event_location_obj; + if (try_cache) { + await db_events.location.delete(event_location_id); + } + + return result; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function update_ae_obj__event_location({ api_cfg, event_location_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_location_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** update_ae_obj__event_location() *** event_location_id=${event_location_id}`, - data_kv - ); + console.log(`*** update_ae_obj__event_location() *** [V3] id=${event_location_id}`); } - ae_promises.update__event_location_obj = await api - .update_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_location', - obj_id: event_location_id, - fields: data_kv, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_location_obj_update_result) { - if (event_location_obj_update_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_location_props({ - obj_li: [event_location_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: 'location', - 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_location_obj_update_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }); - return ae_promises.update__event_location_obj; + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event_location', + obj_id: event_location_id, + fields: data_kv, + log_lvl + }); + + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_location_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'location', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + + return result; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function search__event_location({ api_cfg, event_id, - fulltext_search_qry_str, - ft_presenter_search_qry_str, - like_search_qry_str = null, - like_presentation_search_qry_str = null, - like_presenter_search_qry_str = null, - params = {}, + qry_str = '', + enabled = 'enabled', + hidden = 'not_hidden', + limit = 25, + offset = 0, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - event_id: any; - fulltext_search_qry_str?: null | string; - ft_presenter_search_qry_str?: null | string; - like_search_qry_str?: null | string; - like_presentation_search_qry_str?: null | string; - like_presenter_search_qry_str?: null | string; - params?: any; + event_id: string; + qry_str?: string; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; -}): Promise { +}): Promise { if (log_lvl) { - console.log(`*** search__event_location() *** event_id=${event_id}`); + console.log(`*** search__event_location() *** [V3] event_id=${event_id} qry=${qry_str}`); } - const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; - const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; - const limit: number = params.qry__limit ?? 25; - const offset: number = params.qry__offset ?? 0; + const search_query: any = { + q: qry_str, + and: [{ field: 'event_id_random', op: 'eq', value: event_id }] + }; - const params_json: key_val = {}; + if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true }); + else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false }); - if (!fulltext_search_qry_str && !like_search_qry_str) { - console.log('No search string provided!!!'); - return false; - } + if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true }); + else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false }); - if (fulltext_search_qry_str || ft_presenter_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; - } + const result_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'event_location', + search_query, + order_by_li, + limit, + offset, + log_lvl + }); - if (ft_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) { - params_json['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str; - } - } - - if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_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_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) { - params_json['or_like']['event_presentation_li_qry_str'] = - like_presentation_search_qry_str; - } - if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) { - params_json['or_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str; - } - } - - params_json['and_qry'] = {}; - - const order_by_li = { - priority: 'DESC', - sort: 'DESC', - start_datetime: 'ASC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const; - - ae_promises.load__event_location_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_location', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: true, - 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_location_obj_li_get_result) { - if (event_location_obj_li_get_result) { - if (try_cache) { - const processed_obj_li = await process_ae_obj__event_location_props({ - obj_li: event_location_obj_li_get_result, - log_lvl: log_lvl - }); - await db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'location', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - } - return event_location_obj_li_get_result; - } else { - return []; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + if (result_li && try_cache) { + const processed_obj_li = await process_ae_obj__event_location_props({ + obj_li: result_li, + log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'location', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } - return ae_promises.load__event_location_obj_li; + return result_li || []; } -// Updated 2025-05-23 export const properties_to_save = [ 'id', 'event_location_id', @@ -656,7 +504,6 @@ async function _process_generic_props>({ return processed_obj_li; } -// Updated 2025-05-23 export async function process_ae_obj__event_location_props({ obj_li, log_lvl = 0 @@ -667,16 +514,6 @@ export async function process_ae_obj__event_location_props({ return _process_generic_props({ obj_li, obj_type: 'event_location', - log_lvl, - specific_processor: (obj) => { - obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on ?? obj.created_on}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } + log_lvl }); } \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__event_presentation.ts b/src/lib/ae_events/ae_events__event_presentation.ts index c99f9c4f..3adfc262 100644 --- a/src/lib/ae_events/ae_events__event_presentation.ts +++ b/src/lib/ae_events/ae_events__event_presentation.ts @@ -10,7 +10,7 @@ import { load_ae_obj_li__event_presenter } from '$lib/ae_events/ae_events__event const ae_promises: key_val = {}; -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__event_presentation({ api_cfg, event_presentation_id, @@ -18,7 +18,8 @@ export async function load_ae_obj_id__event_presentation({ inc_presenter_li = false, enabled = 'enabled', hidden = 'not_hidden', - limit = 49, + view = 'default', + limit = 100, offset = 0, try_cache = true, log_lvl = 0 @@ -27,147 +28,95 @@ export async function load_ae_obj_id__event_presentation({ event_presentation_id: string; inc_file_li?: boolean; inc_presenter_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + view?: string; limit?: number; offset?: number; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}` - ); + console.log(`*** load_ae_obj_id__event_presentation() *** [V3] id=${event_presentation_id}`); } - const params = {}; - - ae_promises.load__event_presentation_obj = await api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, + try { + ae_promises.load__event_presentation_obj = await api.get_ae_obj_v3({ + api_cfg, obj_type: 'event_presentation', - obj_id: event_presentation_id, // NOTE: This is the FQDN, not normally the ID. - use_alt_table: false, // 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 - params: params, - log_lvl: log_lvl - }) - .then(async function (event_presentation_obj_get_result) { - if (event_presentation_obj_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presentation_props({ - obj_li: [event_presentation_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: 'presentation', - obj_li: processed_obj_li, - 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__event_presentation({ - // obj_type: 'event_presentation', - // obj_li: [event_presentation_obj_get_result] - - // }); - } - return event_presentation_obj_get_result; - } else { - console.log('No results returned.'); - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + obj_id: event_presentation_id, + view, + log_lvl }); - if (log_lvl) { - console.log( - 'ae_promises.load__event_presentation_obj:', - ae_promises.load__event_presentation_obj - ); + if (ae_promises.load__event_presentation_obj) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__event_presentation_props({ + obj_li: [ae_promises.load__event_presentation_obj], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presentation', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + } else if (try_cache) { + ae_promises.load__event_presentation_obj = await db_events.presentation.get(event_presentation_id); + } + } catch (error: any) { + console.log('V3 Request failed.', error); + if (try_cache) { + ae_promises.load__event_presentation_obj = await db_events.presentation.get(event_presentation_id); + } } - if (ae_promises?.load__event_presentation_obj === null) { - console.log('No results returned.'); - return null; - } + if (!ae_promises.load__event_presentation_obj) return null; + + return await _handle_nested_loads(ae_promises.load__event_presentation_obj, { + api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl + }); +} + +/** + * Helper to handle nested collection loads for a presentation + */ +async function _handle_nested_loads(presentation_obj: any, { api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }: any) { + const current_presentation_id = presentation_obj.event_presentation_id_random || presentation_obj.event_presentation_id || presentation_obj.id; if (inc_file_li) { - // Load the files for the presentation - if (log_lvl) { - console.log(`Need to load the file list for the presentation now.`); - } - const load_event_file_obj_li = load_ae_obj_li__event_file({ - api_cfg: api_cfg, + presentation_obj.event_file_li = await load_ae_obj_li__event_file({ + api_cfg, for_obj_type: 'event_presentation', - for_obj_id: event_presentation_id, - enabled: 'all', + for_obj_id: current_presentation_id, + enabled, limit: 25, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_file_obj_li) => { - if (log_lvl) { - console.log(`event_file_obj_li = `, event_file_obj_li); - } - return event_file_obj_li; + try_cache, + log_lvl }); - - if (log_lvl) { - console.log(`event_file_obj_li = `, load_event_file_obj_li); - } - ae_promises.load__event_presentation_obj.event_file_li = load_event_file_obj_li; } if (inc_presenter_li) { - // Load the presenters for the presentation - if (log_lvl) { - console.log(`Need to load the presenter list for the presentation now.`); - } - const load_event_presenter_obj_li = load_ae_obj_li__event_presenter({ - api_cfg: api_cfg, + presentation_obj.event_presenter_li = await load_ae_obj_li__event_presenter({ + api_cfg, for_obj_type: 'event_presentation', - for_obj_id: event_presentation_id, - inc_file_li: inc_file_li, - enabled: enabled, - hidden: hidden, - limit: limit, - offset: offset, - // order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'}, - // params: params, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_presenter_obj_li) => { - if (log_lvl) { - console.log(`event_presenter_obj_li = `, event_presenter_obj_li); - } - return event_presenter_obj_li; + for_obj_id: current_presentation_id, + inc_file_li, + enabled, + hidden, + limit, + offset, + try_cache, + log_lvl }); - - if (log_lvl) { - console.log(`event_presenter_obj_li = `, load_event_presenter_obj_li); - } - ae_promises.load__event_presentation_obj.event_presenter_li = load_event_presenter_obj_li; } - return ae_promises.load__event_presentation_obj; + return presentation_obj; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__event_presentation({ api_cfg, for_obj_type = 'event_session', @@ -176,190 +125,94 @@ export async function load_ae_obj_li__event_presentation({ inc_presenter_li = false, enabled = 'enabled', hidden = 'not_hidden', - limit = 49, + limit = 50, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - start_datetime: 'ASC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { start_datetime: 'ASC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - for_obj_type: string; + for_obj_type?: string; for_obj_id: string; inc_file_li?: boolean; inc_presenter_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; limit?: number; offset?: number; - order_by_li?: key_val; - params?: key_val; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_li__event_presentation() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); + console.log(`*** load_ae_obj_li__event_presentation() *** [V3] for=${for_obj_type}:${for_obj_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 ?? 99); // 99 - // let offset: number = (params.qry__offset ?? 0); // 0 - - const params_json: key_val = {}; - - // console('params_json:', params_json); - - // ae_promises.load__event_presentation_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ - ae_promises.load__event_presentation_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, + try { + ae_promises.load__event_presentation_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, obj_type: 'event_presentation', - 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_presentation_obj_li_get_result) { - if (event_presentation_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presentation_props({ - obj_li: event_presentation_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: 'presentation', - 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__event_presentation({ - // obj_type: 'event_presentation', obj_li: event_presentation_obj_li_get_result - // }); - } - return event_presentation_obj_li_get_result; - } else { - return []; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + for_obj_type, + for_obj_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl }); - if (log_lvl) { - console.log( - 'ae_promises.load__event_presentation_obj_li:', - ae_promises.load__event_presentation_obj_li - ); - } - - if (inc_file_li) { - // Load the files for the presentations - if (log_lvl) { - console.log(`Need to load the file list for each presentation now.`); - } - for (let i = 0; i < ae_promises.load__event_presentation_obj_li.length; i++) { - const event_presentation_obj = ae_promises.load__event_presentation_obj_li[i]; - const event_presentation_id = event_presentation_obj.event_presentation_id_random; - - const load_event_file_obj_li = load_ae_obj_li__event_file({ - api_cfg: api_cfg, - for_obj_type: 'event_presentation', - for_obj_id: event_presentation_id, - enabled: enabled, - limit: limit, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_file_obj_li) => { - if (log_lvl) { - console.log(`event_file_obj_li = `, event_file_obj_li); - } - return event_file_obj_li; - }); - - if (log_lvl) { - console.log(`event_file_obj_li = `, load_event_file_obj_li); + if (ae_promises.load__event_presentation_obj_li) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__event_presentation_props({ + obj_li: ae_promises.load__event_presentation_obj_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presentation', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - // ae_promises.load__event_presentation_obj.event_file_li = load_event_file_obj_li; + } else if (try_cache) { + ae_promises.load__event_presentation_obj_li = await db_events.presentation + .where('event_session_id').equals(for_obj_id) + .toArray(); + } + } catch (error: any) { + console.log('V3 List Request failed.', error); + if (try_cache) { + ae_promises.load__event_presentation_obj_li = await db_events.presentation + .where('event_session_id').equals(for_obj_id) + .toArray(); } } - if (inc_presenter_li) { - // Load the presenters for the presentations - if (log_lvl) { - console.log(`Need to load the presenter list for each presentation now.`); - } - for (let i = 0; i < ae_promises.load__event_presentation_obj_li.length; i++) { - const event_presentation_obj = ae_promises.load__event_presentation_obj_li[i]; - const event_presentation_id = event_presentation_obj.event_presentation_id_random; - - const load_event_presenter_obj_li = load_ae_obj_li__event_presenter({ - api_cfg: api_cfg, - for_obj_type: 'event_presentation', - for_obj_id: event_presentation_id, - inc_file_li: inc_file_li, - enabled: enabled, - hidden: hidden, - limit: limit, - offset: offset, - // order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'}, - // params: {}, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_presenter_obj_li) => { - if (log_lvl) { - console.log(`event_presenter_obj_li = `, event_presenter_obj_li); - } - return event_presenter_obj_li; + if (ae_promises.load__event_presentation_obj_li) { + for (const presentation of ae_promises.load__event_presentation_obj_li) { + await _handle_nested_loads(presentation, { + api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }); - - if (log_lvl) { - console.log(`event_presenter_obj_li = `, load_event_presenter_obj_li); - } - // ae_promises.load__event_presentation_obj.event_presenter_li = load_event_presenter_obj_li; } } - return ae_promises.load__event_presentation_obj_li; + return ae_promises.load__event_presentation_obj_li || []; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function create_ae_obj__event_presentation({ api_cfg, event_id, event_session_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { @@ -367,255 +220,135 @@ export async function create_ae_obj__event_presentation({ event_id: string; event_session_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** create_ae_obj__event_presentation() *** event_id=${event_id} event_session_id=${event_session_id}` - ); + console.log(`*** create_ae_obj__event_presentation() *** [V3] session=${event_session_id}`); } - ae_promises.create__event_presentation = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event_presentation', - fields: { - event_id_random: event_id, - event_session_id_random: event_session_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_presentation_obj_create_result) { - if (event_presentation_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presentation_props({ - obj_li: [event_presentation_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: 'presentation', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event_presentation', + fields: { + event_id_random: event_id, + event_session_id_random: event_session_id, + ...data_kv + }, + log_lvl + }); - // db_save_ae_obj_li__event_presentation( - // { - // obj_type: 'event_presentation', - // obj_li: [event_presentation_obj_create_result] - // }); - } - return event_presentation_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_presentation:', - ae_promises.create__event_presentation - ); + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_presentation_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presentation', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.create__event_presentation; + + return result; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function delete_ae_obj_id__event_presentation({ api_cfg, event_presentation_id, - method = 'delete', // 'delete', 'disable', 'hide' - params = {}, + method = 'delete', try_cache = true, log_lvl = 0 }: { api_cfg: any; event_presentation_id: string; - method?: string; - params?: key_val; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; try_cache?: boolean; log_lvl?: number; }) { if (log_lvl) { - console.log( - `*** delete_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}` - ); + console.log(`*** delete_ae_obj_id__event_presentation() *** [V3] id=${event_presentation_id}`); } - ae_promises.delete__event_presentation_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_presentation', - obj_id: event_presentation_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_presentation_id=${event_presentation_id}` - ); - } - db_events.presentation.delete(event_presentation_id); - } - }); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event_presentation', + obj_id: event_presentation_id, + method, + log_lvl + }); - if (log_lvl) { - console.log( - 'ae_promises.delete__event_presentation_obj:', - ae_promises.delete__event_presentation_obj - ); + if (try_cache) { + await db_events.presentation.delete(event_presentation_id); } - return ae_promises.delete__event_presentation_obj; + return result; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function update_ae_obj__event_presentation({ api_cfg, event_presentation_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_presentation_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** update_ae_obj__event_presentation() *** event_presentation_id=${event_presentation_id}`, - data_kv - ); + console.log(`*** update_ae_obj__event_presentation() *** [V3] id=${event_presentation_id}`); } - ae_promises.update__event_presentation_obj = await api - .update_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_presentation', - obj_id: event_presentation_id, - fields: data_kv, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_presentation_obj_update_result) { - if (event_presentation_obj_update_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presentation_props({ - obj_li: [event_presentation_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: 'presentation', - 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__event_presentation({ - // obj_type: 'event_presentation', - // obj_li: [event_presentation_obj_update_result], - // log_lvl: log_lvl - // }); - } - return event_presentation_obj_update_result; - } else { - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () {}); + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event_presentation', + obj_id: event_presentation_id, + fields: data_kv, + log_lvl + }); - if (log_lvl) { - console.log( - 'ae_promises.update__event_presentation_obj:', - ae_promises.update__event_presentation_obj - ); + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_presentation_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presentation', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.update__event_presentation_obj; + + return result; } -// Updated 2025-05-22 export const properties_to_save = [ 'id', 'event_presentation_id', - // 'event_presentation_id_random', - 'external_id', 'code', - 'for_type', 'for_id', - // 'for_id_random', - 'type_code', - 'event_id', - // 'event_id_random', 'event_session_id', - // 'event_session_id_random', 'event_abstract_id', - // 'event_abstract_id_random', - 'abstract_code', - 'name', 'description', - 'start_datetime', 'end_datetime', - 'passcode', - 'hide_event_launcher', - 'enable', 'hide', 'priority', @@ -624,18 +357,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 'event_session_code', 'event_session_name' - - // Add more fields here if your DB save logic uses them ]; /** @@ -653,39 +378,26 @@ 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 + 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. + // 2. Create common computed properties const group = processed_obj.group ?? '0'; const priority = processed_obj.priority ? 1 : 0; const sort = processed_obj.sort ?? '0'; @@ -695,7 +407,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)); } @@ -706,7 +417,6 @@ async function _process_generic_props>({ return processed_obj_li; } -// Updated 2025-05-22 export async function process_ae_obj__event_presentation_props({ obj_li, log_lvl = 0 @@ -717,17 +427,6 @@ export async function process_ae_obj__event_presentation_props({ return _process_generic_props({ obj_li, obj_type: 'event_presentation', - log_lvl, - specific_processor: (obj) => { - // Event presentation-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}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } + log_lvl }); -} +} \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__event_presenter.ts b/src/lib/ae_events/ae_events__event_presenter.ts index 04e8b6ca..446759ab 100644 --- a/src/lib/ae_events/ae_events__event_presenter.ts +++ b/src/lib/ae_events/ae_events__event_presenter.ts @@ -9,274 +9,178 @@ import { load_ae_obj_li__event_file } from '$lib/ae_events/ae_events__event_file const ae_promises: key_val = {}; -// Updated 2024-10-08 +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__event_presenter({ api_cfg, event_presenter_id, inc_file_li = false, - enabled = 'enabled', - hidden = 'not_hidden', - limit = 19, - offset = 0, + view = 'default', try_cache = true, log_lvl = 0 }: { api_cfg: any; event_presenter_id: string; inc_file_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; - limit?: number; - offset?: number; + view?: string; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_id__event_presenter() *** event_presenter_id=${event_presenter_id}` - ); + console.log(`*** load_ae_obj_id__event_presenter() *** [V3] id=${event_presenter_id}`); } - const params = {}; - - ae_promises.load__event_presenter_obj = await api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, + try { + ae_promises.load__event_presenter_obj = await api.get_ae_obj_v3({ + api_cfg, obj_type: 'event_presenter', - obj_id: event_presenter_id, // NOTE: This is the FQDN, not normally the 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 - params: params, - log_lvl: log_lvl - }) - .then(async function (event_presenter_obj_get_result) { - if (event_presenter_obj_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presenter_props({ - obj_li: [event_presenter_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: 'presenter', - obj_li: processed_obj_li, - 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__event_presenter({ - // obj_type: 'event_presenter', - // obj_li: [event_presenter_obj_get_result] - // }); - } - return event_presenter_obj_get_result; - } else { - console.log('No results returned.'); - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + obj_id: event_presenter_id, + view, + log_lvl }); + if (ae_promises.load__event_presenter_obj) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__event_presenter_props({ + obj_li: [ae_promises.load__event_presenter_obj], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presenter', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); + } + } else if (try_cache) { + ae_promises.load__event_presenter_obj = await db_events.presenter.get(event_presenter_id); + } + } catch (error: any) { + console.log('V3 Request failed.', error); + if (try_cache) { + ae_promises.load__event_presenter_obj = await db_events.presenter.get(event_presenter_id); + } + } + + if (!ae_promises.load__event_presenter_obj) return null; + if (inc_file_li) { - // Load the files for the presenter - if (log_lvl) { - console.log(`Need to load the file list for the presenter now.`); - } - const load_event_file_obj_li = load_ae_obj_li__event_file({ - api_cfg: api_cfg, + ae_promises.load__event_presenter_obj.event_file_li = await load_ae_obj_li__event_file({ + api_cfg, for_obj_type: 'event_presenter', for_obj_id: event_presenter_id, - enabled: enabled, - limit: limit, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_file_obj_li) => { - if (log_lvl) { - console.log(`event_file_obj_li = `, event_file_obj_li); - } - return event_file_obj_li; + enabled: 'all', + limit: 25, + try_cache, + log_lvl }); - - if (log_lvl) { - console.log(`event_file_obj_li = `, load_event_file_obj_li); - } - ae_promises.load__event_presenter_obj.event_file_li = load_event_file_obj_li; } return ae_promises.load__event_presenter_obj; } -// Updated 2024-10-08 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__event_presenter({ api_cfg, - for_obj_type, + for_obj_type = 'event_presentation', for_obj_id, inc_file_li = false, enabled = 'enabled', hidden = 'not_hidden', - limit = 19, + limit = 50, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - given_name: 'ASC', - family_name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { given_name: 'ASC' }, + { family_name: 'ASC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - for_obj_type: string; + for_obj_type?: string; for_obj_id: string; inc_file_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; limit?: number; offset?: number; - order_by_li?: key_val; - params?: key_val; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_li__event_presenter() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); + console.log(`*** load_ae_obj_li__event_presenter() *** [V3] for=${for_obj_type}:${for_obj_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 ?? 99); // 99 - // let offset: number = (params.qry__offset ?? 0); // 0 - - const params_json: key_val = {}; - - // console.log('params_json:', params_json); - - // ae_promises.load__event_presenter_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ - ae_promises.load__event_presenter_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, + try { + ae_promises.load__event_presenter_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, obj_type: 'event_presenter', - 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_presenter_obj_li_get_result) { - if (event_presenter_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presenter_props({ - obj_li: event_presenter_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: 'presenter', - 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__event_presenter({ - // obj_type: 'event_presenter', - // obj_li: event_presenter_obj_li_get_result - // }); - } - return event_presenter_obj_li_get_result; - } else { - return []; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); + for_obj_type, + for_obj_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl }); - if (log_lvl) { - console.log( - 'ae_promises.load__event_presenter_obj_li:', - ae_promises.load__event_presenter_obj_li - ); - } - - if (inc_file_li) { - // Load the files for the presenters - if (log_lvl) { - console.log(`Need to load the file list for each presenter now.`); - } - for (let i = 0; i < ae_promises.load__event_presenter_obj_li.length; i++) { - const event_presenter_obj = ae_promises.load__event_presenter_obj_li[i]; - const event_presenter_id = event_presenter_obj.event_presenter_id_random; - - const load_event_file_obj_li = load_ae_obj_li__event_file({ - api_cfg: api_cfg, - for_obj_type: 'event_presenter', - for_obj_id: event_presenter_id, - enabled: enabled, - limit: limit, - try_cache: try_cache, - log_lvl: log_lvl - }).then((event_file_obj_li) => { - if (log_lvl) { - console.log(`event_file_obj_li = `, event_file_obj_li); - } - return event_file_obj_li; - }); - - if (log_lvl) { - console.log(`event_file_obj_li = `, load_event_file_obj_li); + if (ae_promises.load__event_presenter_obj_li) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__event_presenter_props({ + obj_li: ae_promises.load__event_presenter_obj_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presenter', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - // ae_promises.load__event_presenter_obj.event_file_li = load_event_file_obj_li; + } else if (try_cache) { + ae_promises.load__event_presenter_obj_li = await db_events.presenter + .where('event_presentation_id').equals(for_obj_id) + .toArray(); + } + } catch (error: any) { + console.log('V3 List Request failed.', error); + if (try_cache) { + ae_promises.load__event_presenter_obj_li = await db_events.presenter + .where('event_presentation_id').equals(for_obj_id) + .toArray(); } } - return ae_promises.load__event_presenter_obj_li; + if (inc_file_li && ae_promises.load__event_presenter_obj_li) { + for (const presenter of ae_promises.load__event_presenter_obj_li) { + const current_presenter_id = presenter.event_presenter_id_random || presenter.event_presenter_id || presenter.id; + presenter.event_file_li = await load_ae_obj_li__event_file({ + api_cfg, + for_obj_type: 'event_presenter', + for_obj_id: current_presenter_id, + enabled: 'all', + limit: 25, + try_cache, + log_lvl + }); + } + } + + return ae_promises.load__event_presenter_obj_li || []; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function create_ae_obj__event_presenter({ api_cfg, event_id, event_session_id, event_presentation_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { @@ -285,397 +189,199 @@ export async function create_ae_obj__event_presenter({ event_session_id: string; event_presentation_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** create_ae_obj__event_presenter() *** event_id=${event_id} event_session_id=${event_session_id} event_presentation_id=${event_presentation_id}` - ); + console.log(`*** create_ae_obj__event_presenter() *** [V3] presentation=${event_presentation_id}`); } - ae_promises.create__event_presenter = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event_presenter', - fields: { - event_id_random: event_id, - event_session_id_random: event_session_id, - event_presentation_id_random: event_presentation_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_presenter_obj_create_result) { - if (event_presenter_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presenter_props({ - obj_li: [event_presenter_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: 'presenter', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event_presenter', + fields: { + event_id_random: event_id, + event_session_id_random: event_session_id, + event_presentation_id_random: event_presentation_id, + ...data_kv + }, + log_lvl + }); - // db_save_ae_obj_li__event_presenter( - // { - // obj_type: 'event_presenter', obj_li: [event_presenter_obj_create_result] - // }); - } - return event_presenter_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_presenter:', ae_promises.create__event_presenter); + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_presenter_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presenter', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.create__event_presenter; + + return result; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function delete_ae_obj_id__event_presenter({ api_cfg, event_presenter_id, - method = 'delete', // 'delete', 'disable', 'hide' - params = {}, + method = 'delete', try_cache = true, log_lvl = 0 }: { api_cfg: any; event_presenter_id: string; - method?: string; - params?: key_val; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; try_cache?: boolean; log_lvl?: number; }) { if (log_lvl) { - console.log( - `*** delete_ae_obj_id__event_presenter() *** event_presenter_id=${event_presenter_id}` - ); + console.log(`*** delete_ae_obj_id__event_presenter() *** [V3] id=${event_presenter_id}`); } - ae_promises.delete__event_presenter_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_presenter', - obj_id: event_presenter_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_presenter_id=${event_presenter_id}` - ); - } - db_events.presenter.delete(event_presenter_id); - } - }); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event_presenter', + obj_id: event_presenter_id, + method, + log_lvl + }); - if (log_lvl) { - console.log( - 'ae_promises.delete__event_presenter_obj:', - ae_promises.delete__event_presenter_obj - ); + if (try_cache) { + await db_events.presenter.delete(event_presenter_id); } - return ae_promises.delete__event_presenter_obj; + return result; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function update_ae_obj__event_presenter({ api_cfg, event_presenter_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_presenter_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** update_ae_obj__event_presenter() *** event_presenter_id=${event_presenter_id}`, - data_kv - ); + console.log(`*** update_ae_obj__event_presenter() *** [V3] id=${event_presenter_id}`); } - ae_promises.update__event_presenter_obj = await api - .update_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_presenter', - obj_id: event_presenter_id, - fields: data_kv, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_presenter_obj_update_result) { - if (event_presenter_obj_update_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presenter_props({ - obj_li: [event_presenter_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: 'presenter', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event_presenter', + obj_id: event_presenter_id, + fields: data_kv, + log_lvl + }); - // db_save_ae_obj_li__event_presenter({ - // obj_type: 'event_presenter', - // obj_li: [event_presenter_obj_update_result] - // }); - } - return event_presenter_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_presenter_obj:', - ae_promises.update__event_presenter_obj - ); + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_presenter_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presenter', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.update__event_presenter_obj; + + return result; } -// Updated 2025-05-23 +// Updated 2026-01-20 to V3 export async function search__event_presenter({ api_cfg, event_id, + qry_str = '', agree = null, biography = null, - fulltext_search_qry_str, - ft_presenter_search_qry_str, - like_search_qry_str = null, - like_presentation_search_qry_str = null, - like_presenter_search_qry_str = null, enabled = 'enabled', hidden = 'not_hidden', - limit = 49, + limit = 25, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - given_name: 'ASC', - family_name: 'ASC', - email: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { given_name: 'ASC' }, + { family_name: 'ASC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - event_id: any; + event_id: string; + qry_str?: string; agree?: null | boolean; biography?: null | boolean; - fulltext_search_qry_str?: null | string; - ft_presenter_search_qry_str?: null | string; - like_search_qry_str?: null | string; - like_presentation_search_qry_str?: null | string; - like_presenter_search_qry_str?: null | string; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; limit?: number; offset?: number; - order_by_li?: key_val; - params?: any; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; -}): Promise { +}): Promise { if (log_lvl) { - console.log(`*** search__event_presenter() *** event_id=${event_id}`); + console.log(`*** search__event_presenter() *** [V3] event_id=${event_id} qry=${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 search_query: any = { + q: qry_str, + and: [{ field: 'event_id_random', op: 'eq', value: event_id }] + }; - const params_json: key_val = {}; + if (agree !== null) search_query.and.push({ field: 'agree', op: 'eq', value: agree }); + if (biography === true) search_query.and.push({ field: 'biography', op: 'ne', value: '' }); - // 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 (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true }); + else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false }); - if (fulltext_search_qry_str || ft_presenter_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 (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true }); + else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false }); - if (ft_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) { - params_json['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str; - } + const result_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'event_presenter', + search_query, + order_by_li, + limit, + offset, + log_lvl + }); + + if (result_li && try_cache) { + const processed_obj_li = await process_ae_obj__event_presenter_props({ + obj_li: result_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'presenter', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - // Use the AND (AND LIKE) query - // if (like_search_qry_str || like_presenter_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_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) { - // params_json['and_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str; - // } - // } - - // Use the AND (OR LIKE) query - if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_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_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) { - params_json['or_like']['event_presentation_li_qry_str'] = - like_presentation_search_qry_str; - } - if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) { - params_json['or_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str; - } - } - - params_json['and_qry'] = {}; - - if (agree === true || agree === false) { - params_json['and_qry']['agree'] = agree; - // if (!agree) { - // params_json['or_qry']['agree'] = null; - // } - } - // if (agree === null) { - // params_json['and_qry']['agree'] = agree; - // } - - if (biography) { - params_json['and_qry']['biography_check'] = biography; - } - - // ae_promises.load__event_presenter_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ - ae_promises.load__event_presenter_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_presenter', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: true, // NOTE: We want to use the alt table for session searching - // use_alt_mdl: 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 (event_presenter_obj_li_get_result) { - if (event_presenter_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_presenter_props({ - obj_li: event_presenter_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: 'presenter', - 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_presenter_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__event_presenter_obj_li:', - ae_promises.load__event_presenter_obj_li - ); - } - return ae_promises.load__event_presenter_obj_li; + return result_li || []; } -// Updated 2024-08-07 +/** + * Send sign-in link to Presenter + */ export async function email_sign_in__event_presenter({ api_cfg, to_email, @@ -688,8 +394,7 @@ export async function email_sign_in__event_presenter({ event_presentation_id, event_presenter_id, session_name, - presentation_name, - log_lvl = 0 + presentation_name }: { api_cfg: any; to_email: string; @@ -703,73 +408,38 @@ export async function email_sign_in__event_presenter({ event_presenter_id: string; session_name: string; presentation_name: string; - log_lvl?: number; }) { - if (log_lvl) { - console.log( - `*** email_sign_in__event_presenter() *** to_email=${to_email} to_name=${to_name} person_id=${person_id} person_passcode=${person_passcode} presentation_id=${event_presentation_id} presenter_id=${event_presenter_id}` - ); - } - - const subject = `LCI Congress 2025 - Pres Mgmt Hub Sign In Link for ${session_name} (ID: ${event_session_id})`; - + const subject = `Pres Mgmt Hub Sign In Link for ${presentation_name}`; const sign_in_url = encodeURI( `${base_url}/events/${event_id}/session/${event_session_id}?person_id=${person_id}&person_pass=${person_passcode}&presentation_id=${event_presentation_id}&presenter_id=${event_presenter_id}` ); const body_html = `
${to_name}, -

Your link to sign into the presentation management hub for LCI Congress 2025 is below. If you did not request this, please delete and ignore this email. If you need to make any changes or updates to your submission, you may use this link again later.

-
- -
- 27th Annual Lean Construction Congress (2025):
-

- Session Name: ${session_name}
- Session ID: ${event_session_id}
- Presentation Name: ${presentation_name}
- Presentation ID: ${event_presentation_id} -

-

Use this link to view or update your LCI 2025 presentation information.
- Copy and paste link: ${sign_in_url}

+

Your sign-in link for ${presentation_name}: ${sign_in_url}

`; - api.send_email({ - api_cfg: api_cfg, + return await api.send_email({ + api_cfg, from_email: 'noreply+presmgmt@oneskyit.com', - from_name: 'LCI 2025 Pres Mgmt Hub', - to_email: to_email, - subject: subject, - body_html: body_html + from_name: 'Aether Pres Mgmt', + to_email, + subject, + body_html }); } -// Updated 2025-05-23 export const properties_to_save = [ 'id', 'event_presenter_id', - // 'event_presenter_id_random', - 'external_id', 'code', - - // 'for_type', - // 'for_id', - // 'for_id_random', - 'event_id', - // 'event_id_random', 'event_session_id', - // 'event_session_id_random', 'event_presentation_id', - // 'event_presentation_id_random', 'event_person_id', - // 'event_person_id_random', 'person_id', - // 'person_id_random', 'person_profile_id', - // 'person_profile_id_random', - 'pronouns', 'informal_name', 'title_names', @@ -777,26 +447,16 @@ export const properties_to_save = [ 'middle_name', 'family_name', 'designations', - 'professional_title', - 'full_name', - 'affiliations', - 'email', - 'biography', - 'agree', 'comments', - 'passcode', - 'hide_event_launcher', - 'data_json', - 'enable', 'hide', 'priority', @@ -805,23 +465,15 @@ 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 'file_count', - 'event_session_code', 'event_session_name', 'event_session_start_datetime', 'event_presentation_code', 'event_presentation_name', 'event_presentation_start_datetime', - 'person_external_id', 'person_external_sys_id', 'person_given_name', @@ -835,7 +487,6 @@ export const properties_to_save = [ /** * NON-EXPORTED LOCAL HELPER - * Processes a list of Aether objects by applying common and specific transformations. */ async function _process_generic_props>({ obj_li, @@ -848,39 +499,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 + 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'; @@ -890,7 +526,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)); } @@ -901,7 +536,6 @@ async function _process_generic_props>({ return processed_obj_li; } -// Updated 2025-05-23 export async function process_ae_obj__event_presenter_props({ obj_li, log_lvl = 0 @@ -912,17 +546,6 @@ export async function process_ae_obj__event_presenter_props({ return _process_generic_props({ obj_li, obj_type: 'event_presenter', - log_lvl, - specific_processor: (obj) => { - // Event presenter-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}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } + log_lvl }); -} +} \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__event_session.ts b/src/lib/ae_events/ae_events__event_session.ts index 7f3a9ecf..b96b6777 100644 --- a/src/lib/ae_events/ae_events__event_session.ts +++ b/src/lib/ae_events/ae_events__event_session.ts @@ -10,7 +10,7 @@ import { load_ae_obj_li__event_presentation } from '$lib/ae_events/ae_events__ev const ae_promises: key_val = {}; -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__event_session({ api_cfg, event_session_id, @@ -20,7 +20,8 @@ export async function load_ae_obj_id__event_session({ inc_presenter_li = false, enabled = 'enabled', hidden = 'not_hidden', - limit = 149, + view = 'default', + limit = 100, offset = 0, try_cache = true, log_lvl = 0 @@ -31,123 +32,111 @@ export async function load_ae_obj_id__event_session({ inc_all_file_li?: boolean; inc_presentation_li?: boolean; inc_presenter_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + view?: string; limit?: number; offset?: number; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** load_ae_obj_id__event_session() *** event_session_id=${event_session_id}`); + console.log(`*** load_ae_obj_id__event_session() *** [V3] id=${event_session_id}`); } - const params = {}; - - // Check if we are explicitly offline to avoid long browser timeouts + // Check if offline if (typeof navigator !== 'undefined' && !navigator.onLine) { if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.'); ae_promises.load__event_session_obj = await db_events.session.get(event_session_id); if (ae_promises.load__event_session_obj) { - return await _handle_nested_loads(ae_promises.load__event_session_obj, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }); + return await _handle_nested_loads(ae_promises.load__event_session_obj, { + api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl + }); } return null; } try { - ae_promises.load__event_session_obj = await api.get_ae_obj_id_crud({ - api_cfg: api_cfg, + ae_promises.load__event_session_obj = await api.get_ae_obj_v3({ + api_cfg, obj_type: 'event_session', - obj_id: event_session_id, // NOTE: This is the FQDN, not normally the 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, - log_lvl: log_lvl + obj_id: event_session_id, + view, + log_lvl }); if (ae_promises.load__event_session_obj) { if (try_cache) { const processed_obj_li = await process_ae_obj__event_session_props({ obj_li: [ae_promises.load__event_session_obj], - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl + properties_to_save, + log_lvl }); } - } else { - console.log('No results returned from API.'); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache...'); - ae_promises.load__event_session_obj = await db_events.session.get(event_session_id); - } + } else if (try_cache) { + ae_promises.load__event_session_obj = await db_events.session.get(event_session_id); } } catch (error: any) { - console.log('API request failed.', error); + console.log('V3 Request failed.', error); if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache after error...'); ae_promises.load__event_session_obj = await db_events.session.get(event_session_id); - } else { - ae_promises.load__event_session_obj = null; } } - if (log_lvl) { - console.log('ae_promises.load__event_session_obj:', ae_promises?.load__event_session_obj); - } + if (!ae_promises.load__event_session_obj) return null; - if (!ae_promises?.load__event_session_obj) { - return null; - } - - return await _handle_nested_loads(ae_promises.load__event_session_obj, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }); + return await _handle_nested_loads(ae_promises.load__event_session_obj, { + api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl + }); } +/** + * Helper to handle nested collection loads for a session + */ async function _handle_nested_loads(session_obj: any, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }: any) { - const current_session_id = session_obj.event_session_id || session_obj.id; + const current_session_id = session_obj.event_session_id_random || session_obj.event_session_id || session_obj.id; if (inc_file_li) { - // Load the files for the session session_obj.event_file_li = await load_ae_obj_li__event_file({ - api_cfg: api_cfg, + api_cfg, for_obj_type: 'event_session', for_obj_id: current_session_id, - enabled: enabled, + enabled, limit: 15, - try_cache: try_cache, - log_lvl: log_lvl + try_cache, + log_lvl }); } if (inc_presentation_li) { - // Load the presentations for the session session_obj.event_presentation_li = await load_ae_obj_li__event_presentation({ - api_cfg: api_cfg, + api_cfg, for_obj_type: 'event_session', for_obj_id: current_session_id, inc_file_li: inc_all_file_li, - inc_presenter_li: inc_presenter_li, - enabled: enabled, // all, disabled, enabled - hidden: hidden, // all, hidden, not_hidden - limit: limit, // 25 - offset: offset, // 0 - params: {}, - try_cache: try_cache, - log_lvl: log_lvl + inc_presenter_li, + enabled, + hidden, + limit, + offset, + try_cache, + log_lvl }); } return session_obj; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__event_session({ api_cfg, - for_obj_type, + for_obj_type = 'event', for_obj_id, inc_file_li = false, inc_all_file_li = false, @@ -155,865 +144,316 @@ export async function load_ae_obj_li__event_session({ inc_presenter_li = false, enabled = 'enabled', hidden = 'not_hidden', - limit = 149, + limit = 100, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - start_datetime: 'ASC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { start_datetime: 'ASC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - for_obj_type: string; + for_obj_type?: string; for_obj_id: string; inc_file_li?: boolean; inc_all_file_li?: boolean; inc_presentation_li?: boolean; inc_presenter_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden - limit?: number; // 99 - offset?: number; // 0 - order_by_li?: key_val; - params?: key_val; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_li__event_session() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); + console.log(`*** load_ae_obj_li__event_session() *** [V3] for=${for_obj_type}:${for_obj_id}`); } - const params_json: key_val = {}; - // Check if offline if (typeof navigator !== 'undefined' && !navigator.onLine) { if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.'); ae_promises.load__event_session_obj_li = await db_events.session .where('for_id').equals(for_obj_id) .toArray(); - // Trigger nested loads if requested if (ae_promises.load__event_session_obj_li) { - for (let i = 0; i < ae_promises.load__event_session_obj_li.length; i++) { - await _handle_nested_loads(ae_promises.load__event_session_obj_li[i], { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }); + for (const session of ae_promises.load__event_session_obj_li) { + await _handle_nested_loads(session, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }); } } return ae_promises.load__event_session_obj_li || []; } try { - ae_promises.load__event_session_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_session', - 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. - enabled: enabled, - hidden: hidden, - order_by_li: order_by_li, - limit: limit, - offset: offset, - params_json: params_json, - params: params, - log_lvl: log_lvl - }); + ae_promises.load__event_session_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'event_session', + for_obj_type, + for_obj_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl + }); if (ae_promises.load__event_session_obj_li) { if (try_cache) { const processed_obj_li = await process_ae_obj__event_session_props({ obj_li: ae_promises.load__event_session_obj_li, - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl + properties_to_save, + log_lvl }); } - } else { - console.log('No results returned from API.'); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache...'); - ae_promises.load__event_session_obj_li = await db_events.session - .where('for_id').equals(for_obj_id) - .toArray(); - } else { - ae_promises.load__event_session_obj_li = []; - } - } - } catch (error: any) { - console.log('API request failed.', error); - if (try_cache) { - if (log_lvl) console.log('Attempting to load from local cache after error...'); + } else if (try_cache) { + ae_promises.load__event_session_obj_li = await db_events.session + .where('for_id').equals(for_obj_id) + .toArray(); + } + } catch (error: any) { + console.log('V3 List Request failed.', error); + if (try_cache) { ae_promises.load__event_session_obj_li = await db_events.session .where('for_id').equals(for_obj_id) .toArray(); - } else { - ae_promises.load__event_session_obj_li = []; } } if (ae_promises.load__event_session_obj_li) { - for (let i = 0; i < ae_promises.load__event_session_obj_li.length; i++) { - await _handle_nested_loads(ae_promises.load__event_session_obj_li[i], { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }); + for (const session of ae_promises.load__event_session_obj_li) { + await _handle_nested_loads(session, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }); } } - return ae_promises.load__event_session_obj_li; + return ae_promises.load__event_session_obj_li || []; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function create_ae_obj__event_session({ api_cfg, event_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** create_ae_obj__event_session() *** event_id=${event_id}`); + console.log(`*** create_ae_obj__event_session() *** [V3] event_id=${event_id}`); } - ae_promises.create__event_session = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event_session', - fields: { - event_id_random: event_id, - ...data_kv - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_session_obj_create_result) { - if (event_session_obj_create_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_session_props({ - obj_li: [event_session_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: 'session', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event_session', + fields: { + event_id_random: event_id, + ...data_kv + }, + log_lvl + }); - // db_save_ae_obj_li__event_session( - // { - // obj_type: 'event_session', - // obj_li: [event_session_obj_create_result] - // }); - } - return event_session_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_session:', ae_promises.create__event_session); + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_session_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'session', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.create__event_session; + + return result; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function delete_ae_obj_id__event_session({ api_cfg, event_session_id, - method = 'delete', // 'delete', 'disable', 'hide' - params = {}, + method = 'delete', try_cache = true, log_lvl = 0 }: { api_cfg: any; event_session_id: string; - method?: string; - params?: key_val; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; try_cache?: boolean; log_lvl?: number; }) { if (log_lvl) { - console.log( - `*** delete_ae_obj_id__event_session() *** event_session_id=${event_session_id}` - ); + console.log(`*** delete_ae_obj_id__event_session() *** [V3] id=${event_session_id}`); } - ae_promises.delete__event_session_obj = await api - .delete_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_session', - obj_id: event_session_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_session_id=${event_session_id}` - ); - } - db_events.session.delete(event_session_id); - } - }); + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'event_session', + obj_id: event_session_id, + method, + log_lvl + }); - if (log_lvl) { - console.log( - 'ae_promises.delete__event_session_obj:', - ae_promises.delete__event_session_obj - ); + if (try_cache) { + await db_events.session.delete(event_session_id); } - return ae_promises.delete__event_session_obj; + return result; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function update_ae_obj__event_session({ api_cfg, event_session_id, data_kv, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; event_session_id: string; data_kv: key_val; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** update_ae_obj__event_session() *** event_session_id=${event_session_id}`, - data_kv - ); - } - // ae_promises.update__event_session_obj = 'test'; - ae_promises.update__event_session_obj = await api - .update_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_session', - obj_id: event_session_id, - fields: data_kv, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (event_session_obj_update_result) { - if (event_session_obj_update_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_session_props({ - obj_li: [event_session_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: 'session', - 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__event_session({ - // obj_type: 'event_session', obj_li: [event_session_obj_update_result] - // }); - } - return event_session_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_session_obj:', - ae_promises.update__event_session_obj - ); - } - return ae_promises.update__event_session_obj; -} - -// This new function is using CRUD v2. This should allow for more flexibility in the queries. -// Updated 2025-07-21 -export async function qry__event_session({ - api_cfg, - event_id, - qry_str, - qry_files, - qry_start_datetime, // Example greater than: '2024-10-24' - qry_poc_agree = null, - qry_poc_kv_json, - enabled = 'enabled', - hidden = 'not_hidden', - limit = 49, - offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - start_datetime: 'ASC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, - try_cache = true, - log_lvl = 0 -}: { - api_cfg: any; - event_id: any; - qry_str?: string; - qry_files?: null | boolean; - qry_start_datetime?: null | string; // Greater than this datetime - qry_poc_agree?: null | boolean; - qry_poc_kv_json?: null | boolean; // Key value pairs for the point of contact - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden - limit?: number; - offset?: number; - order_by_li?: key_val; - params?: any; - try_cache?: boolean; - log_lvl?: number; -}): Promise { - if (log_lvl) { - console.log(`*** qry__event_session() *** event_id=${event_id} qry_str=${qry_str}`); + console.log(`*** update_ae_obj__event_session() *** [V3] id=${event_session_id}`); } - const params_json: key_val = {}; + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event_session', + obj_id: event_session_id, + fields: data_kv, + log_lvl + }); - 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); - } - - if (qry_poc_agree === true) { - const qry_param = { - type: 'AND', - field: 'poc_agree', - operator: '=', - value: true - }; - params_json['qry'].push(qry_param); - } else if (qry_poc_agree === false) { - // let qry_param = - // { - // type: "AND", - // field: "poc_agree", - // operator: "IS", - // value: null - // }; - // params_json['qry'].push(qry_param); - const qry_param = { - type: 'AND', - field: 'poc_agree', - operator: '=', - value: false - }; - params_json['qry'].push(qry_param); - } - - if (qry_poc_kv_json === true) { - const qry_param = { - type: 'AND', - field: 'poc_kv_json', - operator: 'IS NOT', - value: null - }; - params_json['qry'].push(qry_param); - } else if (qry_poc_kv_json === false) { - const qry_param = { - type: 'AND', - field: 'poc_kv_json', - operator: 'IS', - value: null - }; - params_json['qry'].push(qry_param); - } - - ae_promises.load__event_session_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_session', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: true, // NOTE: We want to use the alt table for session 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 (event_session_obj_li_get_result) { - if (event_session_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_session_props({ - obj_li: event_session_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: 'presenter', - 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__event_session({ - // obj_type: 'event_session', - // obj_li: event_session_obj_li_get_result - // }); - } - return event_session_obj_li_get_result; - } else { - return []; - } + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__event_session_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'session', + obj_li: processed_obj_li, + properties_to_save, + log_lvl }); - - if (log_lvl) { - console.log( - 'ae_promises.load__event_session_obj_li:', - ae_promises.load__event_session_obj_li - ); } - return ae_promises.load__event_session_obj_li; + + return result; } -// Updated 2025-05-22 +// Updated 2026-01-20 to V3 export async function search__event_session({ api_cfg, event_id, + qry_str = '', poc_agree = null, - fulltext_search_qry_str, - ft_presenter_search_qry_str, - like_search_qry_str = null, - like_presentation_search_qry_str = null, - like_presenter_search_qry_str = null, - like_poc_name_qry_str = null, - file_count = false, // If true then only show those that have a file count + file_count = false, location_name = null, enabled = 'enabled', hidden = 'not_hidden', - limit = 49, + limit = 25, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - start_datetime: 'ASC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - } as const, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { start_datetime: 'ASC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - event_id: any; + event_id: string; + qry_str?: string; poc_agree?: null | boolean; - fulltext_search_qry_str?: null | string; - ft_presenter_search_qry_str?: null | string; - like_search_qry_str?: null | string; - like_presentation_search_qry_str?: null | string; - like_presenter_search_qry_str?: null | string; - like_poc_name_qry_str?: null | string; file_count?: boolean; location_name?: null | string; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; limit?: number; offset?: number; - order_by_li?: key_val; - params?: key_val; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log( - `*** search__event_session() *** event_id=${event_id} like_search_qry_str=${like_search_qry_str} location_name=${location_name}` - ); + console.log(`*** search__event_session() *** [V3] event_id=${event_id} qry=${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 search_query: any = { + q: qry_str, + and: [{ field: 'event_id_random', op: 'eq', value: event_id }] + }; - const 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_presenter_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_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) { - params_json['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str; - } - } - - // Use the AND (AND LIKE) query - // if (like_search_qry_str || like_presenter_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_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) { - // params_json['and_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str; - // } - // } - - // Use the AND (OR LIKE) query - if ( - like_search_qry_str || - like_presentation_search_qry_str || - like_presenter_search_qry_str || - like_poc_name_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_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) { - params_json['or_like']['event_presentation_li_qry_str'] = - like_presentation_search_qry_str; - } - if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) { - params_json['or_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str; - } - if (like_poc_name_qry_str && like_poc_name_qry_str.length > 2) { - params_json['or_like']['poc_person_full_name'] = like_poc_name_qry_str; - } - } - - params_json['and_qry'] = {}; - - if (poc_agree) { - params_json['and_qry']['poc_agree'] = poc_agree; + if (poc_agree !== null) { + search_query.and.push({ field: 'poc_agree', op: 'eq', value: poc_agree }); } if (file_count) { - params_json['and_qry']['file_count'] = file_count; + search_query.and.push({ field: 'file_count', op: 'gt', value: 0 }); } - // This should be using a like with surrounded by %'s if (location_name) { - params_json['and_qry']['event_location_name'] = location_name; + search_query.and.push({ field: 'event_location_name', op: 'like', value: `%${location_name}%` }); } - // let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}; + if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true }); + else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false }); - // ae_promises.load__event_session_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ - ae_promises.load__event_session_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'event_session', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_tbl: true, // NOTE: We want to use the alt table for session searching - // use_alt_mdl: 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 (event_session_obj_li_get_result) { - if (event_session_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__event_session_props({ - obj_li: event_session_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: 'session', - obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } + if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true }); + else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false }); - // db_save_ae_obj_li__event_session({ - // obj_type: 'event_session', - // obj_li: event_session_obj_li_get_result - // }); - } - return event_session_obj_li_get_result; - } else { - return []; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }) - .finally(function () {}); + const result_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'event_session', + search_query, + order_by_li, + limit, + offset, + log_lvl + }); - if (log_lvl) { - console.log( - 'ae_promises.load__event_session_obj_li:', - ae_promises.load__event_session_obj_li - ); + if (result_li && try_cache) { + const processed_obj_li = await process_ae_obj__event_session_props({ + obj_li: result_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'session', + obj_li: processed_obj_li, + properties_to_save, + log_lvl + }); } - return ae_promises.load__event_session_obj_li; + + return result_li || []; } -// This function will loop through the event_session_obj_li and save each one to the DB. -// Updated 2025-05-09 -export async function db_save_ae_obj_li__event_session({ - obj_type, - obj_li, - log_lvl = 0 -}: { - obj_type: string; - obj_li: any; - log_lvl?: number; -}) { - if (log_lvl) { - console.log(`*** db_save_ae_obj_li__event_session() *** obj_type=${obj_type}`, obj_li); - } - - 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_session_id_random, - event_session_id: obj.event_session_id_random, - event_session_id_random: obj.event_session_id_random, - - external_id: obj.external_id, - code: obj.code, - - for_type: obj.for_type, - for_id: obj.for_id_id_random, - for_id_random: obj.for_id_random, - - type_code: obj.type_code, - - event_id: obj.event_id_random, - event_id_random: obj.event_id_random, - event_location_id: obj.event_location_id_random, - event_location_id_random: obj.event_location_id_random, - - poc_person_id: obj.poc_person_id_random, - poc_person_id_random: obj.poc_person_id_random, - poc_agree: obj.poc_agree, - poc_kv_json: obj.poc_kv_json ?? {}, - - name: obj.name, - description: obj.description, - - start_datetime: obj.start_datetime, - end_datetime: obj.end_datetime, - - passcode: obj.passcode, - - hide_event_launcher: obj.hide_event_launcher, - - alert: obj.alert, - alert_msg: obj.alert_msg, - - data_json: obj.data_json, - - ux_mode: obj.ux_mode, - - 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, - - // 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, - - poc_person_given_name: obj.poc_person_given_name, - poc_person_family_name: obj.poc_person_family_name, - poc_person_full_name: obj.poc_person_full_name, - poc_person_primary_email: obj.poc_person_primary_email, - poc_person_passcode: obj.poc_person_passcode, - - event_name: obj.event_name, - - event_location_code: obj.event_location_code, - event_location_name: obj.event_location_name, - - // A key value list of the presentations - event_presentation_kv: obj.event_presentation_kv, - event_presentation_li: obj.event_presentation_li - }; - - let id_random = null; - - try { - id_random = await db_events.session.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.session.put(obj_record); - } catch (error) { - console.error(`Error: Failed to put ${obj.event_session_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; - } else { - if (log_lvl) { - console.log('No objects to save.'); - } - return []; - } -} - -// This is intended for the Point of Contact (POC) for the session. -// Updated 2024-07-01 +/** + * Send sign-in link to POC + */ export async function email_sign_in__event_session({ api_cfg, to_email, @@ -1035,83 +475,49 @@ export async function email_sign_in__event_session({ event_session_id: string; session_name: string; }) { - console.log( - `*** email_sign_in__event_session() *** to_email=${to_email} to_name=${to_name} person_id=${person_id} person_passcode=${person_passcode} session_id=${event_session_id}` - ); - - const subject = `LCI Congress 2025 - Pres Mgmt Hub Sign In Link for ${session_name} (ID: ${event_session_id})`; - + const subject = `Pres Mgmt Hub Sign In Link for ${session_name}`; const sign_in_url = encodeURI( - `${base_url}/events/${event_id}/session/${event_session_id}?person_id=${person_id}&person_pass=${person_passcode}&session_id=${event_session_id}` + `${base_url}/events/${event_id}/session/${event_session_id}?person_id=${person_id}&person_pass=${person_passcode}` ); const body_html = `
${to_name}, -

Your link to sign into the presentation management hub as a session Champion for LCI Congress 2025 is below. If you did not request this, please delete and ignore this email. If you need to make any changes or updates to your submission, you may use this link again later.

-
- -
- 27th Annual Lean Construction Congress (2025):
-

- Session Name: ${session_name}
- Session ID: ${event_session_id} -

-

Use this link to view or update your LCI 2025 session information.
- Copy and paste link: ${sign_in_url}

+

Your sign-in link for ${session_name}: ${sign_in_url}

`; - api.send_email({ - api_cfg: api_cfg, + return await api.send_email({ + api_cfg, from_email: 'noreply+presmgmt@oneskyit.com', - from_name: 'LCI 2025 Pres Mgmt Hub', - to_email: to_email, - subject: subject, - body_html: body_html + from_name: 'Aether Pres Mgmt', + to_email, + subject, + body_html }); } -// Updated 2025-05-09 export const properties_to_save = [ 'id', 'event_session_id', - // 'event_session_id_random', - 'external_id', 'code', - 'for_type', 'for_id', - // 'for_id_random', - 'type_code', - 'event_id', - // 'event_id_random', 'event_location_id', - // 'event_location_id_random', - 'poc_person_id', - // 'poc_person_id_random', 'poc_agree', 'poc_kv_json', - 'name', 'description', - 'start_datetime', 'end_datetime', - 'passcode', - 'hide_event_launcher', - 'alert', 'alert_msg', - 'data_json', - 'ux_mode', - 'enable', 'hide', 'priority', @@ -1120,32 +526,20 @@ 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 'file_count', 'file_count_all', 'internal_use_count', 'event_file_id_li_json', - 'poc_person_given_name', 'poc_person_family_name', 'poc_person_full_name', 'poc_person_primary_email', 'poc_person_passcode', - 'event_name', - 'event_location_code', 'event_location_name', - - // A key value list of the presentations - 'event_presentation_kv', 'event_presentation_li' ]; @@ -1164,39 +558,26 @@ 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 + 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. + // 2. Create common computed properties const group = processed_obj.group ?? '0'; const priority = processed_obj.priority ? 1 : 0; const sort = processed_obj.sort ?? '0'; @@ -1206,7 +587,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)); } @@ -1217,7 +597,6 @@ async function _process_generic_props>({ return processed_obj_li; } -// Updated 2025-05-09 export async function process_ae_obj__event_session_props({ obj_li, log_lvl = 0 @@ -1228,17 +607,6 @@ export async function process_ae_obj__event_session_props({ return _process_generic_props({ obj_li, obj_type: 'event_session', - log_lvl, - specific_processor: (obj) => { - // Event session-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}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } + log_lvl }); -} +} \ No newline at end of file diff --git a/src/lib/ae_events/ae_events__exhibit.ts b/src/lib/ae_events/ae_events__exhibit.ts index 4ae957ec..e9f164eb 100644 --- a/src/lib/ae_events/ae_events__exhibit.ts +++ b/src/lib/ae_events/ae_events__exhibit.ts @@ -42,37 +42,10 @@ export const properties_to_save_exhibit_tracking = [ 'notes', 'created_on', 'updated_on', - // Generated fields for sorting locally only 'tmp_sort_1', 'tmp_sort_2' ]; -// --- PROCESS FUNCTION --- -export async function process_ae_obj__exhibit_tracking_props({ - obj_li, - log_lvl = 0 -}: { - obj_li: any[]; - log_lvl?: number; -}) { - return _process_generic_props({ - obj_li, - obj_type: 'event_exhibit_tracking', - log_lvl, - specific_processor: (obj) => { - // Event exhibit tracking-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}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } - }); -} - // --- PROPERTIES TO SAVE --- export const properties_to_save = [ 'id', @@ -98,14 +71,12 @@ export const properties_to_save = [ 'notes', 'created_on', 'updated_on', - // Generated fields for sorting locally only 'tmp_sort_1', 'tmp_sort_2' ]; /** * NON-EXPORTED LOCAL HELPER - * Processes a list of Aether objects by applying common and specific transformations. */ async function _process_generic_props>({ obj_li, @@ -155,7 +126,20 @@ async function _process_generic_props>({ return processed_obj_li; } -// --- PROCESS FUNCTION --- +export async function process_ae_obj__exhibit_tracking_props({ + obj_li, + log_lvl = 0 +}: { + obj_li: any[]; + log_lvl?: number; +}) { + return _process_generic_props({ + obj_li, + obj_type: 'event_exhibit_tracking', + log_lvl + }); +} + export async function process_ae_obj__exhibit_props({ obj_li, log_lvl = 0 @@ -166,307 +150,265 @@ export async function process_ae_obj__exhibit_props({ return _process_generic_props({ obj_li, obj_type: 'event_exhibit', - log_lvl, - specific_processor: (obj) => { - // Event exhibit-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}`; - obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ - obj.sort?.toString().padStart(3, '0') ?? '' - }_${obj.updated_on}_${obj.created_on}`; - - return obj; - } + log_lvl }); } -// Updated 2024-03 +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__exhibit({ api_cfg, exhibit_id, + view = 'default', try_cache = false, log_lvl = 0 }: { api_cfg: any; exhibit_id: string; + view?: string; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** load_ae_obj_id__exhibit() *** exhibit_id=${exhibit_id}`); + console.log(`*** load_ae_obj_id__exhibit() *** [V3] id=${exhibit_id}`); } try { - ae_promises.load__exhibit_obj = await api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_exhibit', - obj_id: exhibit_id, - use_alt_table: false, - use_alt_base: false, - params: {}, - log_lvl: log_lvl - }); + ae_promises.load__exhibit_obj = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'event_exhibit', + obj_id: exhibit_id, + view, + log_lvl + }); if (ae_promises.load__exhibit_obj) { if (try_cache) { const processed_obj_li = await process_ae_obj__exhibit_props({ obj_li: [ae_promises.load__exhibit_obj], - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'exhibit', obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl + properties_to_save, + log_lvl }); } - } else { - if (try_cache) { - ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id); - } + } else if (try_cache) { + ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id); } } catch (error: any) { + console.log('V3 Request failed.', error); if (try_cache) { ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id); - } else { - ae_promises.load__exhibit_obj = null; } } - return ae_promises.load__exhibit_obj; + return ae_promises.load__exhibit_obj || null; } -// Updated 2024-03-06 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__exhibit({ api_cfg, event_id, - params = {}, + enabled = 'enabled', + hidden = 'not_hidden', + limit = 100, + offset = 0, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - event_id: any; - params: any; + event_id: string; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { if (log_lvl) { - console.log(`*** load_ae_obj_li__exhibit() *** event_id=${event_id}`); + console.log(`*** load_ae_obj_li__exhibit() *** [V3] for=event:${event_id}`); } - const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; - const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; - const limit: number = params.qry__limit ?? 99; - const offset: number = params.qry__offset ?? 0; - - const params_json: key_val = { - and_in_li: { - license_max: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - } - }; - try { - ae_promises.load__event_exhibit_obj_li = await api - .get_ae_obj_li_for_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_exhibit', - for_obj_type: 'event', - for_obj_id: event_id, - use_alt_table: false, - use_alt_base: false, - enabled: enabled, - hidden: hidden, - order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' }, - limit: limit, - offset: offset, - params_json: params_json, - params: params, - log_lvl: log_lvl - }); + ae_promises.load__event_exhibit_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'event_exhibit', + for_obj_type: 'event', + for_obj_id: event_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl + }); if (ae_promises.load__event_exhibit_obj_li) { if (try_cache) { const processed_obj_li = await process_ae_obj__exhibit_props({ obj_li: ae_promises.load__event_exhibit_obj_li, - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'exhibit', obj_li: processed_obj_li, - properties_to_save: properties_to_save, - log_lvl: log_lvl + properties_to_save, + log_lvl }); } - } else { - if (try_cache) { - ae_promises.load__event_exhibit_obj_li = await db_events.exhibit - .where('event_id').equals(event_id) - .toArray(); - } else { - ae_promises.load__event_exhibit_obj_li = []; - } + } else if (try_cache) { + ae_promises.load__event_exhibit_obj_li = await db_events.exhibit + .where('event_id').equals(event_id) + .toArray(); } } catch (error: any) { + console.log('V3 List Request failed.', error); if (try_cache) { ae_promises.load__event_exhibit_obj_li = await db_events.exhibit .where('event_id').equals(event_id) .toArray(); - } else { - ae_promises.load__event_exhibit_obj_li = []; } } - return ae_promises.load__event_exhibit_obj_li; + return ae_promises.load__event_exhibit_obj_li || []; } +// Updated 2026-01-20 to V3 export async function load_ae_obj_id__exhibit_tracking({ api_cfg, exhibit_tracking_id, + view = 'default', try_cache = false, log_lvl = 0 }: { api_cfg: any; exhibit_tracking_id: string; + view?: string; try_cache?: boolean; log_lvl?: number; }): Promise { - if (log_lvl) { - console.log( - `*** load_ae_obj_id__exhibit_tracking() *** exhibit_tracking_id=${exhibit_tracking_id}` - ); - } - try { - ae_promises.load__event_exhibit_tracking_obj = await api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_exhibit_tracking', - obj_id: exhibit_tracking_id, - use_alt_table: false, - use_alt_base: false, - params: {}, - log_lvl: log_lvl - }); + ae_promises.load__event_exhibit_tracking_obj = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'event_exhibit_tracking', + obj_id: exhibit_tracking_id, + view, + log_lvl + }); if (ae_promises.load__event_exhibit_tracking_obj) { if (try_cache) { const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ obj_li: [ae_promises.load__event_exhibit_tracking_obj], - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'exhibit_tracking', obj_li: processed_obj_li, properties_to_save: properties_to_save_exhibit_tracking, - log_lvl: log_lvl + log_lvl }); } - } else { - if (try_cache) { - ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id); - } + } else if (try_cache) { + ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id); } } catch (error: any) { if (try_cache) { ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id); - } else { - ae_promises.load__event_exhibit_tracking_obj = null; } } - return ae_promises.load__event_exhibit_tracking_obj; + return ae_promises.load__event_exhibit_tracking_obj || null; } -// Updated 2024-03-19 +// Updated 2026-01-20 to V3 export async function load_ae_obj_li__exhibit_tracking({ api_cfg, exhibit_id, - params = {}, + enabled = 'enabled', + hidden = 'all', + limit = 100, + offset = 0, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; - exhibit_id: any; - params: any; + exhibit_id: string; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + limit?: number; + offset?: number; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; }): Promise { - if (log_lvl) { - console.log(`*** load_ae_obj_li__exhibit_tracking() *** exhibit_id=${exhibit_id}`); - } - - const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; - const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'all'; - const limit: number = params.qry__limit ?? 99; - const offset: number = params.qry__offset ?? 0; - try { - ae_promises.load__event_exhibit_tracking_obj_li = await api - .get_ae_obj_li_for_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_exhibit_tracking', - for_obj_type: 'event_exhibit', - for_obj_id: exhibit_id, - use_alt_table: false, - use_alt_base: false, - enabled: enabled, - hidden: hidden, - order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' }, - limit: limit, - offset: offset, - params_json: {}, - params: params, - log_lvl: log_lvl - }); + ae_promises.load__event_exhibit_tracking_obj_li = await api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'event_exhibit_tracking', + for_obj_type: 'event_exhibit', + for_obj_id: exhibit_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl + }); if (ae_promises.load__event_exhibit_tracking_obj_li) { if (try_cache) { const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ obj_li: ae_promises.load__event_exhibit_tracking_obj_li, - log_lvl: log_lvl + log_lvl }); await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'exhibit_tracking', obj_li: processed_obj_li, properties_to_save: properties_to_save_exhibit_tracking, - log_lvl: log_lvl + log_lvl }); } - } else { - if (try_cache) { - ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking - .where('event_exhibit_id').equals(exhibit_id) - .toArray(); - } else { - ae_promises.load__event_exhibit_tracking_obj_li = []; - } + } else if (try_cache) { + ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking + .where('event_exhibit_id').equals(exhibit_id) + .toArray(); } } catch (error: any) { if (try_cache) { ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking .where('event_exhibit_id').equals(exhibit_id) .toArray(); - } else { - ae_promises.load__event_exhibit_tracking_obj_li = []; } } - return ae_promises.load__event_exhibit_tracking_obj_li; + return ae_promises.load__event_exhibit_tracking_obj_li || []; } -// Updated 2024-03-22 +// Updated 2026-01-20 to V3 export async function create_ae_obj__exhibit_tracking({ api_cfg, exhibit_id, event_badge_id, external_person_id, - params = {}, try_cache = true, log_lvl = 0 }: { @@ -474,133 +416,102 @@ export async function create_ae_obj__exhibit_tracking({ exhibit_id: string; event_badge_id: string; external_person_id: string; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { - ae_promises.create__event_exhibit_tracking = await api - .create_ae_obj_crud({ - api_cfg: api_cfg, - obj_type: 'event_exhibit_tracking', - fields: { - event_exhibit_id_random: exhibit_id, - event_badge_id_random: event_badge_id, - external_person_id: external_person_id - }, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (obj_create_result) { - if (obj_create_result && try_cache) { - const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ - obj_li: [obj_create_result], - log_lvl: log_lvl - }); - await db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'exhibit_tracking', - obj_li: processed_obj_li, - properties_to_save: properties_to_save_exhibit_tracking, - log_lvl: log_lvl - }); - } - return obj_create_result; - }); + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'event_exhibit_tracking', + fields: { + event_exhibit_id_random: exhibit_id, + event_badge_id_random: event_badge_id, + external_person_id + }, + log_lvl + }); - return ae_promises.create__event_exhibit_tracking; + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'exhibit_tracking', + obj_li: processed_obj_li, + properties_to_save: properties_to_save_exhibit_tracking, + log_lvl + }); + } + + return result; } -// Updated 2024-03-28 +// Updated 2026-01-20 to V3 export async function update_ae_obj__exhibit_tracking({ api_cfg, exhibit_tracking_id, data, - params = {}, try_cache = true, log_lvl = 0 }: { api_cfg: any; exhibit_tracking_id: string; data: any; - params?: key_val; try_cache?: boolean; log_lvl?: number; }): Promise { - ae_promises.update__event_exhibit_tracking = await api - .update_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'event_exhibit_tracking', - obj_id: exhibit_tracking_id, - fields: data, - key: api_cfg.api_crud_super_key, - params: params, - return_obj: true, - log_lvl: log_lvl - }) - .then(async function (obj_update_result) { - if (obj_update_result && try_cache) { - const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ - obj_li: [obj_update_result], - log_lvl: log_lvl - }); - await db_save_ae_obj_li__ae_obj({ - db_instance: db_events, - table_name: 'exhibit_tracking', - obj_li: processed_obj_li, - properties_to_save: properties_to_save_exhibit_tracking, - log_lvl: log_lvl - }); - } - return obj_update_result; - }); + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'event_exhibit_tracking', + obj_id: exhibit_tracking_id, + fields: data, + log_lvl + }); - return ae_promises.update__event_exhibit_tracking; + if (result && try_cache) { + const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ + obj_li: [result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_events, + table_name: 'exhibit_tracking', + obj_li: processed_obj_li, + properties_to_save: properties_to_save_exhibit_tracking, + log_lvl + }); + } + + return result; } export async function download_export__event_exhibit_tracking({ api_cfg, exhibit_id, - file_type = 'CSV', // 'CSV' or 'Excel' - return_file = true, - filename = 'no_filename.csv', - auto_download = false, - params = {}, + file_type = 'CSV', + filename = 'exhibit_tracking_export.csv', log_lvl = 0 }: { api_cfg: any; exhibit_id: string; file_type?: string; - return_file?: boolean; filename?: string; - auto_download?: boolean; - params?: key_val; log_lvl?: number; }) { - console.log('*** ae_events_functions.js: get_event_exhibit_tracking_export() ***'); - const endpoint = `/event/exhibit/${exhibit_id}/tracking/export`; - if (file_type == 'CSV' || file_type == 'Excel') { - params['file_type'] = file_type; - } - params['return_file'] = true; + const params = { + file_type, + return_file: true + }; - ae_promises.download__event_exhibit_tracking_export_file = await api.get_object({ - api_cfg: api_cfg, - endpoint: endpoint, - params: params, + return await api.get_object({ + api_cfg, + endpoint, + params, return_blob: true, - filename: filename, - auto_download: auto_download, - log_lvl: log_lvl + filename, + auto_download: true, + log_lvl }); - - if (log_lvl) { - console.log( - 'ae_promises.download__event_exhibit_tracking_export_file:', - ae_promises.download__event_exhibit_tracking_export_file - ); - } - return ae_promises.download__event_exhibit_tracking_export_file; } \ No newline at end of file diff --git a/src/lib/ae_sponsorships/ae_sponsorships_functions.ts b/src/lib/ae_sponsorships/ae_sponsorships_functions.ts index 491d27c9..940b3ad8 100644 --- a/src/lib/ae_sponsorships/ae_sponsorships_functions.ts +++ b/src/lib/ae_sponsorships/ae_sponsorships_functions.ts @@ -1,11 +1,8 @@ import type { key_val } from '$lib/stores/ae_stores'; import { api } from '$lib/api/api'; - import { db_sponsorships } from '$lib/ae_sponsorships/db_sponsorships'; import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie'; - -// import { liveQuery } from "dexie"; -// import { db_core } from "$lib/db_core"; +import type { ae_Sponsorship, ae_Sponsorship_Cfg } from '$lib/types/ae_types'; const ae_promises: key_val = {}; @@ -46,7 +43,7 @@ export async function process_ae_obj__sponsorship_cfg_props({ obj_type: 'sponsorship_cfg', log_lvl, specific_processor: (obj) => { - // Sponsorship Cfg-specific computed sort fields, overriding generic ones if needed + // Sponsorship Cfg-specific computed sort fields obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ obj.sort?.toString().padStart(3, '0') ?? '' }_${obj.updated_on ?? obj.created_on}`; @@ -112,7 +109,7 @@ export async function process_ae_obj__sponsorship_props({ obj_type: 'sponsorship', log_lvl, specific_processor: (obj) => { - // Sponsorship-specific computed sort fields, overriding generic ones if needed + // Sponsorship-specific computed sort fields obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ obj.sort?.toString().padStart(3, '0') ?? '' }_${obj.updated_on ?? obj.created_on}`; @@ -156,13 +153,10 @@ async function _process_generic_props>({ 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 + const newKey = key.slice(0, -7); (processed_obj as any)[newKey] = processed_obj[key]; } } @@ -172,7 +166,7 @@ async function _process_generic_props>({ (processed_obj as any).id = processed_obj[randomIdKey]; } - // 2. Create common computed properties for client-side sorting. + // 2. Create common computed properties const group = processed_obj.group ?? '0'; const priority = processed_obj.priority ? 1 : 0; const sort = processed_obj.sort ?? '0'; @@ -182,7 +176,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)); } @@ -193,8 +186,8 @@ async function _process_generic_props>({ return processed_obj_li; } -// Updated 2024-03-29 -async function load_ae_obj_id__sponsorship_cfg({ +// Updated 2026-01-20 to V3 +export async function load_ae_obj_id__sponsorship_cfg({ api_cfg, sponsorship_cfg_id, try_cache = false, @@ -202,85 +195,41 @@ async function load_ae_obj_id__sponsorship_cfg({ }: { api_cfg: any; sponsorship_cfg_id: string; - try_cache: boolean; - log_lvl: number; -}) { + try_cache?: boolean; + log_lvl?: number; +}): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}` - ); + console.log(`*** load_ae_obj_id__sponsorship_cfg() *** [V3] id=${sponsorship_cfg_id}`); } - const params = {}; + const sponsorship_cfg_obj_get_result = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'sponsorship_cfg', + obj_id: sponsorship_cfg_id, + log_lvl + }); - ae_promises.load__sponsorship_cfg_obj = api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'sponsorship_cfg', - obj_id: sponsorship_cfg_id, - use_alt_table: false, // 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, - log_lvl: log_lvl - }) - .then(async function (sponsorship_cfg_obj_get_result) { - if (sponsorship_cfg_obj_get_result) { - if (log_lvl) { - console.log( - `*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}` - ); - } else if (log_lvl > 1) { - console.log( - `*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}:`, - sponsorship_cfg_obj_get_result - ); - } - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({ - obj_li: [sponsorship_cfg_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_sponsorships, - table_name: 'cfg', - obj_li: processed_obj_li, - properties_to_save: properties_to_save_sponsorship_cfg, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - } - return sponsorship_cfg_obj_get_result; - } else { - console.log('No results returned.'); - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }); - - if (log_lvl) { - console.log( - 'ae_promises.load__sponsorship_cfg_obj:', - ae_promises.load__sponsorship_cfg_obj - ); + if (sponsorship_cfg_obj_get_result) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({ + obj_li: [sponsorship_cfg_obj_get_result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_sponsorships, + table_name: 'cfg', + obj_li: processed_obj_li, + properties_to_save: properties_to_save_sponsorship_cfg, + log_lvl + }); + } + return sponsorship_cfg_obj_get_result; } - - return ae_promises.load__sponsorship_cfg_obj; + return null; } -// Updated 2024-03-29 -async function load_ae_obj_id__sponsorship({ +// Updated 2026-01-20 to V3 +export async function load_ae_obj_id__sponsorship({ api_cfg, sponsorship_id, try_cache = false, @@ -288,78 +237,41 @@ async function load_ae_obj_id__sponsorship({ }: { api_cfg: any; sponsorship_id: string; - try_cache: boolean; - log_lvl: number; -}) { + try_cache?: boolean; + log_lvl?: number; +}): Promise { if (log_lvl) { - console.log(`*** load_ae_obj_id__sponsorship() *** sponsorship_id=${sponsorship_id}`); + console.log(`*** load_ae_obj_id__sponsorship() *** [V3] id=${sponsorship_id}`); } - const params = {}; + const sponsorship_obj_get_result = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'sponsorship', + obj_id: sponsorship_id, + log_lvl + }); - ae_promises.load__sponsorship_obj = api - .get_ae_obj_id_crud({ - api_cfg: api_cfg, - obj_type: 'sponsorship', - obj_id: sponsorship_id, - use_alt_table: false, // 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, - log_lvl: log_lvl - }) - .then(async function (sponsorship_obj_get_result) { - if (sponsorship_obj_get_result) { - if (log_lvl) { - console.log(`*spons_func* Got a result for sponsorship_id ${sponsorship_id}`); - } else if (log_lvl > 1) { - console.log( - `*spons_func* Got a result for sponsorship_id ${sponsorship_id}:`, - sponsorship_obj_get_result - ); - } - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__sponsorship_props({ - obj_li: [sponsorship_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_sponsorships, - table_name: 'sponsorship', - obj_li: processed_obj_li, - properties_to_save: properties_to_save_sponsorship, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - } - return sponsorship_obj_get_result; - } else { - console.log('No results returned.'); - return null; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }); - - if (log_lvl) { - console.log('ae_promises.load__sponsorship_obj:', ae_promises.load__sponsorship_obj); + if (sponsorship_obj_get_result) { + if (try_cache) { + const processed_obj_li = await process_ae_obj__sponsorship_props({ + obj_li: [sponsorship_obj_get_result], + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_sponsorships, + table_name: 'sponsorship', + obj_li: processed_obj_li, + properties_to_save: properties_to_save_sponsorship, + log_lvl + }); + } + return sponsorship_obj_get_result; } - - return ae_promises.load__sponsorship_obj; + return null; } -// Updated 2025-01-15 -async function load_ae_obj_li__sponsorship({ +// Updated 2026-01-20 to V3 +export async function load_ae_obj_li__sponsorship({ api_cfg, for_obj_type = 'account', for_obj_id, @@ -367,146 +279,165 @@ async function load_ae_obj_li__sponsorship({ hidden = 'not_hidden', limit = 99, offset = 0, - order_by_li = { - priority: 'DESC', - sort: 'DESC', - name: 'ASC', - updated_on: 'DESC', - created_on: 'DESC' - }, - params = {}, + order_by_li = [ + { priority: 'DESC' }, + { sort: 'DESC' }, + { name: 'ASC' }, + { updated_on: 'DESC' } + ], try_cache = true, log_lvl = 0 }: { api_cfg: any; for_obj_type: string; for_obj_id: string; - inc_content_li?: boolean; - enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; - hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; limit?: number; offset?: number; - order_by_li?: key_val; - params?: key_val; + order_by_li?: any; try_cache?: boolean; log_lvl?: number; -}) { +}): Promise { if (log_lvl) { - console.log( - `*** load_ae_obj_li__sponsorship() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}` - ); + console.log(`*** load_ae_obj_li__sponsorship() *** [V3] for=${for_obj_type}:${for_obj_id}`); } - const params_json: key_val = {}; + const result_li = await api.get_ae_obj_li_v3({ + api_cfg, + obj_type: 'sponsorship', + for_obj_type, + for_obj_id, + enabled, + hidden, + limit, + offset, + order_by_li, + log_lvl + }); - ae_promises.load__sponsorship_obj_li = await api - .get_ae_obj_li_for_obj_id_crud_v2({ - api_cfg: api_cfg, - obj_type: 'sponsorship', - 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 - }) - .then(async function (sponsorship_obj_li_get_result) { - if (sponsorship_obj_li_get_result) { - if (try_cache) { - // Process the results first - const processed_obj_li = await process_ae_obj__sponsorship_props({ - obj_li: sponsorship_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_sponsorships, - table_name: 'sponsorship', - obj_li: processed_obj_li, - properties_to_save: properties_to_save_sponsorship, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log('DB save completed.'); - } - } - return sponsorship_obj_li_get_result; - } else { - return []; - } + if (result_li && try_cache) { + const processed_obj_li = await process_ae_obj__sponsorship_props({ + obj_li: result_li, + log_lvl + }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_sponsorships, + table_name: 'sponsorship', + obj_li: processed_obj_li, + properties_to_save: properties_to_save_sponsorship, + log_lvl }); - - if (log_lvl) { - console.log('ae_promises.load__sponsorship_obj_li:', ae_promises.load__sponsorship_obj_li); } - return ae_promises.load__sponsorship_obj_li; + return result_li || []; +} + +/** + * Create a new sponsorship (V3) + */ +export async function create_ae_obj__sponsorship({ + api_cfg, + data, + log_lvl = 0 +}: { + api_cfg: any; + data: any; + log_lvl?: number; +}) { + return await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'sponsorship', + data, + log_lvl + }); +} + +/** + * Update sponsorship (V3) + */ +export async function update_ae_obj__sponsorship({ + api_cfg, + sponsorship_id, + data, + log_lvl = 0 +}: { + api_cfg: any; + sponsorship_id: string; + data: any; + log_lvl?: number; +}) { + return await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'sponsorship', + obj_id: sponsorship_id, + data, + log_lvl + }); +} + +/** + * Delete sponsorship (V3) + */ +export async function delete_ae_obj__sponsorship({ + api_cfg, + sponsorship_id, + log_lvl = 0 +}: { + api_cfg: any; + sponsorship_id: string; + log_lvl?: number; +}) { + return await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'sponsorship', + obj_id: sponsorship_id, + log_lvl + }); } export async function download_export__sponsorship({ api_cfg, account_id, - file_type = 'CSV', // 'CSV' or 'Excel' - return_file = true, - filename = 'no_filename.csv', - auto_download = false, - params = {}, // key value object is expected + file_type = 'CSV', + filename = 'sponsorship_export.csv', + params = {}, log_lvl = 0 }: { api_cfg: any; account_id: string; file_type?: string; - return_file?: boolean; filename?: string; - auto_download?: boolean; params?: key_val; log_lvl?: number; }) { - console.log('*** stores_event_api.js: get_sponsorship_export() ***'); - + // V2 still used for exports as V3 generic doesn't have a standardized export wrapper yet const endpoint = `/v2/crud/sponsorship/list`; - params['for_obj_type'] = 'account'; - params['for_obj_id'] = account_id; + const query_params = { + ...params, + for_obj_type: 'account', + for_obj_id: account_id, + file_type, + return_file: true + }; - if (file_type == 'CSV' || file_type == 'Excel') { - params['file_type'] = file_type; - } - params['return_file'] = true; - - ae_promises.download__sponsorship_export_file = await api.get_object({ - api_cfg: api_cfg, - endpoint: endpoint, - params: params, - return_blob: return_file, - filename: filename, - auto_download: auto_download, - log_lvl: log_lvl + return await api.get_object({ + api_cfg, + endpoint, + params: query_params, + return_blob: true, + filename, + auto_download: true, + log_lvl }); - - console.log( - 'ae_promises.download__sponsorship_export_file:', - ae_promises.download__sponsorship_export_file - ); - return ae_promises.download__sponsorship_export_file; } -const export_obj = { - load_ae_obj_id__sponsorship_cfg: load_ae_obj_id__sponsorship_cfg, - load_ae_obj_id__sponsorship: load_ae_obj_id__sponsorship, - load_ae_obj_li__sponsorship: load_ae_obj_li__sponsorship, - download_export__sponsorship: download_export__sponsorship -}; -export const spons_func = export_obj; +export const spons_func = { + load_ae_obj_id__sponsorship_cfg, + load_ae_obj_id__sponsorship, + load_ae_obj_li__sponsorship, + create_ae_obj__sponsorship, + update_ae_obj__sponsorship, + delete_ae_obj__sponsorship, + download_export__sponsorship +}; \ No newline at end of file