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

@@ -103,7 +103,7 @@ export async function load_ae_obj_id__event({
* Shared logic for loading nested child collections * 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) { 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) { if (inc_device_li) {
event_obj.event_device_obj_li = await load_ae_obj_li__event_device({ event_obj.event_device_obj_li = await load_ae_obj_li__event_device({

View File

@@ -49,7 +49,6 @@ export const properties_to_save = [
/** /**
* NON-EXPORTED LOCAL HELPER * NON-EXPORTED LOCAL HELPER
* Processes a list of Aether objects by applying common and specific transformations.
*/ */
async function _process_generic_props<T extends Record<string, any>>({ async function _process_generic_props<T extends Record<string, any>>({
obj_li, obj_li,
@@ -99,7 +98,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li; return processed_obj_li;
} }
// --- PROCESS FUNCTION ---
export async function process_ae_badge_template_props({ export async function process_ae_badge_template_props({
obj_li, obj_li,
log_lvl = 0 log_lvl = 0
@@ -110,49 +108,36 @@ export async function process_ae_badge_template_props({
return _process_generic_props({ return _process_generic_props({
obj_li, obj_li,
obj_type: 'event_badge_template', obj_type: 'event_badge_template',
log_lvl, 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;
}
}); });
} }
// --- CRUD FUNCTIONS --- // Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_badge_template({ export async function load_ae_obj_id__event_badge_template({
api_cfg, api_cfg,
event_badge_template_id, event_badge_template_id,
view = 'default',
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_badge_template_id: string; event_badge_template_id: string;
view?: string;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_id__event_badge_template() *** [V3] id=${event_badge_template_id}`);
`*** load_ae_obj_id__event_badge_template() *** event_badge_template_id=${event_badge_template_id}`
);
} }
try { try {
ae_promises.load__event_badge_template_obj = await api ae_promises.load__event_badge_template_obj = await api.get_ae_obj_v3({
.get_ae_obj_id_crud({ api_cfg,
api_cfg, obj_type: 'event_badge_template',
obj_type: 'event_badge_template', obj_id: event_badge_template_id,
obj_id: event_badge_template_id, view,
use_alt_table: false, log_lvl
use_alt_base: false, });
params: {},
log_lvl
});
if (ae_promises.load__event_badge_template_obj) { if (ae_promises.load__event_badge_template_obj) {
if (try_cache) { if (try_cache) {
@@ -168,69 +153,58 @@ export async function load_ae_obj_id__event_badge_template({
log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
if (try_cache) { ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id);
ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id);
}
} }
} catch (error: any) { } catch (error: any) {
if (try_cache) { if (try_cache) {
ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id); 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({ export async function load_ae_obj_li__event_badge_template({
api_cfg, api_cfg,
event_id, event_id,
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 49, limit = 50,
offset = 0, offset = 0,
order_by_li = { order_by_li = [
priority: 'DESC', { priority: 'DESC' },
sort: 'DESC', { sort: 'DESC' },
name: 'ASC', { name: 'ASC' },
updated_on: 'DESC', { updated_on: 'DESC' }
created_on: 'DESC' ],
} as const,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: string; event_id: string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number; limit?: number;
offset?: number; offset?: number;
order_by_li?: key_val; order_by_li?: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
try { try {
ae_promises.load__event_badge_template_obj_li = await api ae_promises.load__event_badge_template_obj_li = await api.get_ae_obj_li_v3({
.get_ae_obj_li_for_obj_id_crud_v2({ api_cfg,
api_cfg, obj_type: 'event_badge_template',
obj_type: 'event_badge_template', for_obj_type: 'event',
for_obj_type: 'event', for_obj_id: event_id,
for_obj_id: event_id, enabled,
use_alt_tbl: false, hidden,
use_alt_mdl: false, limit,
enabled, offset,
hidden, order_by_li,
order_by_li, log_lvl
limit, });
offset,
params_json: {},
params,
log_lvl
});
if (ae_promises.load__event_badge_template_obj_li) { if (ae_promises.load__event_badge_template_obj_li) {
if (try_cache) { if (try_cache) {
@@ -246,226 +220,190 @@ export async function load_ae_obj_li__event_badge_template({
log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
if (try_cache) { ae_promises.load__event_badge_template_obj_li = await db_events.badge_template
ae_promises.load__event_badge_template_obj_li = await db_events.badge_template .where('event_id').equals(event_id)
.where('event_id').equals(event_id) .toArray();
.toArray();
} else {
ae_promises.load__event_badge_template_obj_li = [];
}
} }
} catch (error: any) { } catch (error: any) {
if (try_cache) { if (try_cache) {
ae_promises.load__event_badge_template_obj_li = await db_events.badge_template ae_promises.load__event_badge_template_obj_li = await db_events.badge_template
.where('event_id').equals(event_id) .where('event_id').equals(event_id)
.toArray(); .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({ export async function create_ae_obj__event_badge_template({
api_cfg, api_cfg,
event_id, event_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: string; event_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
ae_promises.create__event_badge_template = await api const result = await api.create_ae_obj_v3({
.create_ae_obj_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_badge_template',
obj_type: 'event_badge_template', fields: {
fields: { event_id_random: event_id,
event_id_random: event_id, ...data_kv
...data_kv },
}, log_lvl
key: api_cfg.api_crud_super_key, });
params,
return_obj: true, if (result && try_cache) {
const processed_obj_li = await process_ae_badge_template_props({
obj_li: [result],
log_lvl 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({ export async function delete_ae_obj_id__event_badge_template({
api_cfg, api_cfg,
event_badge_template_id, event_badge_template_id,
method = 'delete', method = 'delete',
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_badge_template_id: string; event_badge_template_id: string;
method?: string; method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
ae_promises.delete__event_badge_template_obj = await api const result = await api.delete_ae_obj_v3({
.delete_ae_obj_id_crud({ api_cfg,
api_cfg, obj_type: 'event_badge_template',
obj_type: 'event_badge_template', obj_id: event_badge_template_id,
obj_id: event_badge_template_id, method,
key: api_cfg.api_crud_super_key, log_lvl
params, });
method,
log_lvl if (try_cache) {
}) await db_events.badge_template.delete(event_badge_template_id);
.finally(function () { }
if (try_cache) { return result;
db_events.badge_template.delete(event_badge_template_id);
}
});
return ae_promises.delete__event_badge_template_obj;
} }
// Updated 2026-01-20 to V3
export async function update_ae_obj__event_badge_template({ export async function update_ae_obj__event_badge_template({
api_cfg, api_cfg,
event_badge_template_id, event_badge_template_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_badge_template_id: string; event_badge_template_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
ae_promises.update__event_badge_template_obj = await api const result = await api.update_ae_obj_v3({
.update_ae_obj_id_crud({ api_cfg,
api_cfg, obj_type: 'event_badge_template',
obj_type: 'event_badge_template', obj_id: event_badge_template_id,
obj_id: event_badge_template_id, fields: data_kv,
fields: data_kv, log_lvl
key: api_cfg.api_crud_super_key, });
params,
return_obj: true, if (result && try_cache) {
const processed_obj_li = await process_ae_badge_template_props({
obj_li: [result],
log_lvl 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({ export async function search__event_badge_template({
api_cfg, api_cfg,
event_id, event_id,
fulltext_search_qry_str, qry_str = '',
like_search_qry_str = null,
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 25, limit = 25,
offset = 0, offset = 0,
order_by_li = { order_by_li = [
priority: 'DESC', { priority: 'DESC' },
sort: 'DESC', { sort: 'DESC' },
name: 'ASC', { name: 'ASC' },
updated_on: 'DESC', { updated_on: 'DESC' }
created_on: 'DESC' ],
} as const,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: string; event_id: string;
fulltext_search_qry_str?: null | string; qry_str?: string;
like_search_qry_str?: null | string; enabled?: 'enabled' | 'all' | 'not_enabled';
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
limit?: number; limit?: number;
offset?: number; offset?: number;
order_by_li?: key_val; order_by_li?: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
const params_json: key_val = {}; const search_query: any = {
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { q: qry_str,
params_json['ft_qry'] = { default_qry_str: fulltext_search_qry_str }; and: [{ field: 'event_id_random', op: 'eq', value: event_id }]
} };
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 if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true });
.get_ae_obj_li_for_obj_id_crud_v2({ else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false });
api_cfg,
obj_type: 'event_badge_template', if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true });
for_obj_type: 'event', else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false });
for_obj_id: event_id,
use_alt_tbl: false, const result_li = await api.search_ae_obj_v3({
use_alt_mdl: false, api_cfg,
enabled, obj_type: 'event_badge_template',
hidden, search_query,
order_by_li, order_by_li,
limit, limit,
offset, offset,
params_json, log_lvl
params, });
if (result_li && try_cache) {
const processed_obj_li = await process_ae_badge_template_props({
obj_li: result_li,
log_lvl 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 || [];
} }

View File

@@ -9,7 +9,7 @@ import { load_ae_obj_id__event_location } from './ae_events__event_location';
const ae_promises: key_val = {}; const ae_promises: key_val = {};
// Updated 2025-05-23 // Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_device({ export async function load_ae_obj_id__event_device({
api_cfg, api_cfg,
event_device_id, event_device_id,
@@ -24,22 +24,16 @@ export async function load_ae_obj_id__event_device({
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventDevice | null> { }): Promise<ae_EventDevice | null> {
if (log_lvl) { 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 { try {
ae_promises.load__event_device_obj = await api ae_promises.load__event_device_obj = await api.get_ae_obj_v3({
.get_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_device',
obj_type: 'event_device', obj_id: event_device_id,
obj_id: event_device_id, // NOTE: This is the FQDN, not normally the ID. log_lvl
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
});
if (ae_promises.load__event_device_obj) { if (ae_promises.load__event_device_obj) {
if (try_cache) { if (try_cache) {
@@ -56,39 +50,27 @@ export async function load_ae_obj_id__event_device({
}); });
} }
} else { } else {
console.log('No results returned from API.');
if (try_cache) { 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); ae_promises.load__event_device_obj = await db_events.device.get(event_device_id);
} }
} }
} catch (error: any) { } catch (error: any) {
console.log('API request failed.', error); console.log('V3 Request failed.', error);
if (try_cache) { 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); 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) { if (!ae_promises.load__event_device_obj) return null;
console.log('ae_promises.load__event_device_obj:', ae_promises.load__event_device_obj);
}
if (!ae_promises?.load__event_device_obj) {
return null;
}
if (inc_location_id) { if (inc_location_id) {
// Load the location linked to this device
const current_location_id = ae_promises.load__event_device_obj.event_location_id; const current_location_id = ae_promises.load__event_device_obj.event_location_id;
if (current_location_id) { if (current_location_id) {
ae_promises.load__event_device_obj.event_location_obj = await load_ae_obj_id__event_location({ 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, event_location_id: current_location_id,
try_cache: try_cache, try_cache,
log_lvl: log_lvl log_lvl
}); });
} }
} }
@@ -96,514 +78,306 @@ export async function load_ae_obj_id__event_device({
return ae_promises.load__event_device_obj; 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({ export async function load_ae_obj_li__event_device({
api_cfg, api_cfg,
for_obj_type, for_obj_type = 'event',
for_obj_id, for_obj_id,
inc_location_id = false, inc_location_id = false,
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 49, limit = 100,
offset = 0, offset = 0,
order_by_li = { order_by_li = [
priority: 'DESC', { priority: 'DESC' },
sort: 'DESC', { sort: 'DESC' },
name: 'ASC', { name: 'ASC' },
code: 'ASC', { updated_on: 'DESC' }
updated_on: 'DESC', ],
created_on: 'DESC'
} as const,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
for_obj_type: string; for_obj_type?: string;
for_obj_id: string; for_obj_id: string;
inc_location_id?: boolean; inc_location_id?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number; // 99 limit?: number;
offset?: number; // 0 offset?: number;
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[]; order_by_li?: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventDevice[]> { }): Promise<ae_EventDevice[]> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_li__event_device() *** [V3] for=${for_obj_type}:${for_obj_id}`);
`*** load_ae_obj_li__event_device() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
} }
const params_json: key_val = {};
try { try {
ae_promises.load__event_device_obj_li = await api ae_promises.load__event_device_obj_li = await api.get_ae_obj_li_v3({
.get_ae_obj_li_for_obj_id_crud_v2({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_device',
obj_type: 'event_device', for_obj_type,
for_obj_type: for_obj_type, for_obj_id,
for_obj_id: for_obj_id, enabled,
use_alt_tbl: true, hidden,
use_alt_mdl: false, limit,
use_alt_exp: false, offset,
enabled: enabled, order_by_li,
hidden: hidden, log_lvl
order_by_li: order_by_li, });
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
});
if (ae_promises.load__event_device_obj_li) { if (ae_promises.load__event_device_obj_li) {
if (try_cache) { if (try_cache) {
const processed_obj_li = await process_ae_obj__event_device_props({ const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: ae_promises.load__event_device_obj_li, obj_li: ae_promises.load__event_device_obj_li,
log_lvl: log_lvl log_lvl
}); });
await db_save_ae_obj_li__ae_obj({ await db_save_ae_obj_li__ae_obj({
db_instance: db_events, db_instance: db_events,
table_name: 'device', table_name: 'device',
obj_li: processed_obj_li, obj_li: processed_obj_li,
properties_to_save: properties_to_save, properties_to_save,
log_lvl: log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
console.log('No results returned from API.'); ae_promises.load__event_device_obj_li = await db_events.device
if (try_cache) { .where('event_id').equals(for_obj_id)
if (log_lvl) console.log('Attempting to load from local cache...'); .toArray();
ae_promises.load__event_device_obj_li = await db_events.device }
.where('event_id').equals(for_obj_id) } catch (error: any) {
.toArray(); console.log('V3 List Request failed.', error);
} else { if (try_cache) {
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...');
ae_promises.load__event_device_obj_li = await db_events.device ae_promises.load__event_device_obj_li = await db_events.device
.where('event_id').equals(for_obj_id) .where('event_id').equals(for_obj_id)
.toArray(); .toArray();
} else {
ae_promises.load__event_device_obj_li = [];
} }
} }
if (inc_location_id && 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++) { for (const device of ae_promises.load__event_device_obj_li) {
const event_device_obj = ae_promises.load__event_device_obj_li[i]; if (device.event_location_id) {
if (event_device_obj.event_location_id) { device.event_location_obj = await load_ae_obj_id__event_location({
event_device_obj.event_location_obj = await load_ae_obj_id__event_location({ api_cfg,
api_cfg: api_cfg, event_location_id: device.event_location_id,
event_location_id: event_device_obj.event_location_id, try_cache,
try_cache: try_cache, log_lvl
log_lvl: 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({ export async function create_ae_obj__event_device({
api_cfg, api_cfg,
event_id, event_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: string; event_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventDevice | null> { }): Promise<ae_EventDevice | null> {
if (log_lvl) { 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 const result = await api.create_ae_obj_v3({
.create_ae_obj_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_device',
obj_type: 'event_device', fields: {
fields: { event_id_random: event_id,
event_id_random: event_id, ...data_kv
...data_kv },
}, log_lvl
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.');
}
// db_save_ae_obj_li__event_device( if (result && try_cache) {
// { const processed_obj_li = await process_ae_obj__event_device_props({
// obj_type: 'event_device', obj_li: [result],
// obj_li: [event_device_obj_create_result] log_lvl
// }); });
} await db_save_ae_obj_li__ae_obj({
return event_device_obj_create_result; db_instance: db_events,
} else { table_name: 'device',
return null; obj_li: processed_obj_li,
} properties_to_save,
}) log_lvl
.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);
} }
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({ export async function delete_ae_obj_id__event_device({
api_cfg, api_cfg,
event_device_id, event_device_id,
method = 'delete', // 'delete', 'disable', 'hide' method = 'delete',
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_device_id: string; event_device_id: string;
method?: string; method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { 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 const result = await api.delete_ae_obj_v3({
.delete_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_device',
obj_type: 'event_device', obj_id: event_device_id,
obj_id: event_device_id, method,
key: api_cfg.api_crud_super_key, log_lvl
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);
}
});
if (log_lvl) { if (try_cache) {
console.log('ae_promises.delete__event_device_obj:', ae_promises.delete__event_device_obj); 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({ export async function update_ae_obj__event_device({
api_cfg, api_cfg,
event_device_id, event_device_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_device_id: string; event_device_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventDevice | null> { }): Promise<ae_EventDevice | null> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** update_ae_obj__event_device() *** [V3] id=${event_device_id}`);
`*** update_ae_obj__event_device() *** event_device_id=${event_device_id}`,
data_kv
);
} }
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({ const result = await api.update_ae_obj_v3({
// obj_type: 'event_device', obj_li: [event_device_obj_update_result] api_cfg,
// }); obj_type: 'event_device',
} obj_id: event_device_id,
return event_device_obj_update_result; fields: data_kv,
} else { log_lvl
return null; });
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) { if (result && try_cache) {
console.log('ae_promises.update__event_device_obj:', ae_promises.update__event_device_obj); 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 2026-01-20 to V3
// Updated 2025-05-23
export async function search__event_device({ export async function search__event_device({
api_cfg, api_cfg,
event_id, event_id,
fulltext_search_qry_str, qry_str = '',
ft_presenter_search_qry_str, enabled = 'enabled',
like_search_qry_str = null, hidden = 'not_hidden',
like_presentation_search_qry_str = null, limit = 25,
like_presenter_search_qry_str = null, offset = 0,
params = {}, order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: any; event_id: string;
fulltext_search_qry_str?: null | string; qry_str?: string;
ft_presenter_search_qry_str?: null | string; enabled?: 'enabled' | 'all' | 'not_enabled';
like_search_qry_str?: null | string; hidden?: 'hidden' | 'all' | 'not_hidden';
like_presentation_search_qry_str?: null | string; limit?: number;
like_presenter_search_qry_str?: null | string; offset?: number;
params?: any; order_by_li?: any;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventDevice[] | false> { }): Promise<ae_EventDevice[]> {
if (log_lvl) { 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 search_query: any = {
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; q: qry_str,
const limit: number = params.qry__limit ?? 25; // 99 and: [{ field: 'event_id_random', op: 'eq', value: event_id }]
const offset: number = params.qry__offset ?? 0; // 0 };
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) { if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true });
console.log('No search string provided!!!'); else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false });
return false; // Returning false instead of [] because no search was performed.
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) { return result_li || [];
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;
} }
// Updated 2025-05-23
export const properties_to_save = [ export const properties_to_save = [
'id', 'id',
'event_device_id', 'event_device_id',
// 'event_device_id_random',
'event_id', 'event_id',
// 'event_id_random',
'event_location_id', 'event_location_id',
// 'event_location_id_random',
'code', 'code',
'name', 'name',
'description', 'description',
'passcode', 'passcode',
'local_file_cache_path', 'local_file_cache_path',
'host_file_temp_path', 'host_file_temp_path',
'recording_path', 'recording_path',
'record_audio', 'record_audio',
'record_video', 'record_video',
'trigger_open_file_id', 'trigger_open_file_id',
'trigger_open_session_id', 'trigger_open_session_id',
'trigger_recording_start', 'trigger_recording_start',
@@ -611,7 +385,6 @@ export const properties_to_save = [
'trigger_reset', 'trigger_reset',
'trigger_show_admin', 'trigger_show_admin',
'trigger_show_hidden', 'trigger_show_hidden',
'alert', 'alert',
'alert_msg', 'alert_msg',
'alert_on', 'alert_on',
@@ -622,13 +395,10 @@ export const properties_to_save = [
'record_status_msg', 'record_status_msg',
'record_status_on', 'record_status_on',
'heartbeat', 'heartbeat',
'info_hostname', 'info_hostname',
'info_ip_list', 'info_ip_list',
'meta_json', 'meta_json',
'other_json', 'other_json',
'enable', 'enable',
'hide', 'hide',
'priority', 'priority',
@@ -637,14 +407,8 @@ export const properties_to_save = [
'notes', 'notes',
'created_on', 'created_on',
'updated_on', 'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1', 'tmp_sort_1',
'tmp_sort_2', 'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
'event_name', 'event_name',
'event_location_code', 'event_location_code',
'event_location_name' 'event_location_name'
@@ -665,39 +429,26 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number; log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T; specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> { }): Promise<T[]> {
if (log_lvl > 0) { if (!obj_li || obj_li.length === 0) return [];
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 [];
}
const processed_obj_li: T[] = []; const processed_obj_li: T[] = [];
for (const original_obj of obj_li) { for (const original_obj of obj_li) {
let processed_obj = { ...original_obj }; let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields // 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) { for (const key in processed_obj) {
if (key.endsWith('_random')) { 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]; (processed_obj as any)[newKey] = processed_obj[key];
} }
} }
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`; const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) { if (processed_obj[randomIdKey]) {
(processed_obj as any).id = 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 group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0; const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0'; const sort = processed_obj.sort ?? '0';
@@ -707,7 +458,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`; (processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) { if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj)); processed_obj = await Promise.resolve(specific_processor(processed_obj));
} }
@@ -718,7 +468,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li; return processed_obj_li;
} }
// Updated 2025-05-23
export async function process_ae_obj__event_device_props({ export async function process_ae_obj__event_device_props({
obj_li, obj_li,
log_lvl = 0 log_lvl = 0
@@ -731,19 +480,9 @@ export async function process_ae_obj__event_device_props({
obj_type: 'event_device', obj_type: 'event_device',
log_lvl, log_lvl,
specific_processor: (obj) => { specific_processor: (obj) => {
// Special handling for heartbeat timestamp
if (obj.heartbeat) { if (obj.heartbeat) {
obj.heartbeat = obj.heartbeat + 'Z'; 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; return obj;
} }
}); });

View File

@@ -7,114 +7,92 @@ import type { ae_EventFile } from '$lib/types/ae_types';
const ae_promises: key_val = {}; const ae_promises: key_val = {};
// Updated 2025-07-21 // Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_file({ export async function load_ae_obj_id__event_file({
api_cfg, api_cfg,
event_file_id, event_file_id,
view = 'default',
try_cache = false, try_cache = false,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_file_id: string; event_file_id: string;
view?: string;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventFile | null> { }): Promise<ae_EventFile | null> {
if (log_lvl) { 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 = {}; try {
ae_promises.load__event_file_obj = await api.get_ae_obj_v3({
ae_promises.load__event_file_obj = await api api_cfg,
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_file', obj_type: 'event_file',
obj_id: event_file_id, // NOTE: This is the FQDN, not normally the ID. obj_id: event_file_id,
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. view,
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value log_lvl
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);
}); });
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({ export async function load_ae_obj_li__event_file({
api_cfg, api_cfg,
for_obj_type, for_obj_type,
for_obj_id, for_obj_id,
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 99, limit = 100,
offset = 0, offset = 0,
order_by_li = { order_by_li = [
priority: 'DESC', { priority: 'DESC' },
sort: 'DESC', { sort: 'DESC' },
updated_on: 'DESC', { updated_on: 'DESC' }
created_on: 'DESC' ],
} as const,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
for_obj_type: string; for_obj_type: string;
for_obj_id: string; for_obj_id: string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number; // 99 limit?: number;
offset?: number; // 0 offset?: number;
order_by_li?: key_val; order_by_li?: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventFile[]> { }): Promise<ae_EventFile[]> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_li__event_file() *** [V3] for=${for_obj_type}:${for_obj_id}`);
`*** load_ae_obj_li__event_file() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
} }
// Check if for_obj_type is in the list of valid Aether object types:
const valid_for_obj_types = [ const valid_for_obj_types = [
'event', 'event',
'event_session', 'event_session',
@@ -129,74 +107,55 @@ export async function load_ae_obj_li__event_file({
return []; return [];
} }
const params_json: key_val = {}; try {
ae_promises.load__event_file_obj_li = await api.get_ae_obj_li_v3({
// console.log('params_json:', params_json); api_cfg,
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', obj_type: 'event_file',
for_obj_type: for_obj_type, for_obj_type,
for_obj_id: 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,
use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value hidden,
use_alt_exp: false, limit,
enabled: enabled, offset,
hidden: hidden, order_by_li,
order_by_li: order_by_li, log_lvl
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);
}); });
if (log_lvl) { if (ae_promises.load__event_file_obj_li) {
console.log('ae_promises.load__event_file_obj_li:', 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({ export async function create_event_file_obj_from_hosted_file_async({
api_cfg, api_cfg,
hosted_file_id, hosted_file_id,
@@ -204,7 +163,6 @@ export async function create_event_file_obj_from_hosted_file_async({
data = {}, data = {},
return_obj = false, return_obj = false,
inc_hosted_file = false, inc_hosted_file = false,
return_meta = false,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
@@ -213,57 +171,28 @@ export async function create_event_file_obj_from_hosted_file_async({
data?: key_val; data?: key_val;
return_obj?: boolean; return_obj?: boolean;
inc_hosted_file?: boolean; inc_hosted_file?: boolean;
return_meta?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { if (!hosted_file_id) return false;
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;
}
const endpoint = `/event/file/from_hosted_file/${hosted_file_id}`; const endpoint = `/event/file/from_hosted_file/${hosted_file_id}`;
if (return_obj) { const query_params = { ...params };
params['return_obj'] = true; if (return_obj) query_params['return_obj'] = true;
} if (inc_hosted_file) query_params['inc_hosted_file'] = 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;
});
// console.log(event_file_obj_post_promise); const result = await api.post_object({
if (return_obj) { api_cfg,
return event_file_obj_post_promise; endpoint,
} else { params: query_params,
return event_file_obj_post_promise.event_file_id_random; 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({ export async function delete_ae_obj_id__event_file({
api_cfg, api_cfg,
event_file_id, event_file_id,
@@ -277,42 +206,23 @@ export async function delete_ae_obj_id__event_file({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { // V3 delete handles orphans via policy or explicit params
console.log(`*** delete_ae_obj_id__event_file() *** event_file_id=${event_file_id}`); 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`; return result;
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;
} }
// Updated 2025-07-21 // Updated 2026-01-20 to V3
export async function update_ae_obj__event_file({ export async function update_ae_obj__event_file({
api_cfg, api_cfg,
event_file_id, event_file_id,
@@ -328,401 +238,116 @@ export async function update_ae_obj__event_file({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventFile | null> { }): Promise<ae_EventFile | null> {
if (log_lvl) { const result = await api.update_ae_obj_v3({
console.log(`*** update_ae_obj__event_file() *** event_file_id=${event_file_id}`); api_cfg,
}
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_file', 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, fields: data_kv,
key: api_cfg.api_crud_super_key, params,
params: params, log_lvl
return_obj: true,
log_lvl: 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({ if (result && try_cache) {
// obj_type: 'event_file', const processed_obj_li = await process_ae_obj__event_file_props({
// obj_li: [result], obj_li: [result],
// log_lvl: log_lvl, log_lvl
// }); });
} await db_save_ae_obj_li__ae_obj({
return result; db_instance: db_events,
} else { table_name: 'file',
console.error('Failed to update event file.'); obj_li: processed_obj_li,
return null; properties_to_save,
} log_lvl
}
// 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<ae_EventFile[]> {
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 (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({ export async function search__event_file({
api_cfg, api_cfg,
event_id, event_id,
created_on = null, qry_str = '',
min_file_size = null, min_file_size = null,
fulltext_search_qry_str, enabled = 'enabled',
ft_file_search_qry_str, hidden = 'not_hidden',
like_search_qry_str = null, limit = 25,
like_presentation_search_qry_str = null, offset = 0,
like_file_search_qry_str = null, order_by_li = [
order_by_li = { { priority: 'DESC' },
priority: 'DESC', { sort: 'DESC' },
sort: 'DESC', { updated_on: 'DESC' }
created_on: 'DESC', ],
updated_on: 'DESC',
filename: 'ASC',
extension: 'ASC',
hosted_file_size: 'ASC'
} as const,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: any; event_id: string;
created_on?: null | string; qry_str?: string;
min_file_size?: null | number; min_file_size?: null | number;
fulltext_search_qry_str?: null | string; enabled?: 'enabled' | 'all' | 'not_enabled';
ft_file_search_qry_str?: null | string; hidden?: 'hidden' | 'all' | 'not_hidden';
like_search_qry_str?: null | string; limit?: number;
like_presentation_search_qry_str?: null | string; offset?: number;
like_file_search_qry_str?: null | string; order_by_li?: any;
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
params?: any;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventFile[]> { }): Promise<ae_EventFile[]> {
if (log_lvl) { const search_query: any = {
console.log(`*** search__event_file() *** event_id=${event_id}`); q: qry_str,
} and: [{ field: 'event_id_random', op: 'eq', value: 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;
// }
if (min_file_size) { 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 const result_li = await api.search_ae_obj_v3({
.get_ae_obj_li_for_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_file',
obj_type: 'event_file', search_query,
for_obj_type: 'event', order_by_li,
for_obj_id: event_id, limit,
use_alt_table: true, // NOTE: We want to use the alt table for file searching? offset,
use_alt_base: false, log_lvl
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}); if (result_li && try_cache) {
} const processed_obj_li = await process_ae_obj__event_file_props({
return event_file_obj_li_get_result; obj_li: result_li,
} else { log_lvl
return []; });
} await db_save_ae_obj_li__ae_obj({
}) db_instance: db_events,
.catch(function (error: any) { table_name: 'file',
console.log('No results returned or failed.', error); obj_li: processed_obj_li,
}) properties_to_save,
.finally(function () {}); 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_li || [];
} }
// Updated 2025-05-23
export const properties_to_save = [ export const properties_to_save = [
'id', 'id',
// 'id_random',
'event_file_id', 'event_file_id',
// 'event_file_id_random',
'hosted_file_id', 'hosted_file_id',
// 'hosted_file_id_random',
'hash_sha256', 'hash_sha256',
'for_type', 'for_type',
'for_id', 'for_id',
// 'for_id_random',
'event_id', 'event_id',
// 'event_id_random',
'event_session_id', 'event_session_id',
// 'event_session_id_random',
'event_presentation_id', 'event_presentation_id',
// 'event_presentation_id_random',
'event_presenter_id', 'event_presenter_id',
// 'event_presenter_id_random',
'event_location_id', 'event_location_id',
// 'event_location_id_random',
'filename', 'filename',
'extension', 'extension',
'open_in_os', 'open_in_os',
'lu_file_purpose_id', 'lu_file_purpose_id',
'lu_event_file_purpose_name', 'lu_event_file_purpose_name',
'file_purpose', 'file_purpose',
'enable', 'enable',
'hide', 'hide',
'priority', 'priority',
@@ -731,19 +356,13 @@ export const properties_to_save = [
'notes', 'notes',
'created_on', 'created_on',
'updated_on', 'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1', 'tmp_sort_1',
'tmp_sort_2', 'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
'filename_no_ext', 'filename_no_ext',
'filename_w_ext', 'filename_w_ext',
'hosted_file_content_type', 'hosted_file_content_type',
'file_size', 'file_size',
'hosted_file_size', 'hosted_file_size',
'event_location_code', 'event_location_code',
'event_location_name', 'event_location_name',
'event_session_code', 'event_session_code',
@@ -764,7 +383,6 @@ export const properties_to_save = [
/** /**
* NON-EXPORTED LOCAL HELPER * NON-EXPORTED LOCAL HELPER
* Processes a list of Aether objects by applying common and specific transformations.
*/ */
async function _process_generic_props<T extends Record<string, any>>({ async function _process_generic_props<T extends Record<string, any>>({
obj_li, obj_li,
@@ -777,39 +395,24 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number; log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T; specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> { }): Promise<T[]> {
if (log_lvl > 0) { if (!obj_li || obj_li.length === 0) return [];
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 [];
}
const processed_obj_li: T[] = []; const processed_obj_li: T[] = [];
for (const original_obj of obj_li) { for (const original_obj of obj_li) {
let processed_obj = { ...original_obj }; 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) { for (const key in processed_obj) {
if (key.endsWith('_random')) { 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]; (processed_obj as any)[newKey] = processed_obj[key];
} }
} }
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`; const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) { if (processed_obj[randomIdKey]) {
(processed_obj as any).id = 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 group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0; const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0'; const sort = processed_obj.sort ?? '0';
@@ -819,7 +422,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`; (processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) { if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj)); processed_obj = await Promise.resolve(specific_processor(processed_obj));
} }
@@ -830,7 +432,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li; return processed_obj_li;
} }
// Updated 2025-05-23
export async function process_ae_obj__event_file_props({ export async function process_ae_obj__event_file_props({
obj_li, obj_li,
log_lvl = 0 log_lvl = 0
@@ -841,17 +442,6 @@ export async function process_ae_obj__event_file_props({
return _process_generic_props({ return _process_generic_props({
obj_li, obj_li,
obj_type: 'event_file', obj_type: 'event_file',
log_lvl, 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;
}
}); });
} }

View File

@@ -11,13 +11,14 @@ import { load_ae_obj_li__event_session } from './ae_events__event_session';
const ae_promises: key_val = {}; const ae_promises: key_val = {};
// Updated 2026-01-16 // Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_location({ export async function load_ae_obj_id__event_location({
api_cfg, api_cfg,
event_location_id, event_location_id,
inc_device_li = false, inc_device_li = false,
inc_file_li = false, inc_file_li = false,
inc_session_li = false, inc_session_li = false,
view = 'default',
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
@@ -26,38 +27,34 @@ export async function load_ae_obj_id__event_location({
inc_device_li?: boolean; inc_device_li?: boolean;
inc_file_li?: boolean; inc_file_li?: boolean;
inc_session_li?: boolean; inc_session_li?: boolean;
view?: string;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventLocation | null> { }): Promise<ae_EventLocation | null> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_id__event_location() *** [V3] id=${event_location_id}`);
`*** load_ae_obj_id__event_location() *** event_location_id=${event_location_id}`
);
} }
const params = {};
// Check if offline // Check if offline
if (typeof navigator !== 'undefined' && !navigator.onLine) { if (typeof navigator !== 'undefined' && !navigator.onLine) {
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.'); 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); ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
if (ae_promises.load__event_location_obj) { 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; return null;
} }
try { try {
ae_promises.load__event_location_obj = await api ae_promises.load__event_location_obj = await api.get_ae_obj_v3({
.get_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_location',
obj_type: 'event_location', obj_id: event_location_id,
obj_id: event_location_id, // NOTE: This is the FQDN, not normally the ID. view,
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. log_lvl
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
});
if (ae_promises.load__event_location_obj) { if (ae_promises.load__event_location_obj) {
if (try_cache) { if (try_cache) {
@@ -73,121 +70,104 @@ export async function load_ae_obj_id__event_location({
log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
console.log('No results returned from API.'); ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
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);
}
} }
} catch (error: any) { } catch (error: any) {
console.log('API request failed.', error); console.log('V3 Request failed.', error);
if (try_cache) { 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); 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) { if (!ae_promises.load__event_location_obj) return null;
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 * 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) { 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) { if (inc_device_li) {
location_obj.event_device_obj_li = await load_ae_obj_li__event_device({ 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_type: 'event_location',
for_obj_id: current_location_id, for_obj_id: current_location_id,
log_lvl: log_lvl log_lvl
}); });
} }
if (inc_file_li) { if (inc_file_li) {
// Load the files for the location
location_obj.event_file_li = await load_ae_obj_li__event_file({ 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_type: 'event_location',
for_obj_id: current_location_id, for_obj_id: current_location_id,
enabled: 'all', enabled: 'all',
limit: 15, limit: 15,
try_cache: try_cache, try_cache,
log_lvl: log_lvl log_lvl
}); });
} }
if (inc_session_li) { if (inc_session_li) {
// Load the sessions for the location
location_obj.event_session_li = await load_ae_obj_li__event_session({ 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_type: 'event_location',
for_obj_id: current_location_id, for_obj_id: current_location_id,
enabled: 'all', enabled: 'all',
limit: 15, limit: 15,
try_cache: try_cache, try_cache,
log_lvl: log_lvl log_lvl
}); });
} }
return location_obj; return location_obj;
} }
// Updated 2025-05-23 // Updated 2026-01-20 to V3
export async function load_ae_obj_li__event_location({ export async function load_ae_obj_li__event_location({
api_cfg, api_cfg,
for_obj_type, for_obj_type = 'event',
for_obj_id, for_obj_id,
inc_device_li = false, inc_device_li = false,
inc_file_li = false, inc_file_li = false,
inc_session_li = false, inc_session_li = false,
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 29, limit = 50,
offset = 0, offset = 0,
order_by_li = { order_by_li = [
priority: 'DESC', { priority: 'DESC' },
sort: 'DESC', { sort: 'DESC' },
name: 'ASC', { name: 'ASC' },
code: 'ASC', { updated_on: 'DESC' }
updated_on: 'DESC', ],
created_on: 'DESC'
},
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
for_obj_type: string; for_obj_type?: string;
for_obj_id: string; for_obj_id: string;
inc_device_li?: boolean; inc_device_li?: boolean;
inc_file_li?: boolean; inc_file_li?: boolean;
inc_session_li?: boolean; inc_session_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number; // 99 limit?: number;
offset?: number; // 0 offset?: number;
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[]; order_by_li?: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventLocation[]> { }): Promise<ae_EventLocation[]> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_li__event_location() *** [V3] for=${for_obj_type}:${for_obj_id}`);
`*** load_ae_obj_li__event_location() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
} }
const params_json: key_val = {};
// Check if offline // Check if offline
if (typeof navigator !== 'undefined' && !navigator.onLine) { if (typeof navigator !== 'undefined' && !navigator.onLine) {
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.'); 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) .where('event_id').equals(for_obj_id)
.toArray(); .toArray();
if (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++) { for (const loc of ae_promises.load__event_location_obj_li) {
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 }); 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 || [];
} }
try { try {
ae_promises.load__event_location_obj_li = await api ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_v3({
.get_ae_obj_li_for_obj_id_crud_v2({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_location',
obj_type: 'event_location', for_obj_type,
for_obj_type: for_obj_type, for_obj_id,
for_obj_id: for_obj_id, enabled,
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. hidden,
enabled: enabled, limit,
hidden: hidden, offset,
order_by_li: order_by_li, order_by_li,
limit: limit, log_lvl
offset: offset, });
params_json: params_json,
params: params,
log_lvl: log_lvl
});
if (ae_promises.load__event_location_obj_li) { if (ae_promises.load__event_location_obj_li) {
if (try_cache) { if (try_cache) {
const processed_obj_li = await process_ae_obj__event_location_props({ const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: ae_promises.load__event_location_obj_li, obj_li: ae_promises.load__event_location_obj_li,
log_lvl: log_lvl log_lvl
}); });
await db_save_ae_obj_li__ae_obj({ await db_save_ae_obj_li__ae_obj({
db_instance: db_events, db_instance: db_events,
table_name: 'location', table_name: 'location',
obj_li: processed_obj_li, obj_li: processed_obj_li,
properties_to_save: properties_to_save, properties_to_save,
log_lvl: log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
console.log('No results returned from API.'); ae_promises.load__event_location_obj_li = await db_events.location
if (try_cache) { .where('event_id').equals(for_obj_id)
if (log_lvl) console.log('Attempting to load from local cache...'); .toArray();
ae_promises.load__event_location_obj_li = await db_events.location }
.where('event_id').equals(for_obj_id) } catch (error: any) {
.toArray(); console.log('V3 List Request failed.', error);
} else { if (try_cache) {
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...');
ae_promises.load__event_location_obj_li = await db_events.location ae_promises.load__event_location_obj_li = await db_events.location
.where('event_id').equals(for_obj_id) .where('event_id').equals(for_obj_id)
.toArray(); .toArray();
} else {
ae_promises.load__event_location_obj_li = [];
} }
} }
if (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++) { for (const loc of ae_promises.load__event_location_obj_li) {
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 }); 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({ export async function create_ae_obj__event_location({
api_cfg, api_cfg,
event_id, event_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: string; event_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventLocation | null> { }): Promise<ae_EventLocation | null> {
if (log_lvl) { 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 const result = await api.create_ae_obj_v3({
.create_ae_obj_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_location',
obj_type: 'event_location', fields: {
fields: { event_id_random: event_id,
event_id_random: event_id, ...data_kv
...data_kv },
}, log_lvl
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);
});
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({ export async function delete_ae_obj_id__event_location({
api_cfg, api_cfg,
event_location_id, event_location_id,
method = 'delete', // 'delete', 'disable', 'hide' method = 'delete',
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_location_id: string; event_location_id: string;
method?: string; method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** delete_ae_obj_id__event_location() *** [V3] id=${event_location_id}`);
`*** delete_ae_obj_id__event_location() *** event_location_id=${event_location_id}`
);
} }
ae_promises.delete__event_location_obj = await api const result = await api.delete_ae_obj_v3({
.delete_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_location',
obj_type: 'event_location', obj_id: event_location_id,
obj_id: event_location_id, method,
key: api_cfg.api_crud_super_key, log_lvl
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);
}
});
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({ export async function update_ae_obj__event_location({
api_cfg, api_cfg,
event_location_id, event_location_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_location_id: string; event_location_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventLocation | null> { }): Promise<ae_EventLocation | null> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** update_ae_obj__event_location() *** [V3] id=${event_location_id}`);
`*** update_ae_obj__event_location() *** event_location_id=${event_location_id}`,
data_kv
);
} }
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({ export async function search__event_location({
api_cfg, api_cfg,
event_id, event_id,
fulltext_search_qry_str, qry_str = '',
ft_presenter_search_qry_str, enabled = 'enabled',
like_search_qry_str = null, hidden = 'not_hidden',
like_presentation_search_qry_str = null, limit = 25,
like_presenter_search_qry_str = null, offset = 0,
params = {}, order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: any; event_id: string;
fulltext_search_qry_str?: null | string; qry_str?: string;
ft_presenter_search_qry_str?: null | string; enabled?: 'enabled' | 'all' | 'not_enabled';
like_search_qry_str?: null | string; hidden?: 'hidden' | 'all' | 'not_hidden';
like_presentation_search_qry_str?: null | string; limit?: number;
like_presenter_search_qry_str?: null | string; offset?: number;
params?: any; order_by_li?: any;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventLocation[] | false> { }): Promise<ae_EventLocation[]> {
if (log_lvl) { 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 search_query: any = {
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; q: qry_str,
const limit: number = params.qry__limit ?? 25; and: [{ field: 'event_id_random', op: 'eq', value: event_id }]
const offset: number = params.qry__offset ?? 0; };
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) { if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true });
console.log('No search string provided!!!'); else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false });
return false;
}
if (fulltext_search_qry_str || ft_presenter_search_qry_str) { const result_li = await api.search_ae_obj_v3({
params_json['ft_qry'] = {}; api_cfg,
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { obj_type: 'event_location',
params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str; search_query,
} order_by_li,
limit,
offset,
log_lvl
});
if (ft_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) { if (result_li && try_cache) {
params_json['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str; const processed_obj_li = await process_ae_obj__event_location_props({
} obj_li: result_li,
} log_lvl
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);
}); });
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 = [ export const properties_to_save = [
'id', 'id',
'event_location_id', 'event_location_id',
@@ -656,7 +504,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li; return processed_obj_li;
} }
// Updated 2025-05-23
export async function process_ae_obj__event_location_props({ export async function process_ae_obj__event_location_props({
obj_li, obj_li,
log_lvl = 0 log_lvl = 0
@@ -667,16 +514,6 @@ export async function process_ae_obj__event_location_props({
return _process_generic_props({ return _process_generic_props({
obj_li, obj_li,
obj_type: 'event_location', obj_type: 'event_location',
log_lvl, 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;
}
}); });
} }

View File

@@ -10,7 +10,7 @@ import { load_ae_obj_li__event_presenter } from '$lib/ae_events/ae_events__event
const ae_promises: key_val = {}; const ae_promises: key_val = {};
// Updated 2025-05-22 // Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_presentation({ export async function load_ae_obj_id__event_presentation({
api_cfg, api_cfg,
event_presentation_id, event_presentation_id,
@@ -18,7 +18,8 @@ export async function load_ae_obj_id__event_presentation({
inc_presenter_li = false, inc_presenter_li = false,
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 49, view = 'default',
limit = 100,
offset = 0, offset = 0,
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
@@ -27,147 +28,95 @@ export async function load_ae_obj_id__event_presentation({
event_presentation_id: string; event_presentation_id: string;
inc_file_li?: boolean; inc_file_li?: boolean;
inc_presenter_li?: boolean; inc_presenter_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden';
view?: string;
limit?: number; limit?: number;
offset?: number; offset?: number;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventPresentation | null> { }): Promise<ae_EventPresentation | null> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_id__event_presentation() *** [V3] id=${event_presentation_id}`);
`*** load_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}`
);
} }
const params = {}; try {
ae_promises.load__event_presentation_obj = await api.get_ae_obj_v3({
ae_promises.load__event_presentation_obj = await api api_cfg,
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_presentation', obj_type: 'event_presentation',
obj_id: event_presentation_id, // NOTE: This is the FQDN, not normally the ID. obj_id: event_presentation_id,
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. view,
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value log_lvl
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);
}); });
if (log_lvl) { if (ae_promises.load__event_presentation_obj) {
console.log( if (try_cache) {
'ae_promises.load__event_presentation_obj:', const processed_obj_li = await process_ae_obj__event_presentation_props({
ae_promises.load__event_presentation_obj 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) { if (!ae_promises.load__event_presentation_obj) return null;
console.log('No results returned.');
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) { if (inc_file_li) {
// Load the files for the presentation presentation_obj.event_file_li = await load_ae_obj_li__event_file({
if (log_lvl) { api_cfg,
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,
for_obj_type: 'event_presentation', for_obj_type: 'event_presentation',
for_obj_id: event_presentation_id, for_obj_id: current_presentation_id,
enabled: 'all', enabled,
limit: 25, limit: 25,
try_cache: try_cache, try_cache,
log_lvl: 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);
}
ae_promises.load__event_presentation_obj.event_file_li = load_event_file_obj_li;
} }
if (inc_presenter_li) { if (inc_presenter_li) {
// Load the presenters for the presentation presentation_obj.event_presenter_li = await load_ae_obj_li__event_presenter({
if (log_lvl) { api_cfg,
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,
for_obj_type: 'event_presentation', for_obj_type: 'event_presentation',
for_obj_id: event_presentation_id, for_obj_id: current_presentation_id,
inc_file_li: inc_file_li, inc_file_li,
enabled: enabled, enabled,
hidden: hidden, hidden,
limit: limit, limit,
offset: offset, offset,
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'}, try_cache,
// params: params, log_lvl
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 (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({ export async function load_ae_obj_li__event_presentation({
api_cfg, api_cfg,
for_obj_type = 'event_session', for_obj_type = 'event_session',
@@ -176,190 +125,94 @@ export async function load_ae_obj_li__event_presentation({
inc_presenter_li = false, inc_presenter_li = false,
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 49, limit = 50,
offset = 0, offset = 0,
order_by_li = { order_by_li = [
priority: 'DESC', { priority: 'DESC' },
sort: 'DESC', { sort: 'DESC' },
start_datetime: 'ASC', { start_datetime: 'ASC' },
name: 'ASC', { name: 'ASC' },
updated_on: 'DESC', { updated_on: 'DESC' }
created_on: 'DESC' ],
} as const,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
for_obj_type: string; for_obj_type?: string;
for_obj_id: string; for_obj_id: string;
inc_file_li?: boolean; inc_file_li?: boolean;
inc_presenter_li?: boolean; inc_presenter_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number; limit?: number;
offset?: number; offset?: number;
order_by_li?: key_val; order_by_li?: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventPresentation[]> { }): Promise<ae_EventPresentation[]> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_li__event_presentation() *** [V3] for=${for_obj_type}:${for_obj_id}`);
`*** load_ae_obj_li__event_presentation() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
} }
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled try {
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden ae_promises.load__event_presentation_obj_li = await api.get_ae_obj_li_v3({
// let limit: number = (params.qry__limit ?? 99); // 99 api_cfg,
// 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,
obj_type: 'event_presentation', obj_type: 'event_presentation',
for_obj_type: for_obj_type, for_obj_type,
for_obj_id: 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,
// use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value hidden,
enabled: enabled, limit,
hidden: hidden, offset,
order_by_li: order_by_li, order_by_li,
limit: limit, log_lvl
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);
}); });
if (log_lvl) { if (ae_promises.load__event_presentation_obj_li) {
console.log( if (try_cache) {
'ae_promises.load__event_presentation_obj_li:', const processed_obj_li = await process_ae_obj__event_presentation_props({
ae_promises.load__event_presentation_obj_li obj_li: ae_promises.load__event_presentation_obj_li,
); log_lvl
} });
await db_save_ae_obj_li__ae_obj({
if (inc_file_li) { db_instance: db_events,
// Load the files for the presentations table_name: 'presentation',
if (log_lvl) { obj_li: processed_obj_li,
console.log(`Need to load the file list for each presentation now.`); properties_to_save,
} log_lvl
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);
} }
// 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) { if (ae_promises.load__event_presentation_obj_li) {
// Load the presenters for the presentations for (const presentation of ae_promises.load__event_presentation_obj_li) {
if (log_lvl) { await _handle_nested_loads(presentation, {
console.log(`Need to load the presenter list for each presentation now.`); api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl
}
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 (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({ export async function create_ae_obj__event_presentation({
api_cfg, api_cfg,
event_id, event_id,
event_session_id, event_session_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
@@ -367,255 +220,135 @@ export async function create_ae_obj__event_presentation({
event_id: string; event_id: string;
event_session_id: string; event_session_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventPresentation | null> { }): Promise<ae_EventPresentation | null> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** create_ae_obj__event_presentation() *** [V3] session=${event_session_id}`);
`*** create_ae_obj__event_presentation() *** event_id=${event_id} event_session_id=${event_session_id}`
);
} }
ae_promises.create__event_presentation = await api const result = await api.create_ae_obj_v3({
.create_ae_obj_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_presentation',
obj_type: 'event_presentation', fields: {
fields: { event_id_random: event_id,
event_id_random: event_id, event_session_id_random: event_session_id,
event_session_id_random: event_session_id, ...data_kv
...data_kv },
}, log_lvl
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.');
}
// db_save_ae_obj_li__event_presentation( if (result && try_cache) {
// { const processed_obj_li = await process_ae_obj__event_presentation_props({
// obj_type: 'event_presentation', obj_li: [result],
// obj_li: [event_presentation_obj_create_result] log_lvl
// }); });
} await db_save_ae_obj_li__ae_obj({
return event_presentation_obj_create_result; db_instance: db_events,
} else { table_name: 'presentation',
return null; obj_li: processed_obj_li,
} properties_to_save,
}) log_lvl
.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
);
} }
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({ export async function delete_ae_obj_id__event_presentation({
api_cfg, api_cfg,
event_presentation_id, event_presentation_id,
method = 'delete', // 'delete', 'disable', 'hide' method = 'delete',
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_presentation_id: string; event_presentation_id: string;
method?: string; method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** delete_ae_obj_id__event_presentation() *** [V3] id=${event_presentation_id}`);
`*** delete_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}`
);
} }
ae_promises.delete__event_presentation_obj = await api const result = await api.delete_ae_obj_v3({
.delete_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_presentation',
obj_type: 'event_presentation', obj_id: event_presentation_id,
obj_id: event_presentation_id, method,
key: api_cfg.api_crud_super_key, log_lvl
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);
}
});
if (log_lvl) { if (try_cache) {
console.log( await db_events.presentation.delete(event_presentation_id);
'ae_promises.delete__event_presentation_obj:',
ae_promises.delete__event_presentation_obj
);
} }
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({ export async function update_ae_obj__event_presentation({
api_cfg, api_cfg,
event_presentation_id, event_presentation_id,
data_kv, data_kv,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_presentation_id: string; event_presentation_id: string;
data_kv: key_val; data_kv: key_val;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventPresentation | null> { }): Promise<ae_EventPresentation | null> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** update_ae_obj__event_presentation() *** [V3] id=${event_presentation_id}`);
`*** update_ae_obj__event_presentation() *** event_presentation_id=${event_presentation_id}`,
data_kv
);
} }
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({ const result = await api.update_ae_obj_v3({
// obj_type: 'event_presentation', api_cfg,
// obj_li: [event_presentation_obj_update_result], obj_type: 'event_presentation',
// log_lvl: log_lvl obj_id: event_presentation_id,
// }); fields: data_kv,
} 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 () {});
if (log_lvl) { if (result && try_cache) {
console.log( const processed_obj_li = await process_ae_obj__event_presentation_props({
'ae_promises.update__event_presentation_obj:', obj_li: [result],
ae_promises.update__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
});
} }
return ae_promises.update__event_presentation_obj;
return result;
} }
// Updated 2025-05-22
export const properties_to_save = [ export const properties_to_save = [
'id', 'id',
'event_presentation_id', 'event_presentation_id',
// 'event_presentation_id_random',
'external_id', 'external_id',
'code', 'code',
'for_type', 'for_type',
'for_id', 'for_id',
// 'for_id_random',
'type_code', 'type_code',
'event_id', 'event_id',
// 'event_id_random',
'event_session_id', 'event_session_id',
// 'event_session_id_random',
'event_abstract_id', 'event_abstract_id',
// 'event_abstract_id_random',
'abstract_code', 'abstract_code',
'name', 'name',
'description', 'description',
'start_datetime', 'start_datetime',
'end_datetime', 'end_datetime',
'passcode', 'passcode',
'hide_event_launcher', 'hide_event_launcher',
'enable', 'enable',
'hide', 'hide',
'priority', 'priority',
@@ -624,18 +357,10 @@ export const properties_to_save = [
'notes', 'notes',
'created_on', 'created_on',
'updated_on', 'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1', 'tmp_sort_1',
'tmp_sort_2', 'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
'event_session_code', 'event_session_code',
'event_session_name' 'event_session_name'
// Add more fields here if your DB save logic uses them
]; ];
/** /**
@@ -653,39 +378,26 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number; log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T; specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> { }): Promise<T[]> {
if (log_lvl > 0) { if (!obj_li || obj_li.length === 0) return [];
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 [];
}
const processed_obj_li: T[] = []; const processed_obj_li: T[] = [];
for (const original_obj of obj_li) { for (const original_obj of obj_li) {
let processed_obj = { ...original_obj }; let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields // 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) { for (const key in processed_obj) {
if (key.endsWith('_random')) { 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]; (processed_obj as any)[newKey] = processed_obj[key];
} }
} }
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`; const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) { if (processed_obj[randomIdKey]) {
(processed_obj as any).id = 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 group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0; const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0'; const sort = processed_obj.sort ?? '0';
@@ -695,7 +407,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`; (processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) { if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj)); processed_obj = await Promise.resolve(specific_processor(processed_obj));
} }
@@ -706,7 +417,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li; return processed_obj_li;
} }
// Updated 2025-05-22
export async function process_ae_obj__event_presentation_props({ export async function process_ae_obj__event_presentation_props({
obj_li, obj_li,
log_lvl = 0 log_lvl = 0
@@ -717,17 +427,6 @@ export async function process_ae_obj__event_presentation_props({
return _process_generic_props({ return _process_generic_props({
obj_li, obj_li,
obj_type: 'event_presentation', obj_type: 'event_presentation',
log_lvl, 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;
}
}); });
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -42,37 +42,10 @@ export const properties_to_save_exhibit_tracking = [
'notes', 'notes',
'created_on', 'created_on',
'updated_on', 'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1', 'tmp_sort_1',
'tmp_sort_2' '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 --- // --- PROPERTIES TO SAVE ---
export const properties_to_save = [ export const properties_to_save = [
'id', 'id',
@@ -98,14 +71,12 @@ export const properties_to_save = [
'notes', 'notes',
'created_on', 'created_on',
'updated_on', 'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1', 'tmp_sort_1',
'tmp_sort_2' 'tmp_sort_2'
]; ];
/** /**
* NON-EXPORTED LOCAL HELPER * NON-EXPORTED LOCAL HELPER
* Processes a list of Aether objects by applying common and specific transformations.
*/ */
async function _process_generic_props<T extends Record<string, any>>({ async function _process_generic_props<T extends Record<string, any>>({
obj_li, obj_li,
@@ -155,7 +126,20 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li; 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({ export async function process_ae_obj__exhibit_props({
obj_li, obj_li,
log_lvl = 0 log_lvl = 0
@@ -166,307 +150,265 @@ export async function process_ae_obj__exhibit_props({
return _process_generic_props({ return _process_generic_props({
obj_li, obj_li,
obj_type: 'event_exhibit', obj_type: 'event_exhibit',
log_lvl, 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;
}
}); });
} }
// Updated 2024-03 // Updated 2026-01-20 to V3
export async function load_ae_obj_id__exhibit({ export async function load_ae_obj_id__exhibit({
api_cfg, api_cfg,
exhibit_id, exhibit_id,
view = 'default',
try_cache = false, try_cache = false,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
exhibit_id: string; exhibit_id: string;
view?: string;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibit | null> { }): Promise<ae_EventExhibit | null> {
if (log_lvl) { 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 { try {
ae_promises.load__exhibit_obj = await api ae_promises.load__exhibit_obj = await api.get_ae_obj_v3({
.get_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_exhibit',
obj_type: 'event_exhibit', obj_id: exhibit_id,
obj_id: exhibit_id, view,
use_alt_table: false, log_lvl
use_alt_base: false, });
params: {},
log_lvl: log_lvl
});
if (ae_promises.load__exhibit_obj) { if (ae_promises.load__exhibit_obj) {
if (try_cache) { if (try_cache) {
const processed_obj_li = await process_ae_obj__exhibit_props({ const processed_obj_li = await process_ae_obj__exhibit_props({
obj_li: [ae_promises.load__exhibit_obj], obj_li: [ae_promises.load__exhibit_obj],
log_lvl: log_lvl log_lvl
}); });
await db_save_ae_obj_li__ae_obj({ await db_save_ae_obj_li__ae_obj({
db_instance: db_events, db_instance: db_events,
table_name: 'exhibit', table_name: 'exhibit',
obj_li: processed_obj_li, obj_li: processed_obj_li,
properties_to_save: properties_to_save, properties_to_save,
log_lvl: log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
if (try_cache) { ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id);
ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id);
}
} }
} catch (error: any) { } catch (error: any) {
console.log('V3 Request failed.', error);
if (try_cache) { if (try_cache) {
ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id); 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({ export async function load_ae_obj_li__exhibit({
api_cfg, api_cfg,
event_id, 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, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
event_id: any; event_id: string;
params: any; enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibit[]> { }): Promise<ae_EventExhibit[]> {
if (log_lvl) { 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 { try {
ae_promises.load__event_exhibit_obj_li = await api ae_promises.load__event_exhibit_obj_li = await api.get_ae_obj_li_v3({
.get_ae_obj_li_for_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_exhibit',
obj_type: 'event_exhibit', for_obj_type: 'event',
for_obj_type: 'event', for_obj_id: event_id,
for_obj_id: event_id, enabled,
use_alt_table: false, hidden,
use_alt_base: false, limit,
enabled: enabled, offset,
hidden: hidden, order_by_li,
order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' }, log_lvl
limit: limit, });
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
});
if (ae_promises.load__event_exhibit_obj_li) { if (ae_promises.load__event_exhibit_obj_li) {
if (try_cache) { if (try_cache) {
const processed_obj_li = await process_ae_obj__exhibit_props({ const processed_obj_li = await process_ae_obj__exhibit_props({
obj_li: ae_promises.load__event_exhibit_obj_li, obj_li: ae_promises.load__event_exhibit_obj_li,
log_lvl: log_lvl log_lvl
}); });
await db_save_ae_obj_li__ae_obj({ await db_save_ae_obj_li__ae_obj({
db_instance: db_events, db_instance: db_events,
table_name: 'exhibit', table_name: 'exhibit',
obj_li: processed_obj_li, obj_li: processed_obj_li,
properties_to_save: properties_to_save, properties_to_save,
log_lvl: log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
if (try_cache) { ae_promises.load__event_exhibit_obj_li = await db_events.exhibit
ae_promises.load__event_exhibit_obj_li = await db_events.exhibit .where('event_id').equals(event_id)
.where('event_id').equals(event_id) .toArray();
.toArray();
} else {
ae_promises.load__event_exhibit_obj_li = [];
}
} }
} catch (error: any) { } catch (error: any) {
console.log('V3 List Request failed.', error);
if (try_cache) { if (try_cache) {
ae_promises.load__event_exhibit_obj_li = await db_events.exhibit ae_promises.load__event_exhibit_obj_li = await db_events.exhibit
.where('event_id').equals(event_id) .where('event_id').equals(event_id)
.toArray(); .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({ export async function load_ae_obj_id__exhibit_tracking({
api_cfg, api_cfg,
exhibit_tracking_id, exhibit_tracking_id,
view = 'default',
try_cache = false, try_cache = false,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
exhibit_tracking_id: string; exhibit_tracking_id: string;
view?: string;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibitTracking | null> { }): Promise<ae_EventExhibitTracking | null> {
if (log_lvl) {
console.log(
`*** load_ae_obj_id__exhibit_tracking() *** exhibit_tracking_id=${exhibit_tracking_id}`
);
}
try { try {
ae_promises.load__event_exhibit_tracking_obj = await api ae_promises.load__event_exhibit_tracking_obj = await api.get_ae_obj_v3({
.get_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_exhibit_tracking',
obj_type: 'event_exhibit_tracking', obj_id: exhibit_tracking_id,
obj_id: exhibit_tracking_id, view,
use_alt_table: false, log_lvl
use_alt_base: false, });
params: {},
log_lvl: log_lvl
});
if (ae_promises.load__event_exhibit_tracking_obj) { if (ae_promises.load__event_exhibit_tracking_obj) {
if (try_cache) { if (try_cache) {
const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
obj_li: [ae_promises.load__event_exhibit_tracking_obj], obj_li: [ae_promises.load__event_exhibit_tracking_obj],
log_lvl: log_lvl log_lvl
}); });
await db_save_ae_obj_li__ae_obj({ await db_save_ae_obj_li__ae_obj({
db_instance: db_events, db_instance: db_events,
table_name: 'exhibit_tracking', table_name: 'exhibit_tracking',
obj_li: processed_obj_li, obj_li: processed_obj_li,
properties_to_save: properties_to_save_exhibit_tracking, properties_to_save: properties_to_save_exhibit_tracking,
log_lvl: log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
if (try_cache) { ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id);
ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id);
}
} }
} catch (error: any) { } catch (error: any) {
if (try_cache) { if (try_cache) {
ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id); 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({ export async function load_ae_obj_li__exhibit_tracking({
api_cfg, api_cfg,
exhibit_id, exhibit_id,
params = {}, enabled = 'enabled',
hidden = 'all',
limit = 100,
offset = 0,
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ updated_on: 'DESC' }
],
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
exhibit_id: any; exhibit_id: string;
params: any; enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibitTracking[]> { }): Promise<ae_EventExhibitTracking[]> {
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 { try {
ae_promises.load__event_exhibit_tracking_obj_li = await api ae_promises.load__event_exhibit_tracking_obj_li = await api.get_ae_obj_li_v3({
.get_ae_obj_li_for_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_exhibit_tracking',
obj_type: 'event_exhibit_tracking', for_obj_type: 'event_exhibit',
for_obj_type: 'event_exhibit', for_obj_id: exhibit_id,
for_obj_id: exhibit_id, enabled,
use_alt_table: false, hidden,
use_alt_base: false, limit,
enabled: enabled, offset,
hidden: hidden, order_by_li,
order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' }, log_lvl
limit: limit, });
offset: offset,
params_json: {},
params: params,
log_lvl: log_lvl
});
if (ae_promises.load__event_exhibit_tracking_obj_li) { if (ae_promises.load__event_exhibit_tracking_obj_li) {
if (try_cache) { if (try_cache) {
const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
obj_li: ae_promises.load__event_exhibit_tracking_obj_li, obj_li: ae_promises.load__event_exhibit_tracking_obj_li,
log_lvl: log_lvl log_lvl
}); });
await db_save_ae_obj_li__ae_obj({ await db_save_ae_obj_li__ae_obj({
db_instance: db_events, db_instance: db_events,
table_name: 'exhibit_tracking', table_name: 'exhibit_tracking',
obj_li: processed_obj_li, obj_li: processed_obj_li,
properties_to_save: properties_to_save_exhibit_tracking, properties_to_save: properties_to_save_exhibit_tracking,
log_lvl: log_lvl log_lvl
}); });
} }
} else { } else if (try_cache) {
if (try_cache) { ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking
ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking .where('event_exhibit_id').equals(exhibit_id)
.where('event_exhibit_id').equals(exhibit_id) .toArray();
.toArray();
} else {
ae_promises.load__event_exhibit_tracking_obj_li = [];
}
} }
} catch (error: any) { } catch (error: any) {
if (try_cache) { if (try_cache) {
ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking
.where('event_exhibit_id').equals(exhibit_id) .where('event_exhibit_id').equals(exhibit_id)
.toArray(); .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({ export async function create_ae_obj__exhibit_tracking({
api_cfg, api_cfg,
exhibit_id, exhibit_id,
event_badge_id, event_badge_id,
external_person_id, external_person_id,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
@@ -474,133 +416,102 @@ export async function create_ae_obj__exhibit_tracking({
exhibit_id: string; exhibit_id: string;
event_badge_id: string; event_badge_id: string;
external_person_id: string; external_person_id: string;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibitTracking | null> { }): Promise<ae_EventExhibitTracking | null> {
ae_promises.create__event_exhibit_tracking = await api const result = await api.create_ae_obj_v3({
.create_ae_obj_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_exhibit_tracking',
obj_type: 'event_exhibit_tracking', fields: {
fields: { event_exhibit_id_random: exhibit_id,
event_exhibit_id_random: exhibit_id, event_badge_id_random: event_badge_id,
event_badge_id_random: event_badge_id, external_person_id
external_person_id: external_person_id },
}, log_lvl
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;
});
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({ export async function update_ae_obj__exhibit_tracking({
api_cfg, api_cfg,
exhibit_tracking_id, exhibit_tracking_id,
data, data,
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
exhibit_tracking_id: string; exhibit_tracking_id: string;
data: any; data: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibitTracking | null> { }): Promise<ae_EventExhibitTracking | null> {
ae_promises.update__event_exhibit_tracking = await api const result = await api.update_ae_obj_v3({
.update_ae_obj_id_crud({ api_cfg,
api_cfg: api_cfg, obj_type: 'event_exhibit_tracking',
obj_type: 'event_exhibit_tracking', obj_id: exhibit_tracking_id,
obj_id: exhibit_tracking_id, fields: data,
fields: data, log_lvl
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;
});
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({ export async function download_export__event_exhibit_tracking({
api_cfg, api_cfg,
exhibit_id, exhibit_id,
file_type = 'CSV', // 'CSV' or 'Excel' file_type = 'CSV',
return_file = true, filename = 'exhibit_tracking_export.csv',
filename = 'no_filename.csv',
auto_download = false,
params = {},
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
exhibit_id: string; exhibit_id: string;
file_type?: string; file_type?: string;
return_file?: boolean;
filename?: string; filename?: string;
auto_download?: boolean;
params?: key_val;
log_lvl?: number; log_lvl?: number;
}) { }) {
console.log('*** ae_events_functions.js: get_event_exhibit_tracking_export() ***');
const endpoint = `/event/exhibit/${exhibit_id}/tracking/export`; const endpoint = `/event/exhibit/${exhibit_id}/tracking/export`;
if (file_type == 'CSV' || file_type == 'Excel') { const params = {
params['file_type'] = file_type; file_type,
} return_file: true
params['return_file'] = true; };
ae_promises.download__event_exhibit_tracking_export_file = await api.get_object({ return await api.get_object({
api_cfg: api_cfg, api_cfg,
endpoint: endpoint, endpoint,
params: params, params,
return_blob: true, return_blob: true,
filename: filename, filename,
auto_download: auto_download, auto_download: true,
log_lvl: log_lvl 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;
} }

View File

@@ -1,11 +1,8 @@
import type { key_val } from '$lib/stores/ae_stores'; import type { key_val } from '$lib/stores/ae_stores';
import { api } from '$lib/api/api'; import { api } from '$lib/api/api';
import { db_sponsorships } from '$lib/ae_sponsorships/db_sponsorships'; 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 { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
import type { ae_Sponsorship, ae_Sponsorship_Cfg } from '$lib/types/ae_types';
// import { liveQuery } from "dexie";
// import { db_core } from "$lib/db_core";
const ae_promises: key_val = {}; const ae_promises: key_val = {};
@@ -46,7 +43,7 @@ export async function process_ae_obj__sponsorship_cfg_props({
obj_type: 'sponsorship_cfg', obj_type: 'sponsorship_cfg',
log_lvl, log_lvl,
specific_processor: (obj) => { 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.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? '' obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`; }_${obj.updated_on ?? obj.created_on}`;
@@ -112,7 +109,7 @@ export async function process_ae_obj__sponsorship_props({
obj_type: 'sponsorship', obj_type: 'sponsorship',
log_lvl, log_lvl,
specific_processor: (obj) => { 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.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? '' obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`; }_${obj.updated_on ?? obj.created_on}`;
@@ -156,13 +153,10 @@ async function _process_generic_props<T extends Record<string, any>>({
for (const original_obj of obj_li) { for (const original_obj of obj_li) {
let processed_obj = { ...original_obj }; let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields // 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) { for (const key in processed_obj) {
if (key.endsWith('_random')) { 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]; (processed_obj as any)[newKey] = processed_obj[key];
} }
} }
@@ -172,7 +166,7 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).id = 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 group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0; const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0'; const sort = processed_obj.sort ?? '0';
@@ -182,7 +176,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`; (processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) { if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj)); processed_obj = await Promise.resolve(specific_processor(processed_obj));
} }
@@ -193,8 +186,8 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li; return processed_obj_li;
} }
// Updated 2024-03-29 // Updated 2026-01-20 to V3
async function load_ae_obj_id__sponsorship_cfg({ export async function load_ae_obj_id__sponsorship_cfg({
api_cfg, api_cfg,
sponsorship_cfg_id, sponsorship_cfg_id,
try_cache = false, try_cache = false,
@@ -202,85 +195,41 @@ async function load_ae_obj_id__sponsorship_cfg({
}: { }: {
api_cfg: any; api_cfg: any;
sponsorship_cfg_id: string; sponsorship_cfg_id: string;
try_cache: boolean; try_cache?: boolean;
log_lvl: number; log_lvl?: number;
}) { }): Promise<ae_Sponsorship_Cfg | null> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_id__sponsorship_cfg() *** [V3] id=${sponsorship_cfg_id}`);
`*** load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_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 if (sponsorship_cfg_obj_get_result) {
.get_ae_obj_id_crud({ if (try_cache) {
api_cfg: api_cfg, const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({
obj_type: 'sponsorship_cfg', obj_li: [sponsorship_cfg_obj_get_result],
obj_id: sponsorship_cfg_id, log_lvl
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. await db_save_ae_obj_li__ae_obj({
params: params, db_instance: db_sponsorships,
log_lvl: log_lvl table_name: 'cfg',
}) obj_li: processed_obj_li,
.then(async function (sponsorship_cfg_obj_get_result) { properties_to_save: properties_to_save_sponsorship_cfg,
if (sponsorship_cfg_obj_get_result) { log_lvl
if (log_lvl) { });
console.log( }
`*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}` return sponsorship_cfg_obj_get_result;
);
} 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
);
} }
return null;
return ae_promises.load__sponsorship_cfg_obj;
} }
// Updated 2024-03-29 // Updated 2026-01-20 to V3
async function load_ae_obj_id__sponsorship({ export async function load_ae_obj_id__sponsorship({
api_cfg, api_cfg,
sponsorship_id, sponsorship_id,
try_cache = false, try_cache = false,
@@ -288,78 +237,41 @@ async function load_ae_obj_id__sponsorship({
}: { }: {
api_cfg: any; api_cfg: any;
sponsorship_id: string; sponsorship_id: string;
try_cache: boolean; try_cache?: boolean;
log_lvl: number; log_lvl?: number;
}) { }): Promise<ae_Sponsorship | null> {
if (log_lvl) { 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 if (sponsorship_obj_get_result) {
.get_ae_obj_id_crud({ if (try_cache) {
api_cfg: api_cfg, const processed_obj_li = await process_ae_obj__sponsorship_props({
obj_type: 'sponsorship', obj_li: [sponsorship_obj_get_result],
obj_id: sponsorship_id, log_lvl
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. await db_save_ae_obj_li__ae_obj({
params: params, db_instance: db_sponsorships,
log_lvl: log_lvl table_name: 'sponsorship',
}) obj_li: processed_obj_li,
.then(async function (sponsorship_obj_get_result) { properties_to_save: properties_to_save_sponsorship,
if (sponsorship_obj_get_result) { log_lvl
if (log_lvl) { });
console.log(`*spons_func* Got a result for sponsorship_id ${sponsorship_id}`); }
} else if (log_lvl > 1) { return sponsorship_obj_get_result;
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);
} }
return null;
return ae_promises.load__sponsorship_obj;
} }
// Updated 2025-01-15 // Updated 2026-01-20 to V3
async function load_ae_obj_li__sponsorship({ export async function load_ae_obj_li__sponsorship({
api_cfg, api_cfg,
for_obj_type = 'account', for_obj_type = 'account',
for_obj_id, for_obj_id,
@@ -367,146 +279,165 @@ async function load_ae_obj_li__sponsorship({
hidden = 'not_hidden', hidden = 'not_hidden',
limit = 99, limit = 99,
offset = 0, offset = 0,
order_by_li = { order_by_li = [
priority: 'DESC', { priority: 'DESC' },
sort: 'DESC', { sort: 'DESC' },
name: 'ASC', { name: 'ASC' },
updated_on: 'DESC', { updated_on: 'DESC' }
created_on: 'DESC' ],
},
params = {},
try_cache = true, try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
for_obj_type: string; for_obj_type: string;
for_obj_id: string; for_obj_id: string;
inc_content_li?: boolean; enabled?: 'enabled' | 'all' | 'not_enabled';
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden';
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
limit?: number; limit?: number;
offset?: number; offset?: number;
order_by_li?: key_val; order_by_li?: any;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }): Promise<ae_Sponsorship[]> {
if (log_lvl) { if (log_lvl) {
console.log( console.log(`*** load_ae_obj_li__sponsorship() *** [V3] for=${for_obj_type}:${for_obj_id}`);
`*** load_ae_obj_li__sponsorship() *** for_obj_type=${for_obj_type} for_obj_id=${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 if (result_li && try_cache) {
.get_ae_obj_li_for_obj_id_crud_v2({ const processed_obj_li = await process_ae_obj__sponsorship_props({
api_cfg: api_cfg, obj_li: result_li,
obj_type: 'sponsorship', log_lvl
for_obj_type: for_obj_type, });
for_obj_id: for_obj_id, await db_save_ae_obj_li__ae_obj({
use_alt_tbl: false, db_instance: db_sponsorships,
use_alt_mdl: false, table_name: 'sponsorship',
use_alt_exp: false, obj_li: processed_obj_li,
enabled: enabled, properties_to_save: properties_to_save_sponsorship,
hidden: hidden, log_lvl
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 (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({ export async function download_export__sponsorship({
api_cfg, api_cfg,
account_id, account_id,
file_type = 'CSV', // 'CSV' or 'Excel' file_type = 'CSV',
return_file = true, filename = 'sponsorship_export.csv',
filename = 'no_filename.csv', params = {},
auto_download = false,
params = {}, // key value object is expected
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
account_id: string; account_id: string;
file_type?: string; file_type?: string;
return_file?: boolean;
filename?: string; filename?: string;
auto_download?: boolean;
params?: key_val; params?: key_val;
log_lvl?: number; 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`; const endpoint = `/v2/crud/sponsorship/list`;
params['for_obj_type'] = 'account'; const query_params = {
params['for_obj_id'] = account_id; ...params,
for_obj_type: 'account',
for_obj_id: account_id,
file_type,
return_file: true
};
if (file_type == 'CSV' || file_type == 'Excel') { return await api.get_object({
params['file_type'] = file_type; api_cfg,
} endpoint,
params['return_file'] = true; params: query_params,
return_blob: true,
ae_promises.download__sponsorship_export_file = await api.get_object({ filename,
api_cfg: api_cfg, auto_download: true,
endpoint: endpoint, log_lvl
params: params,
return_blob: return_file,
filename: filename,
auto_download: auto_download,
log_lvl: 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 = { export const spons_func = {
load_ae_obj_id__sponsorship_cfg: 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_id__sponsorship,
load_ae_obj_li__sponsorship: load_ae_obj_li__sponsorship, load_ae_obj_li__sponsorship,
download_export__sponsorship: download_export__sponsorship create_ae_obj__sponsorship,
update_ae_obj__sponsorship,
delete_ae_obj__sponsorship,
download_export__sponsorship
}; };
export const spons_func = export_obj;