Modernize(Events/Sponsorships): Full V3 API Migration and ID Hardening

- API Migration: Refactored Event (Device, Location, Session, Presentation, Presenter, File, Exhibit, BadgeTemplate) and Sponsorship modules to use AE API CRUD V3.
- ID Hardening: Ensured all nested collection loads and searches use 'id_random' string identifiers to resolve 404 errors.
- Logic Consolidation: Unified property processing via '_process_generic_props'.
- Cleanup: Removed redundant '/admin' routes.
- Stability: Maintained V2 isolation for IDAA search.
This commit is contained in:
Scott Idem
2026-01-21 12:44:13 -05:00
parent cd06fb79e8
commit 2f2a1a87dc
10 changed files with 1719 additions and 4083 deletions

View File

@@ -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<ae_EventLocation | null> {
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<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
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<ae_EventLocation[]> {
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<ae_EventLocation | null> {
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<ae_EventLocation | null> {
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<ae_EventLocation[] | false> {
}): Promise<ae_EventLocation[]> {
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<T extends Record<string, any>>({
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
});
}