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
*/
async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, inc_location_li, inc_session_li, inc_template_li, log_lvl }: any) {
const current_event_id = event_obj.event_id || event_obj.id;
const current_event_id = event_obj.event_id_random || event_obj.event_id || event_obj.id;
if (inc_device_li) {
event_obj.event_device_obj_li = await load_ae_obj_li__event_device({

View File

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

View File

@@ -9,7 +9,7 @@ import { load_ae_obj_id__event_location } from './ae_events__event_location';
const ae_promises: key_val = {};
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_device({
api_cfg,
event_device_id,
@@ -24,22 +24,16 @@ export async function load_ae_obj_id__event_device({
log_lvl?: number;
}): Promise<ae_EventDevice | null> {
if (log_lvl) {
console.log(`*** load_ae_obj_id__event_device() *** event_device_id=${event_device_id}`);
console.log(`*** load_ae_obj_id__event_device() *** [V3] id=${event_device_id}`);
}
const params = {};
try {
ae_promises.load__event_device_obj = await api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_device',
obj_id: event_device_id, // NOTE: This is the FQDN, not normally the ID.
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
params: params,
log_lvl: log_lvl
});
ae_promises.load__event_device_obj = await api.get_ae_obj_v3({
api_cfg,
obj_type: 'event_device',
obj_id: event_device_id,
log_lvl
});
if (ae_promises.load__event_device_obj) {
if (try_cache) {
@@ -56,39 +50,27 @@ export async function load_ae_obj_id__event_device({
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_device_obj = await db_events.device.get(event_device_id);
}
}
} catch (error: any) {
console.log('API request failed.', error);
console.log('V3 Request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_device_obj = await db_events.device.get(event_device_id);
} else {
ae_promises.load__event_device_obj = null;
}
}
if (log_lvl) {
console.log('ae_promises.load__event_device_obj:', ae_promises.load__event_device_obj);
}
if (!ae_promises?.load__event_device_obj) {
return null;
}
if (!ae_promises.load__event_device_obj) return null;
if (inc_location_id) {
// Load the location linked to this device
const current_location_id = ae_promises.load__event_device_obj.event_location_id;
if (current_location_id) {
ae_promises.load__event_device_obj.event_location_obj = await load_ae_obj_id__event_location({
api_cfg: api_cfg,
api_cfg,
event_location_id: current_location_id,
try_cache: try_cache,
log_lvl: log_lvl
try_cache,
log_lvl
});
}
}
@@ -96,514 +78,306 @@ export async function load_ae_obj_id__event_device({
return ae_promises.load__event_device_obj;
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function load_ae_obj_li__event_device({
api_cfg,
for_obj_type,
for_obj_type = 'event',
for_obj_id,
inc_location_id = false,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 49,
limit = 100,
offset = 0,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
name: 'ASC',
code: 'ASC',
updated_on: 'DESC',
created_on: 'DESC'
} as const,
params = {},
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
for_obj_type: string;
for_obj_type?: string;
for_obj_id: string;
inc_location_id?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden
limit?: number; // 99
offset?: number; // 0
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
params?: key_val;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventDevice[]> {
if (log_lvl) {
console.log(
`*** load_ae_obj_li__event_device() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
console.log(`*** load_ae_obj_li__event_device() *** [V3] for=${for_obj_type}:${for_obj_id}`);
}
const params_json: key_val = {};
try {
ae_promises.load__event_device_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'event_device',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true,
use_alt_mdl: false,
use_alt_exp: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
});
ae_promises.load__event_device_obj_li = await api.get_ae_obj_li_v3({
api_cfg,
obj_type: 'event_device',
for_obj_type,
for_obj_id,
enabled,
hidden,
limit,
offset,
order_by_li,
log_lvl
});
if (ae_promises.load__event_device_obj_li) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: ae_promises.load__event_device_obj_li,
log_lvl: log_lvl
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
properties_to_save,
log_lvl
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_device_obj_li = await db_events.device
.where('event_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_device_obj_li = [];
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
} else if (try_cache) {
ae_promises.load__event_device_obj_li = await db_events.device
.where('event_id').equals(for_obj_id)
.toArray();
}
} catch (error: any) {
console.log('V3 List Request failed.', error);
if (try_cache) {
ae_promises.load__event_device_obj_li = await db_events.device
.where('event_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_device_obj_li = [];
}
}
if (inc_location_id && ae_promises.load__event_device_obj_li) {
for (let i = 0; i < ae_promises.load__event_device_obj_li.length; i++) {
const event_device_obj = ae_promises.load__event_device_obj_li[i];
if (event_device_obj.event_location_id) {
event_device_obj.event_location_obj = await load_ae_obj_id__event_location({
api_cfg: api_cfg,
event_location_id: event_device_obj.event_location_id,
try_cache: try_cache,
log_lvl: log_lvl
for (const device of ae_promises.load__event_device_obj_li) {
if (device.event_location_id) {
device.event_location_obj = await load_ae_obj_id__event_location({
api_cfg,
event_location_id: device.event_location_id,
try_cache,
log_lvl
});
}
}
}
return ae_promises.load__event_device_obj_li;
return ae_promises.load__event_device_obj_li || [];
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function create_ae_obj__event_device({
api_cfg,
event_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_id: string;
data_kv: key_val;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventDevice | null> {
if (log_lvl) {
console.log(`*** create_ae_obj__event_device() *** event_id=${event_id}`);
console.log(`*** create_ae_obj__event_device() *** [V3] event_id=${event_id}`);
}
ae_promises.create__event_device = await api
.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'event_device',
fields: {
event_id_random: event_id,
...data_kv
},
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (event_device_obj_create_result) {
if (event_device_obj_create_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: [event_device_obj_create_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
const result = await api.create_ae_obj_v3({
api_cfg,
obj_type: 'event_device',
fields: {
event_id_random: event_id,
...data_kv
},
log_lvl
});
// db_save_ae_obj_li__event_device(
// {
// obj_type: 'event_device',
// obj_li: [event_device_obj_create_result]
// });
}
return event_device_obj_create_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) {
console.log('ae_promises.create__event_device:', ae_promises.create__event_device);
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return ae_promises.create__event_device;
return result;
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function delete_ae_obj_id__event_device({
api_cfg,
event_device_id,
method = 'delete', // 'delete', 'disable', 'hide'
params = {},
method = 'delete',
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_device_id: string;
method?: string;
params?: key_val;
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
try_cache?: boolean;
log_lvl?: number;
}) {
if (log_lvl) {
console.log(`*** delete_ae_obj_id__event_device() *** event_device_id=${event_device_id}`);
console.log(`*** delete_ae_obj_id__event_device() *** [V3] id=${event_device_id}`);
}
ae_promises.delete__event_device_obj = await api
.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_device',
obj_id: event_device_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
log_lvl: log_lvl
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {
if (try_cache) {
if (log_lvl) {
console.log(
`Attempting to remove IDB entry for event_device_id=${event_device_id}`
);
}
db_events.device.delete(event_device_id);
}
});
const result = await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'event_device',
obj_id: event_device_id,
method,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.delete__event_device_obj:', ae_promises.delete__event_device_obj);
if (try_cache) {
await db_events.device.delete(event_device_id);
}
return ae_promises.delete__event_device_obj;
return result;
}
// Updated 2024-10-16
// Updated 2026-01-20 to V3
export async function update_ae_obj__event_device({
api_cfg,
event_device_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_device_id: string;
data_kv: key_val;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventDevice | null> {
if (log_lvl) {
console.log(
`*** update_ae_obj__event_device() *** event_device_id=${event_device_id}`,
data_kv
);
console.log(`*** update_ae_obj__event_device() *** [V3] id=${event_device_id}`);
}
ae_promises.update__event_device_obj = await api
.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_device',
obj_id: event_device_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (event_device_obj_update_result) {
if (event_device_obj_update_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: [event_device_obj_update_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event_device({
// obj_type: 'event_device', obj_li: [event_device_obj_update_result]
// });
}
return event_device_obj_update_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'event_device',
obj_id: event_device_id,
fields: data_kv,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.update__event_device_obj:', ae_promises.update__event_device_obj);
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return ae_promises.update__event_device_obj;
return result;
}
// Not yet used or tested fully!
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function search__event_device({
api_cfg,
event_id,
fulltext_search_qry_str,
ft_presenter_search_qry_str,
like_search_qry_str = null,
like_presentation_search_qry_str = null,
like_presenter_search_qry_str = null,
params = {},
qry_str = '',
enabled = 'enabled',
hidden = 'not_hidden',
limit = 25,
offset = 0,
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_id: any;
fulltext_search_qry_str?: null | string;
ft_presenter_search_qry_str?: null | string;
like_search_qry_str?: null | string;
like_presentation_search_qry_str?: null | string;
like_presenter_search_qry_str?: null | string;
params?: any;
event_id: string;
qry_str?: string;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventDevice[] | false> {
}): Promise<ae_EventDevice[]> {
if (log_lvl) {
console.log(`*** search__event_device() *** event_id=${event_id}`);
console.log(`*** search__event_device() *** [V3] event_id=${event_id} qry=${qry_str}`);
}
const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled';
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden';
const limit: number = params.qry__limit ?? 25; // 99
const offset: number = params.qry__offset ?? 0; // 0
const search_query: any = {
q: qry_str,
and: [{ field: 'event_id_random', op: 'eq', value: event_id }]
};
const params_json: key_val = {};
// Logical filters
if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true });
else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false });
if (!fulltext_search_qry_str && !like_search_qry_str) {
console.log('No search string provided!!!');
return false; // Returning false instead of [] because no search was performed.
if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true });
else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false });
const result_li = await api.search_ae_obj_v3({
api_cfg,
obj_type: 'event_device',
search_query,
order_by_li,
limit,
offset,
log_lvl
});
if (result_li && try_cache) {
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: result_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
if (fulltext_search_qry_str || ft_presenter_search_qry_str) {
params_json['ft_qry'] = {};
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str;
}
if (ft_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) {
params_json['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str;
}
}
// Use the AND (AND LIKE) query
// if (like_search_qry_str || like_presenter_search_qry_str) {
// params_json['and_like'] = {};
// if (like_search_qry_str && like_search_qry_str.length > 2) {
// params_json['and_like']['default_qry_str'] = like_search_qry_str;
// }
// if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) {
// params_json['and_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str;
// }
// }
// Use the AND (OR LIKE) query
if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_search_qry_str) {
params_json['or_like'] = {};
if (like_search_qry_str && like_search_qry_str.length > 2) {
params_json['or_like']['default_qry_str'] = like_search_qry_str;
}
if (like_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) {
params_json['or_like']['event_presentation_li_qry_str'] =
like_presentation_search_qry_str;
}
if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) {
params_json['or_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str;
}
}
params_json['and_qry'] = {};
// if (device_type_code) {
// params_json['and_qry']['device_type_code'] = device_type_code;
// }
const order_by_li = {
priority: 'DESC',
sort: 'DESC',
start_datetime: 'ASC',
name: 'ASC',
updated_on: 'DESC',
created_on: 'DESC'
} as const;
// ae_promises.load__event_device_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
ae_promises.load__event_device_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'event_device',
for_obj_type: 'event',
for_obj_id: event_id,
use_alt_tbl: true, // NOTE: We want to use the alt table for device searching
// use_alt_mdl: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (event_device_obj_li_get_result) {
if (event_device_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: event_device_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return event_device_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) {
console.log(
'ae_promises.load__event_device_obj_li:',
ae_promises.load__event_device_obj_li
);
}
return ae_promises.load__event_device_obj_li;
return result_li || [];
}
// Updated 2025-05-23
export const properties_to_save = [
'id',
'event_device_id',
// 'event_device_id_random',
'event_id',
// 'event_id_random',
'event_location_id',
// 'event_location_id_random',
'code',
'name',
'description',
'passcode',
'local_file_cache_path',
'host_file_temp_path',
'recording_path',
'record_audio',
'record_video',
'trigger_open_file_id',
'trigger_open_session_id',
'trigger_recording_start',
@@ -611,7 +385,6 @@ export const properties_to_save = [
'trigger_reset',
'trigger_show_admin',
'trigger_show_hidden',
'alert',
'alert_msg',
'alert_on',
@@ -622,13 +395,10 @@ export const properties_to_save = [
'record_status_msg',
'record_status_on',
'heartbeat',
'info_hostname',
'info_ip_list',
'meta_json',
'other_json',
'enable',
'hide',
'priority',
@@ -637,14 +407,8 @@ export const properties_to_save = [
'notes',
'created_on',
'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1',
'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
'event_name',
'event_location_code',
'event_location_name'
@@ -665,39 +429,26 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> {
if (log_lvl > 0) {
console.log(
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
);
}
if (!obj_li || obj_li.length === 0) {
if (log_lvl > 0) console.log('No objects to process.');
return [];
}
if (!obj_li || obj_li.length === 0) return [];
const processed_obj_li: T[] = [];
for (const original_obj of obj_li) {
let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
for (const key in processed_obj) {
if (key.endsWith('_random')) {
const newKey = key.slice(0, -7); // Remove '_random' suffix
const newKey = key.slice(0, -7);
(processed_obj as any)[newKey] = processed_obj[key];
}
}
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) {
(processed_obj as any).id = processed_obj[randomIdKey];
}
// 2. Create common computed properties for client-side sorting.
// 2. Create common computed properties
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
@@ -707,7 +458,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj));
}
@@ -718,7 +468,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li;
}
// Updated 2025-05-23
export async function process_ae_obj__event_device_props({
obj_li,
log_lvl = 0
@@ -731,20 +480,10 @@ export async function process_ae_obj__event_device_props({
obj_type: 'event_device',
log_lvl,
specific_processor: (obj) => {
// Special handling for heartbeat timestamp
if (obj.heartbeat) {
obj.heartbeat = obj.heartbeat + 'Z';
}
// Event device-specific computed sort fields, overriding generic ones if needed
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;
obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on}_${obj.created_on}`;
return obj;
}
});
}
}

View File

@@ -7,114 +7,92 @@ import type { ae_EventFile } from '$lib/types/ae_types';
const ae_promises: key_val = {};
// Updated 2025-07-21
// Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_file({
api_cfg,
event_file_id,
view = 'default',
try_cache = false,
log_lvl = 0
}: {
api_cfg: any;
event_file_id: string;
view?: string;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventFile | null> {
if (log_lvl) {
console.log(`*** load_ae_obj_id__event_file() *** event_file_id=${event_file_id}`);
console.log(`*** load_ae_obj_id__event_file() *** [V3] id=${event_file_id}`);
}
const params = {};
ae_promises.load__event_file_obj = await api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
try {
ae_promises.load__event_file_obj = await api.get_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
obj_id: event_file_id, // NOTE: This is the FQDN, not normally the ID.
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value
params: params,
log_lvl: log_lvl
})
.then(async function (event_file_obj_get_result) {
if (event_file_obj_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: [event_file_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// This is expecting a list
// db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: [event_file_obj_get_result]});
}
return event_file_obj_get_result;
} else {
console.log('No results returned.');
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
obj_id: event_file_id,
view,
log_lvl
});
return ae_promises.load__event_file_obj;
if (ae_promises.load__event_file_obj) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: [ae_promises.load__event_file_obj],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
} else if (try_cache) {
ae_promises.load__event_file_obj = await db_events.file.get(event_file_id);
}
} catch (error: any) {
console.log('V3 Request failed.', error);
if (try_cache) {
ae_promises.load__event_file_obj = await db_events.file.get(event_file_id);
}
}
return ae_promises.load__event_file_obj || null;
}
// Updated 2025-07-21
// Updated 2026-01-20 to V3
export async function load_ae_obj_li__event_file({
api_cfg,
for_obj_type,
for_obj_id,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 99,
limit = 100,
offset = 0,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
updated_on: 'DESC',
created_on: 'DESC'
} as const,
params = {},
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
for_obj_type: string;
for_obj_id: string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden
limit?: number; // 99
offset?: number; // 0
order_by_li?: key_val;
params?: key_val;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventFile[]> {
if (log_lvl) {
console.log(
`*** load_ae_obj_li__event_file() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
console.log(`*** load_ae_obj_li__event_file() *** [V3] for=${for_obj_type}:${for_obj_id}`);
}
// Check if for_obj_type is in the list of valid Aether object types:
const valid_for_obj_types = [
'event',
'event_session',
@@ -129,74 +107,55 @@ export async function load_ae_obj_li__event_file({
return [];
}
const params_json: key_val = {};
// console.log('params_json:', params_json);
ae_promises.load__event_file_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
try {
ae_promises.load__event_file_obj_li = await api.get_ae_obj_li_v3({
api_cfg,
obj_type: 'event_file',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value
use_alt_exp: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (event_file_obj_li_get_result) {
if (event_file_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: event_file_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result});
}
return event_file_obj_li_get_result;
} else {
console.log('No results returned.');
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
for_obj_type,
for_obj_id,
enabled,
hidden,
limit,
offset,
order_by_li,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.load__event_file_obj_li:', ae_promises.load__event_file_obj_li);
if (ae_promises.load__event_file_obj_li) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: ae_promises.load__event_file_obj_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
} else if (try_cache) {
// Dexie fallback - search for parent ID across common link fields
ae_promises.load__event_file_obj_li = await db_events.file
.filter((f: any) => f.for_id === for_obj_id || f.event_id === for_obj_id)
.toArray();
}
} catch (error: any) {
console.log('V3 List Request failed.', error);
if (try_cache) {
ae_promises.load__event_file_obj_li = await db_events.file
.filter((f: any) => f.for_id === for_obj_id || f.event_id === for_obj_id)
.toArray();
}
}
return ae_promises.load__event_file_obj_li;
return ae_promises.load__event_file_obj_li || [];
}
// Updated 2025-07-21
// This may need to be reviewed again???
/**
* Legacy wrapper maintained for specific creation logic (link from hosted_file)
*/
export async function create_event_file_obj_from_hosted_file_async({
api_cfg,
hosted_file_id,
@@ -204,7 +163,6 @@ export async function create_event_file_obj_from_hosted_file_async({
data = {},
return_obj = false,
inc_hosted_file = false,
return_meta = false,
log_lvl = 0
}: {
api_cfg: any;
@@ -213,57 +171,28 @@ export async function create_event_file_obj_from_hosted_file_async({
data?: key_val;
return_obj?: boolean;
inc_hosted_file?: boolean;
return_meta?: boolean;
log_lvl?: number;
}) {
if (log_lvl) {
console.log(
`*** create_event_file_obj_from_hosted_file_async() *** hosted_file_id=${hosted_file_id}`
);
}
if (!hosted_file_id) {
console.log(`ERROR: Events Launcher - Event File - hosted_file_id required to create`);
return false;
}
if (!hosted_file_id) return false;
const endpoint = `/event/file/from_hosted_file/${hosted_file_id}`;
if (return_obj) {
params['return_obj'] = true;
}
if (inc_hosted_file) {
params['inc_hosted_file'] = true;
}
const event_file_obj_post_promise = await api
.post_object({
api_cfg: api_cfg,
endpoint: endpoint,
params: params,
data: data,
// return_obj: return_obj,
return_meta: return_meta,
log_lvl: log_lvl
})
.then(function (result) {
console.log('POST DONE create_event_file_obj_from_hosted_file');
console.log(result);
return result;
})
.catch(function (error: any) {
console.log(error);
return false; // Returning false since something may have gone wrong. Also more in line with what the API returns.
// return error;
});
const query_params = { ...params };
if (return_obj) query_params['return_obj'] = true;
if (inc_hosted_file) query_params['inc_hosted_file'] = true;
// console.log(event_file_obj_post_promise);
if (return_obj) {
return event_file_obj_post_promise;
} else {
return event_file_obj_post_promise.event_file_id_random;
}
const result = await api.post_object({
api_cfg,
endpoint,
params: query_params,
data,
log_lvl
});
if (return_obj) return result;
return result?.event_file_id_random;
}
// Updated 2025-07-21
// Updated 2026-01-20 to V3
export async function delete_ae_obj_id__event_file({
api_cfg,
event_file_id,
@@ -277,42 +206,23 @@ export async function delete_ae_obj_id__event_file({
try_cache?: boolean;
log_lvl?: number;
}) {
if (log_lvl) {
console.log(`*** delete_ae_obj_id__event_file() *** event_file_id=${event_file_id}`);
// V3 delete handles orphans via policy or explicit params
const result = await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
obj_id: event_file_id,
params: { ...params, delete_hosted_file: true, rm_orphan: true },
log_lvl
});
if (try_cache) {
await db_events.file.delete(event_file_id);
}
const endpoint = `/event/file/${event_file_id}/v2`;
params['delete_hosted_file'] = true; // This does not actually delete the hosted file from the server.
params['rm_orphan'] = true; // This is what actually allows the hosted file to be deleted from the server.
ae_promises.delete__event_file_obj = await api
.delete_object({
api_cfg: api_cfg,
endpoint: endpoint,
params: params,
// return_meta: return_meta,
log_lvl: log_lvl
})
.finally(function () {
if (try_cache) {
if (log_lvl) {
console.log(
`Attempting to remove IDB entry for event_file_id=${event_file_id}`
);
}
db_events.file.delete(event_file_id); // Delete from the DB no matter what.
}
});
if (log_lvl) {
console.log('ae_promises.delete__event_file_obj:', ae_promises.delete__event_file_obj);
}
return ae_promises.delete__event_file_obj;
return result;
}
// Updated 2025-07-21
// Updated 2026-01-20 to V3
export async function update_ae_obj__event_file({
api_cfg,
event_file_id,
@@ -328,401 +238,116 @@ export async function update_ae_obj__event_file({
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventFile | null> {
if (log_lvl) {
console.log(`*** update_ae_obj__event_file() *** event_file_id=${event_file_id}`);
}
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
obj_id: event_file_id, // NOTE: This is the FQDN, not normally the ID.
obj_id: event_file_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
params,
log_lvl
});
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: [result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__event_file({
// obj_type: 'event_file',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update event file.');
return null;
}
}
// This new function is using CRUD v2. This should allow for more flexibility in the queries.
// Updated 2025-07-21
export async function qry__event_file({
api_cfg,
event_id,
qry_created_on = null, // Example greater than: '2024-10-24'
qry_min_file_size = null,
qry_file_purpose = null,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 49,
offset = 0,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
created_on: 'DESC',
updated_on: 'DESC',
filename: 'ASC',
extension: 'ASC',
hosted_file_size: 'ASC'
} as const,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_id: any;
qry_created_on?: null | string;
qry_min_file_size?: null | number;
qry_file_purpose?: null | string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
limit?: number;
offset?: number;
order_by_li?: key_val;
params?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<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 (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.load__event_file_obj_li:', ae_promises.load__event_file_obj_li);
}
return ae_promises.load__event_file_obj_li;
return result;
}
// Updated 2025-07-21
// Updated 2026-01-20 to V3
export async function search__event_file({
api_cfg,
event_id,
created_on = null,
qry_str = '',
min_file_size = null,
fulltext_search_qry_str,
ft_file_search_qry_str,
like_search_qry_str = null,
like_presentation_search_qry_str = null,
like_file_search_qry_str = null,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
created_on: 'DESC',
updated_on: 'DESC',
filename: 'ASC',
extension: 'ASC',
hosted_file_size: 'ASC'
} as const,
params = {},
enabled = 'enabled',
hidden = 'not_hidden',
limit = 25,
offset = 0,
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_id: any;
created_on?: null | string;
event_id: string;
qry_str?: string;
min_file_size?: null | number;
fulltext_search_qry_str?: null | string;
ft_file_search_qry_str?: null | string;
like_search_qry_str?: null | string;
like_presentation_search_qry_str?: null | string;
like_file_search_qry_str?: null | string;
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
params?: any;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventFile[]> {
if (log_lvl) {
console.log(`*** search__event_file() *** event_id=${event_id}`);
}
const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled';
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden';
const limit: number = params.qry__limit ?? 25; // 99
const offset: number = params.qry__offset ?? 0; // 0
const params_json: key_val = {};
// if (!fulltext_search_qry_str && !like_search_qry_str) {
// console.log('No search string provided!!!');
// return false; // Returning false instead of [] because no search was performed.
// }
if (fulltext_search_qry_str || ft_file_search_qry_str) {
params_json['ft_qry'] = {};
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str;
}
if (ft_file_search_qry_str && ft_file_search_qry_str.length > 2) {
params_json['ft_qry']['event_file_li_qry_str'] = ft_file_search_qry_str;
}
}
// Use the AND (AND LIKE) query
// if (like_search_qry_str || like_file_search_qry_str) {
// params_json['and_like'] = {};
// if (like_search_qry_str && like_search_qry_str.length > 2) {
// params_json['and_like']['default_qry_str'] = like_search_qry_str;
// }
// if (like_file_search_qry_str && like_file_search_qry_str.length > 2) {
// params_json['and_like']['event_file_li_qry_str'] = like_file_search_qry_str;
// }
// }
// Use the AND (OR LIKE) query
// if (like_search_qry_str || like_presentation_search_qry_str || like_file_search_qry_str) {
// params_json['or_like'] = {};
// if (like_search_qry_str && like_search_qry_str.length > 2) {
// params_json['or_like']['default_qry_str'] = like_search_qry_str;
// }
// if (like_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) {
// params_json['or_like']['event_presentation_li_qry_str'] = like_presentation_search_qry_str;
// }
// if (like_file_search_qry_str && like_file_search_qry_str.length > 2) {
// params_json['or_like']['event_file_li_qry_str'] = like_file_search_qry_str;
// }
// }
// params_json['and_qry'] = {};
// if (created_on) {
// params_json['and_qry']['created_on'] = created_on;
// }
const search_query: any = {
q: qry_str,
and: [{ field: 'event_id_random', op: 'eq', value: event_id }]
};
if (min_file_size) {
params_json['and_qry'] = { hosted_file_size: { '>': min_file_size } };
search_query.and.push({ field: 'hosted_file_size', op: 'gt', value: min_file_size });
}
ae_promises.load__event_file_obj_li = await api
.get_ae_obj_li_for_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_file',
for_obj_type: 'event',
for_obj_id: event_id,
use_alt_table: true, // NOTE: We want to use the alt table for file searching?
use_alt_base: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (event_file_obj_li_get_result) {
if (event_file_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: event_file_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
const result_li = await api.search_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
search_query,
order_by_li,
limit,
offset,
log_lvl
});
// db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result});
}
return event_file_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) {
console.log('ae_promises.load__event_file_obj_li:', ae_promises.load__event_file_obj_li);
if (result_li && try_cache) {
const processed_obj_li = await process_ae_obj__event_file_props({
obj_li: result_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return ae_promises.load__event_file_obj_li;
return result_li || [];
}
// Updated 2025-05-23
export const properties_to_save = [
'id',
// 'id_random',
'event_file_id',
// 'event_file_id_random',
'hosted_file_id',
// 'hosted_file_id_random',
'hash_sha256',
'for_type',
'for_id',
// 'for_id_random',
'event_id',
// 'event_id_random',
'event_session_id',
// 'event_session_id_random',
'event_presentation_id',
// 'event_presentation_id_random',
'event_presenter_id',
// 'event_presenter_id_random',
'event_location_id',
// 'event_location_id_random',
'filename',
'extension',
'open_in_os',
'lu_file_purpose_id',
'lu_event_file_purpose_name',
'file_purpose',
'enable',
'hide',
'priority',
@@ -731,19 +356,13 @@ export const properties_to_save = [
'notes',
'created_on',
'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1',
'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
'filename_no_ext',
'filename_w_ext',
'hosted_file_content_type',
'file_size',
'hosted_file_size',
'event_location_code',
'event_location_name',
'event_session_code',
@@ -764,7 +383,6 @@ export const properties_to_save = [
/**
* NON-EXPORTED LOCAL HELPER
* Processes a list of Aether objects by applying common and specific transformations.
*/
async function _process_generic_props<T extends Record<string, any>>({
obj_li,
@@ -777,39 +395,24 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> {
if (log_lvl > 0) {
console.log(
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
);
}
if (!obj_li || obj_li.length === 0) {
if (log_lvl > 0) console.log('No objects to process.');
return [];
}
if (!obj_li || obj_li.length === 0) return [];
const processed_obj_li: T[] = [];
for (const original_obj of obj_li) {
let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
for (const key in processed_obj) {
if (key.endsWith('_random')) {
const newKey = key.slice(0, -7); // Remove '_random' suffix
const newKey = key.slice(0, -7);
(processed_obj as any)[newKey] = processed_obj[key];
}
}
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) {
(processed_obj as any).id = processed_obj[randomIdKey];
}
// 2. Create common computed properties for client-side sorting.
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
@@ -819,7 +422,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj));
}
@@ -830,7 +432,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li;
}
// Updated 2025-05-23
export async function process_ae_obj__event_file_props({
obj_li,
log_lvl = 0
@@ -841,17 +442,6 @@ export async function process_ae_obj__event_file_props({
return _process_generic_props({
obj_li,
obj_type: 'event_file',
log_lvl,
specific_processor: (obj) => {
// Event file-specific computed sort fields, overriding generic ones if needed
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;
obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on}_${obj.created_on}`;
return obj;
}
log_lvl
});
}
}

View File

@@ -11,13 +11,14 @@ import { load_ae_obj_li__event_session } from './ae_events__event_session';
const ae_promises: key_val = {};
// Updated 2026-01-16
// Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_location({
api_cfg,
event_location_id,
inc_device_li = false,
inc_file_li = false,
inc_session_li = false,
view = 'default',
try_cache = true,
log_lvl = 0
}: {
@@ -26,38 +27,34 @@ export async function load_ae_obj_id__event_location({
inc_device_li?: boolean;
inc_file_li?: boolean;
inc_session_li?: boolean;
view?: string;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventLocation | null> {
if (log_lvl) {
console.log(
`*** load_ae_obj_id__event_location() *** event_location_id=${event_location_id}`
);
console.log(`*** load_ae_obj_id__event_location() *** [V3] id=${event_location_id}`);
}
const params = {};
// Check if offline
if (typeof navigator !== 'undefined' && !navigator.onLine) {
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.');
ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
if (ae_promises.load__event_location_obj) {
return await _handle_nested_loads(ae_promises.load__event_location_obj, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
return await _handle_nested_loads(ae_promises.load__event_location_obj, {
api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl
});
}
return null;
}
try {
ae_promises.load__event_location_obj = await api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_location',
obj_id: event_location_id, // NOTE: This is the FQDN, not normally the ID.
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
params: params,
log_lvl: log_lvl
});
ae_promises.load__event_location_obj = await api.get_ae_obj_v3({
api_cfg,
obj_type: 'event_location',
obj_id: event_location_id,
view,
log_lvl
});
if (ae_promises.load__event_location_obj) {
if (try_cache) {
@@ -73,121 +70,104 @@ export async function load_ae_obj_id__event_location({
log_lvl
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
}
} else if (try_cache) {
ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
}
} catch (error: any) {
console.log('API request failed.', error);
console.log('V3 Request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
} else {
ae_promises.load__event_location_obj = null;
}
}
if (!ae_promises?.load__event_location_obj) {
return null;
}
if (!ae_promises.load__event_location_obj) return null;
return await _handle_nested_loads(ae_promises.load__event_location_obj, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
return await _handle_nested_loads(ae_promises.load__event_location_obj, {
api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl
});
}
/**
* Helper to handle nested collection loads for a location
*/
async function _handle_nested_loads(location_obj: any, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }: any) {
const current_location_id = location_obj.event_location_id || location_obj.id;
const current_location_id = location_obj.event_location_id_random || location_obj.event_location_id || location_obj.id;
if (inc_device_li) {
location_obj.event_device_obj_li = await load_ae_obj_li__event_device({
api_cfg: api_cfg,
api_cfg,
for_obj_type: 'event_location',
for_obj_id: current_location_id,
log_lvl: log_lvl
log_lvl
});
}
if (inc_file_li) {
// Load the files for the location
location_obj.event_file_li = await load_ae_obj_li__event_file({
api_cfg: api_cfg,
api_cfg,
for_obj_type: 'event_location',
for_obj_id: current_location_id,
enabled: 'all',
limit: 15,
try_cache: try_cache,
log_lvl: log_lvl
try_cache,
log_lvl
});
}
if (inc_session_li) {
// Load the sessions for the location
location_obj.event_session_li = await load_ae_obj_li__event_session({
api_cfg: api_cfg,
api_cfg,
for_obj_type: 'event_location',
for_obj_id: current_location_id,
enabled: 'all',
limit: 15,
try_cache: try_cache,
log_lvl: log_lvl
try_cache,
log_lvl
});
}
return location_obj;
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function load_ae_obj_li__event_location({
api_cfg,
for_obj_type,
for_obj_type = 'event',
for_obj_id,
inc_device_li = false,
inc_file_li = false,
inc_session_li = false,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 29,
limit = 50,
offset = 0,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
name: 'ASC',
code: 'ASC',
updated_on: 'DESC',
created_on: 'DESC'
},
params = {},
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
for_obj_type: string;
for_obj_type?: string;
for_obj_id: string;
inc_device_li?: boolean;
inc_file_li?: boolean;
inc_session_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden
limit?: number; // 99
offset?: number; // 0
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
params?: key_val;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventLocation[]> {
if (log_lvl) {
console.log(
`*** load_ae_obj_li__event_location() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
console.log(`*** load_ae_obj_li__event_location() *** [V3] for=${for_obj_type}:${for_obj_id}`);
}
const params_json: key_val = {};
// Check if offline
if (typeof navigator !== 'undefined' && !navigator.onLine) {
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.');
@@ -195,388 +175,256 @@ export async function load_ae_obj_li__event_location({
.where('event_id').equals(for_obj_id)
.toArray();
if (ae_promises.load__event_location_obj_li) {
for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) {
await _handle_nested_loads(ae_promises.load__event_location_obj_li[i], { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
for (const loc of ae_promises.load__event_location_obj_li) {
await _handle_nested_loads(loc, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
}
}
return ae_promises.load__event_location_obj_li || [];
}
try {
ae_promises.load__event_location_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'event_location',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
});
ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_v3({
api_cfg,
obj_type: 'event_location',
for_obj_type,
for_obj_id,
enabled,
hidden,
limit,
offset,
order_by_li,
log_lvl
});
if (ae_promises.load__event_location_obj_li) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: ae_promises.load__event_location_obj_li,
log_lvl: log_lvl
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
properties_to_save,
log_lvl
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_location_obj_li = await db_events.location
.where('event_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_location_obj_li = [];
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
} else if (try_cache) {
ae_promises.load__event_location_obj_li = await db_events.location
.where('event_id').equals(for_obj_id)
.toArray();
}
} catch (error: any) {
console.log('V3 List Request failed.', error);
if (try_cache) {
ae_promises.load__event_location_obj_li = await db_events.location
.where('event_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_location_obj_li = [];
}
}
if (ae_promises.load__event_location_obj_li) {
for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) {
await _handle_nested_loads(ae_promises.load__event_location_obj_li[i], { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
for (const loc of ae_promises.load__event_location_obj_li) {
await _handle_nested_loads(loc, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
}
}
return ae_promises.load__event_location_obj_li;
return ae_promises.load__event_location_obj_li || [];
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function create_ae_obj__event_location({
api_cfg,
event_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_id: string;
data_kv: key_val;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventLocation | null> {
if (log_lvl) {
console.log(`*** create_ae_obj__event_location() *** event_id=${event_id}`);
console.log(`*** create_ae_obj__event_location() *** [V3] event_id=${event_id}`);
}
ae_promises.create__event_location = await api
.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'event_location',
fields: {
event_id_random: event_id,
...data_kv
},
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (event_location_obj_create_result) {
if (event_location_obj_create_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: [event_location_obj_create_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return event_location_obj_create_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
const result = await api.create_ae_obj_v3({
api_cfg,
obj_type: 'event_location',
fields: {
event_id_random: event_id,
...data_kv
},
log_lvl
});
return ae_promises.create__event_location;
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return result;
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function delete_ae_obj_id__event_location({
api_cfg,
event_location_id,
method = 'delete', // 'delete', 'disable', 'hide'
params = {},
method = 'delete',
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_location_id: string;
method?: string;
params?: key_val;
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
try_cache?: boolean;
log_lvl?: number;
}) {
if (log_lvl) {
console.log(
`*** delete_ae_obj_id__event_location() *** event_location_id=${event_location_id}`
);
console.log(`*** delete_ae_obj_id__event_location() *** [V3] id=${event_location_id}`);
}
ae_promises.delete__event_location_obj = await api
.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_location',
obj_id: event_location_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
log_lvl: log_lvl
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {
if (try_cache) {
if (log_lvl) {
console.log(
`Attempting to remove IDB entry for event_location_id=${event_location_id}`
);
}
db_events.location.delete(event_location_id);
}
});
const result = await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'event_location',
obj_id: event_location_id,
method,
log_lvl
});
return ae_promises.delete__event_location_obj;
if (try_cache) {
await db_events.location.delete(event_location_id);
}
return result;
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function update_ae_obj__event_location({
api_cfg,
event_location_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_location_id: string;
data_kv: key_val;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventLocation | null> {
if (log_lvl) {
console.log(
`*** update_ae_obj__event_location() *** event_location_id=${event_location_id}`,
data_kv
);
console.log(`*** update_ae_obj__event_location() *** [V3] id=${event_location_id}`);
}
ae_promises.update__event_location_obj = await api
.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_location',
obj_id: event_location_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (event_location_obj_update_result) {
if (event_location_obj_update_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: [event_location_obj_update_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return event_location_obj_update_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
return ae_promises.update__event_location_obj;
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'event_location',
obj_id: event_location_id,
fields: data_kv,
log_lvl
});
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return result;
}
// Updated 2025-05-23
// Updated 2026-01-20 to V3
export async function search__event_location({
api_cfg,
event_id,
fulltext_search_qry_str,
ft_presenter_search_qry_str,
like_search_qry_str = null,
like_presentation_search_qry_str = null,
like_presenter_search_qry_str = null,
params = {},
qry_str = '',
enabled = 'enabled',
hidden = 'not_hidden',
limit = 25,
offset = 0,
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_id: any;
fulltext_search_qry_str?: null | string;
ft_presenter_search_qry_str?: null | string;
like_search_qry_str?: null | string;
like_presentation_search_qry_str?: null | string;
like_presenter_search_qry_str?: null | string;
params?: any;
event_id: string;
qry_str?: string;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventLocation[] | false> {
}): Promise<ae_EventLocation[]> {
if (log_lvl) {
console.log(`*** search__event_location() *** event_id=${event_id}`);
console.log(`*** search__event_location() *** [V3] event_id=${event_id} qry=${qry_str}`);
}
const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled';
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden';
const limit: number = params.qry__limit ?? 25;
const offset: number = params.qry__offset ?? 0;
const search_query: any = {
q: qry_str,
and: [{ field: 'event_id_random', op: 'eq', value: event_id }]
};
const params_json: key_val = {};
if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true });
else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: false });
if (!fulltext_search_qry_str && !like_search_qry_str) {
console.log('No search string provided!!!');
return false;
}
if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true });
else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: false });
if (fulltext_search_qry_str || ft_presenter_search_qry_str) {
params_json['ft_qry'] = {};
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str;
}
const result_li = await api.search_ae_obj_v3({
api_cfg,
obj_type: 'event_location',
search_query,
order_by_li,
limit,
offset,
log_lvl
});
if (ft_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) {
params_json['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str;
}
}
if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_search_qry_str) {
params_json['or_like'] = {};
if (like_search_qry_str && like_search_qry_str.length > 2) {
params_json['or_like']['default_qry_str'] = like_search_qry_str;
}
if (like_presentation_search_qry_str && like_presentation_search_qry_str.length > 2) {
params_json['or_like']['event_presentation_li_qry_str'] =
like_presentation_search_qry_str;
}
if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) {
params_json['or_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str;
}
}
params_json['and_qry'] = {};
const order_by_li = {
priority: 'DESC',
sort: 'DESC',
start_datetime: 'ASC',
name: 'ASC',
updated_on: 'DESC',
created_on: 'DESC'
} as const;
ae_promises.load__event_location_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'event_location',
for_obj_type: 'event',
for_obj_id: event_id,
use_alt_tbl: true,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (event_location_obj_li_get_result) {
if (event_location_obj_li_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: event_location_obj_li_get_result,
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
return event_location_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
if (result_li && try_cache) {
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: result_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return ae_promises.load__event_location_obj_li;
return result_li || [];
}
// Updated 2025-05-23
export const properties_to_save = [
'id',
'event_location_id',
@@ -656,7 +504,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li;
}
// Updated 2025-05-23
export async function process_ae_obj__event_location_props({
obj_li,
log_lvl = 0
@@ -667,16 +514,6 @@ export async function process_ae_obj__event_location_props({
return _process_generic_props({
obj_li,
obj_type: 'event_location',
log_lvl,
specific_processor: (obj) => {
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;
obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on}_${obj.created_on}`;
return obj;
}
log_lvl
});
}

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 = {};
// Updated 2025-05-22
// Updated 2026-01-20 to V3
export async function load_ae_obj_id__event_presentation({
api_cfg,
event_presentation_id,
@@ -18,7 +18,8 @@ export async function load_ae_obj_id__event_presentation({
inc_presenter_li = false,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 49,
view = 'default',
limit = 100,
offset = 0,
try_cache = true,
log_lvl = 0
@@ -27,147 +28,95 @@ export async function load_ae_obj_id__event_presentation({
event_presentation_id: string;
inc_file_li?: boolean;
inc_presenter_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
view?: string;
limit?: number;
offset?: number;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventPresentation | null> {
if (log_lvl) {
console.log(
`*** load_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}`
);
console.log(`*** load_ae_obj_id__event_presentation() *** [V3] id=${event_presentation_id}`);
}
const params = {};
ae_promises.load__event_presentation_obj = await api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
try {
ae_promises.load__event_presentation_obj = await api.get_ae_obj_v3({
api_cfg,
obj_type: 'event_presentation',
obj_id: event_presentation_id, // NOTE: This is the FQDN, not normally the ID.
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value
params: params,
log_lvl: log_lvl
})
.then(async function (event_presentation_obj_get_result) {
if (event_presentation_obj_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: [event_presentation_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// db_save_ae_obj_li__event_presentation({
// obj_type: 'event_presentation',
// obj_li: [event_presentation_obj_get_result]
// });
}
return event_presentation_obj_get_result;
} else {
console.log('No results returned.');
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
obj_id: event_presentation_id,
view,
log_lvl
});
if (log_lvl) {
console.log(
'ae_promises.load__event_presentation_obj:',
ae_promises.load__event_presentation_obj
);
if (ae_promises.load__event_presentation_obj) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: [ae_promises.load__event_presentation_obj],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
} else if (try_cache) {
ae_promises.load__event_presentation_obj = await db_events.presentation.get(event_presentation_id);
}
} catch (error: any) {
console.log('V3 Request failed.', error);
if (try_cache) {
ae_promises.load__event_presentation_obj = await db_events.presentation.get(event_presentation_id);
}
}
if (ae_promises?.load__event_presentation_obj === null) {
console.log('No results returned.');
return null;
}
if (!ae_promises.load__event_presentation_obj) return null;
return await _handle_nested_loads(ae_promises.load__event_presentation_obj, {
api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl
});
}
/**
* Helper to handle nested collection loads for a presentation
*/
async function _handle_nested_loads(presentation_obj: any, { api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }: any) {
const current_presentation_id = presentation_obj.event_presentation_id_random || presentation_obj.event_presentation_id || presentation_obj.id;
if (inc_file_li) {
// Load the files for the presentation
if (log_lvl) {
console.log(`Need to load the file list for the presentation now.`);
}
const load_event_file_obj_li = load_ae_obj_li__event_file({
api_cfg: api_cfg,
presentation_obj.event_file_li = await load_ae_obj_li__event_file({
api_cfg,
for_obj_type: 'event_presentation',
for_obj_id: event_presentation_id,
enabled: 'all',
for_obj_id: current_presentation_id,
enabled,
limit: 25,
try_cache: try_cache,
log_lvl: log_lvl
}).then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
try_cache,
log_lvl
});
if (log_lvl) {
console.log(`event_file_obj_li = `, load_event_file_obj_li);
}
ae_promises.load__event_presentation_obj.event_file_li = load_event_file_obj_li;
}
if (inc_presenter_li) {
// Load the presenters for the presentation
if (log_lvl) {
console.log(`Need to load the presenter list for the presentation now.`);
}
const load_event_presenter_obj_li = load_ae_obj_li__event_presenter({
api_cfg: api_cfg,
presentation_obj.event_presenter_li = await load_ae_obj_li__event_presenter({
api_cfg,
for_obj_type: 'event_presentation',
for_obj_id: event_presentation_id,
inc_file_li: inc_file_li,
enabled: enabled,
hidden: hidden,
limit: limit,
offset: offset,
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'},
// params: params,
try_cache: try_cache,
log_lvl: log_lvl
}).then((event_presenter_obj_li) => {
if (log_lvl) {
console.log(`event_presenter_obj_li = `, event_presenter_obj_li);
}
return event_presenter_obj_li;
for_obj_id: current_presentation_id,
inc_file_li,
enabled,
hidden,
limit,
offset,
try_cache,
log_lvl
});
if (log_lvl) {
console.log(`event_presenter_obj_li = `, load_event_presenter_obj_li);
}
ae_promises.load__event_presentation_obj.event_presenter_li = load_event_presenter_obj_li;
}
return ae_promises.load__event_presentation_obj;
return presentation_obj;
}
// Updated 2025-05-22
// Updated 2026-01-20 to V3
export async function load_ae_obj_li__event_presentation({
api_cfg,
for_obj_type = 'event_session',
@@ -176,190 +125,94 @@ export async function load_ae_obj_li__event_presentation({
inc_presenter_li = false,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 49,
limit = 50,
offset = 0,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
start_datetime: 'ASC',
name: 'ASC',
updated_on: 'DESC',
created_on: 'DESC'
} as const,
params = {},
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ start_datetime: 'ASC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
for_obj_type: string;
for_obj_type?: string;
for_obj_id: string;
inc_file_li?: boolean;
inc_presenter_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: key_val;
params?: key_val;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventPresentation[]> {
if (log_lvl) {
console.log(
`*** load_ae_obj_li__event_presentation() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
console.log(`*** load_ae_obj_li__event_presentation() *** [V3] for=${for_obj_type}:${for_obj_id}`);
}
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
// let limit: number = (params.qry__limit ?? 99); // 99
// let offset: number = (params.qry__offset ?? 0); // 0
const params_json: key_val = {};
// console('params_json:', params_json);
// ae_promises.load__event_presentation_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
ae_promises.load__event_presentation_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
try {
ae_promises.load__event_presentation_obj_li = await api.get_ae_obj_li_v3({
api_cfg,
obj_type: 'event_presentation',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
// use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (event_presentation_obj_li_get_result) {
if (event_presentation_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: event_presentation_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event_presentation({
// obj_type: 'event_presentation', obj_li: event_presentation_obj_li_get_result
// });
}
return event_presentation_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
for_obj_type,
for_obj_id,
enabled,
hidden,
limit,
offset,
order_by_li,
log_lvl
});
if (log_lvl) {
console.log(
'ae_promises.load__event_presentation_obj_li:',
ae_promises.load__event_presentation_obj_li
);
}
if (inc_file_li) {
// Load the files for the presentations
if (log_lvl) {
console.log(`Need to load the file list for each presentation now.`);
}
for (let i = 0; i < ae_promises.load__event_presentation_obj_li.length; i++) {
const event_presentation_obj = ae_promises.load__event_presentation_obj_li[i];
const event_presentation_id = event_presentation_obj.event_presentation_id_random;
const load_event_file_obj_li = load_ae_obj_li__event_file({
api_cfg: api_cfg,
for_obj_type: 'event_presentation',
for_obj_id: event_presentation_id,
enabled: enabled,
limit: limit,
try_cache: try_cache,
log_lvl: log_lvl
}).then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
});
if (log_lvl) {
console.log(`event_file_obj_li = `, load_event_file_obj_li);
if (ae_promises.load__event_presentation_obj_li) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: ae_promises.load__event_presentation_obj_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
// ae_promises.load__event_presentation_obj.event_file_li = load_event_file_obj_li;
} else if (try_cache) {
ae_promises.load__event_presentation_obj_li = await db_events.presentation
.where('event_session_id').equals(for_obj_id)
.toArray();
}
} catch (error: any) {
console.log('V3 List Request failed.', error);
if (try_cache) {
ae_promises.load__event_presentation_obj_li = await db_events.presentation
.where('event_session_id').equals(for_obj_id)
.toArray();
}
}
if (inc_presenter_li) {
// Load the presenters for the presentations
if (log_lvl) {
console.log(`Need to load the presenter list for each presentation now.`);
}
for (let i = 0; i < ae_promises.load__event_presentation_obj_li.length; i++) {
const event_presentation_obj = ae_promises.load__event_presentation_obj_li[i];
const event_presentation_id = event_presentation_obj.event_presentation_id_random;
const load_event_presenter_obj_li = load_ae_obj_li__event_presenter({
api_cfg: api_cfg,
for_obj_type: 'event_presentation',
for_obj_id: event_presentation_id,
inc_file_li: inc_file_li,
enabled: enabled,
hidden: hidden,
limit: limit,
offset: offset,
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'},
// params: {},
try_cache: try_cache,
log_lvl: log_lvl
}).then((event_presenter_obj_li) => {
if (log_lvl) {
console.log(`event_presenter_obj_li = `, event_presenter_obj_li);
}
return event_presenter_obj_li;
if (ae_promises.load__event_presentation_obj_li) {
for (const presentation of ae_promises.load__event_presentation_obj_li) {
await _handle_nested_loads(presentation, {
api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl
});
if (log_lvl) {
console.log(`event_presenter_obj_li = `, load_event_presenter_obj_li);
}
// ae_promises.load__event_presentation_obj.event_presenter_li = load_event_presenter_obj_li;
}
}
return ae_promises.load__event_presentation_obj_li;
return ae_promises.load__event_presentation_obj_li || [];
}
// Updated 2025-05-22
// Updated 2026-01-20 to V3
export async function create_ae_obj__event_presentation({
api_cfg,
event_id,
event_session_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0
}: {
@@ -367,255 +220,135 @@ export async function create_ae_obj__event_presentation({
event_id: string;
event_session_id: string;
data_kv: key_val;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventPresentation | null> {
if (log_lvl) {
console.log(
`*** create_ae_obj__event_presentation() *** event_id=${event_id} event_session_id=${event_session_id}`
);
console.log(`*** create_ae_obj__event_presentation() *** [V3] session=${event_session_id}`);
}
ae_promises.create__event_presentation = await api
.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'event_presentation',
fields: {
event_id_random: event_id,
event_session_id_random: event_session_id,
...data_kv
},
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (event_presentation_obj_create_result) {
if (event_presentation_obj_create_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: [event_presentation_obj_create_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
const result = await api.create_ae_obj_v3({
api_cfg,
obj_type: 'event_presentation',
fields: {
event_id_random: event_id,
event_session_id_random: event_session_id,
...data_kv
},
log_lvl
});
// db_save_ae_obj_li__event_presentation(
// {
// obj_type: 'event_presentation',
// obj_li: [event_presentation_obj_create_result]
// });
}
return event_presentation_obj_create_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) {
console.log(
'ae_promises.create__event_presentation:',
ae_promises.create__event_presentation
);
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return ae_promises.create__event_presentation;
return result;
}
// Updated 2025-05-22
// Updated 2026-01-20 to V3
export async function delete_ae_obj_id__event_presentation({
api_cfg,
event_presentation_id,
method = 'delete', // 'delete', 'disable', 'hide'
params = {},
method = 'delete',
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_presentation_id: string;
method?: string;
params?: key_val;
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
try_cache?: boolean;
log_lvl?: number;
}) {
if (log_lvl) {
console.log(
`*** delete_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}`
);
console.log(`*** delete_ae_obj_id__event_presentation() *** [V3] id=${event_presentation_id}`);
}
ae_promises.delete__event_presentation_obj = await api
.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_presentation',
obj_id: event_presentation_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
log_lvl: log_lvl
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {
if (try_cache) {
if (log_lvl) {
console.log(
`Attempting to remove IDB entry for event_presentation_id=${event_presentation_id}`
);
}
db_events.presentation.delete(event_presentation_id);
}
});
const result = await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'event_presentation',
obj_id: event_presentation_id,
method,
log_lvl
});
if (log_lvl) {
console.log(
'ae_promises.delete__event_presentation_obj:',
ae_promises.delete__event_presentation_obj
);
if (try_cache) {
await db_events.presentation.delete(event_presentation_id);
}
return ae_promises.delete__event_presentation_obj;
return result;
}
// Updated 2025-05-22
// Updated 2026-01-20 to V3
export async function update_ae_obj__event_presentation({
api_cfg,
event_presentation_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
event_presentation_id: string;
data_kv: key_val;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventPresentation | null> {
if (log_lvl) {
console.log(
`*** update_ae_obj__event_presentation() *** event_presentation_id=${event_presentation_id}`,
data_kv
);
console.log(`*** update_ae_obj__event_presentation() *** [V3] id=${event_presentation_id}`);
}
ae_promises.update__event_presentation_obj = await api
.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_presentation',
obj_id: event_presentation_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (event_presentation_obj_update_result) {
if (event_presentation_obj_update_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: [event_presentation_obj_update_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event_presentation({
// obj_type: 'event_presentation',
// obj_li: [event_presentation_obj_update_result],
// log_lvl: log_lvl
// });
}
return event_presentation_obj_update_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'event_presentation',
obj_id: event_presentation_id,
fields: data_kv,
log_lvl
});
if (log_lvl) {
console.log(
'ae_promises.update__event_presentation_obj:',
ae_promises.update__event_presentation_obj
);
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_presentation_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'presentation',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return ae_promises.update__event_presentation_obj;
return result;
}
// Updated 2025-05-22
export const properties_to_save = [
'id',
'event_presentation_id',
// 'event_presentation_id_random',
'external_id',
'code',
'for_type',
'for_id',
// 'for_id_random',
'type_code',
'event_id',
// 'event_id_random',
'event_session_id',
// 'event_session_id_random',
'event_abstract_id',
// 'event_abstract_id_random',
'abstract_code',
'name',
'description',
'start_datetime',
'end_datetime',
'passcode',
'hide_event_launcher',
'enable',
'hide',
'priority',
@@ -624,18 +357,10 @@ export const properties_to_save = [
'notes',
'created_on',
'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1',
'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
'event_session_code',
'event_session_name'
// Add more fields here if your DB save logic uses them
];
/**
@@ -653,39 +378,26 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> {
if (log_lvl > 0) {
console.log(
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
);
}
if (!obj_li || obj_li.length === 0) {
if (log_lvl > 0) console.log('No objects to process.');
return [];
}
if (!obj_li || obj_li.length === 0) return [];
const processed_obj_li: T[] = [];
for (const original_obj of obj_li) {
let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
for (const key in processed_obj) {
if (key.endsWith('_random')) {
const newKey = key.slice(0, -7); // Remove '_random' suffix
const newKey = key.slice(0, -7);
(processed_obj as any)[newKey] = processed_obj[key];
}
}
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) {
(processed_obj as any).id = processed_obj[randomIdKey];
}
// 2. Create common computed properties for client-side sorting.
// 2. Create common computed properties
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
@@ -695,7 +407,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj));
}
@@ -706,7 +417,6 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li;
}
// Updated 2025-05-22
export async function process_ae_obj__event_presentation_props({
obj_li,
log_lvl = 0
@@ -717,17 +427,6 @@ export async function process_ae_obj__event_presentation_props({
return _process_generic_props({
obj_li,
obj_type: 'event_presentation',
log_lvl,
specific_processor: (obj) => {
// Event presentation-specific computed sort fields, overriding generic ones if needed
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;
obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on}_${obj.created_on}`;
return obj;
}
log_lvl
});
}
}

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

View File

@@ -1,11 +1,8 @@
import type { key_val } from '$lib/stores/ae_stores';
import { api } from '$lib/api/api';
import { db_sponsorships } from '$lib/ae_sponsorships/db_sponsorships';
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
// import { liveQuery } from "dexie";
// import { db_core } from "$lib/db_core";
import type { ae_Sponsorship, ae_Sponsorship_Cfg } from '$lib/types/ae_types';
const ae_promises: key_val = {};
@@ -46,7 +43,7 @@ export async function process_ae_obj__sponsorship_cfg_props({
obj_type: 'sponsorship_cfg',
log_lvl,
specific_processor: (obj) => {
// Sponsorship Cfg-specific computed sort fields, overriding generic ones if needed
// Sponsorship Cfg-specific computed sort fields
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;
@@ -112,7 +109,7 @@ export async function process_ae_obj__sponsorship_props({
obj_type: 'sponsorship',
log_lvl,
specific_processor: (obj) => {
// Sponsorship-specific computed sort fields, overriding generic ones if needed
// Sponsorship-specific computed sort fields
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;
@@ -156,13 +153,10 @@ async function _process_generic_props<T extends Record<string, any>>({
for (const original_obj of obj_li) {
let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
for (const key in processed_obj) {
if (key.endsWith('_random')) {
const newKey = key.slice(0, -7); // Remove '_random' suffix
const newKey = key.slice(0, -7);
(processed_obj as any)[newKey] = processed_obj[key];
}
}
@@ -172,7 +166,7 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).id = processed_obj[randomIdKey];
}
// 2. Create common computed properties for client-side sorting.
// 2. Create common computed properties
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
@@ -182,7 +176,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj));
}
@@ -193,8 +186,8 @@ async function _process_generic_props<T extends Record<string, any>>({
return processed_obj_li;
}
// Updated 2024-03-29
async function load_ae_obj_id__sponsorship_cfg({
// Updated 2026-01-20 to V3
export async function load_ae_obj_id__sponsorship_cfg({
api_cfg,
sponsorship_cfg_id,
try_cache = false,
@@ -202,85 +195,41 @@ async function load_ae_obj_id__sponsorship_cfg({
}: {
api_cfg: any;
sponsorship_cfg_id: string;
try_cache: boolean;
log_lvl: number;
}) {
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_Sponsorship_Cfg | null> {
if (log_lvl) {
console.log(
`*** load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}`
);
console.log(`*** load_ae_obj_id__sponsorship_cfg() *** [V3] id=${sponsorship_cfg_id}`);
}
const params = {};
const sponsorship_cfg_obj_get_result = await api.get_ae_obj_v3({
api_cfg,
obj_type: 'sponsorship_cfg',
obj_id: sponsorship_cfg_id,
log_lvl
});
ae_promises.load__sponsorship_cfg_obj = api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'sponsorship_cfg',
obj_id: sponsorship_cfg_id,
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
params: params,
log_lvl: log_lvl
})
.then(async function (sponsorship_cfg_obj_get_result) {
if (sponsorship_cfg_obj_get_result) {
if (log_lvl) {
console.log(
`*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}`
);
} else if (log_lvl > 1) {
console.log(
`*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}:`,
sponsorship_cfg_obj_get_result
);
}
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({
obj_li: [sponsorship_cfg_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_sponsorships,
table_name: 'cfg',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_sponsorship_cfg,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return sponsorship_cfg_obj_get_result;
} else {
console.log('No results returned.');
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log(
'ae_promises.load__sponsorship_cfg_obj:',
ae_promises.load__sponsorship_cfg_obj
);
if (sponsorship_cfg_obj_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({
obj_li: [sponsorship_cfg_obj_get_result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_sponsorships,
table_name: 'cfg',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_sponsorship_cfg,
log_lvl
});
}
return sponsorship_cfg_obj_get_result;
}
return ae_promises.load__sponsorship_cfg_obj;
return null;
}
// Updated 2024-03-29
async function load_ae_obj_id__sponsorship({
// Updated 2026-01-20 to V3
export async function load_ae_obj_id__sponsorship({
api_cfg,
sponsorship_id,
try_cache = false,
@@ -288,78 +237,41 @@ async function load_ae_obj_id__sponsorship({
}: {
api_cfg: any;
sponsorship_id: string;
try_cache: boolean;
log_lvl: number;
}) {
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_Sponsorship | null> {
if (log_lvl) {
console.log(`*** load_ae_obj_id__sponsorship() *** sponsorship_id=${sponsorship_id}`);
console.log(`*** load_ae_obj_id__sponsorship() *** [V3] id=${sponsorship_id}`);
}
const params = {};
const sponsorship_obj_get_result = await api.get_ae_obj_v3({
api_cfg,
obj_type: 'sponsorship',
obj_id: sponsorship_id,
log_lvl
});
ae_promises.load__sponsorship_obj = api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'sponsorship',
obj_id: sponsorship_id,
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
params: params,
log_lvl: log_lvl
})
.then(async function (sponsorship_obj_get_result) {
if (sponsorship_obj_get_result) {
if (log_lvl) {
console.log(`*spons_func* Got a result for sponsorship_id ${sponsorship_id}`);
} else if (log_lvl > 1) {
console.log(
`*spons_func* Got a result for sponsorship_id ${sponsorship_id}:`,
sponsorship_obj_get_result
);
}
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__sponsorship_props({
obj_li: [sponsorship_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_sponsorships,
table_name: 'sponsorship',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_sponsorship,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return sponsorship_obj_get_result;
} else {
console.log('No results returned.');
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log('ae_promises.load__sponsorship_obj:', ae_promises.load__sponsorship_obj);
if (sponsorship_obj_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__sponsorship_props({
obj_li: [sponsorship_obj_get_result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_sponsorships,
table_name: 'sponsorship',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_sponsorship,
log_lvl
});
}
return sponsorship_obj_get_result;
}
return ae_promises.load__sponsorship_obj;
return null;
}
// Updated 2025-01-15
async function load_ae_obj_li__sponsorship({
// Updated 2026-01-20 to V3
export async function load_ae_obj_li__sponsorship({
api_cfg,
for_obj_type = 'account',
for_obj_id,
@@ -367,146 +279,165 @@ async function load_ae_obj_li__sponsorship({
hidden = 'not_hidden',
limit = 99,
offset = 0,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
name: 'ASC',
updated_on: 'DESC',
created_on: 'DESC'
},
params = {},
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ name: 'ASC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
for_obj_type: string;
for_obj_id: string;
inc_content_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: key_val;
params?: key_val;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}) {
}): Promise<ae_Sponsorship[]> {
if (log_lvl) {
console.log(
`*** load_ae_obj_li__sponsorship() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
);
console.log(`*** load_ae_obj_li__sponsorship() *** [V3] for=${for_obj_type}:${for_obj_id}`);
}
const params_json: key_val = {};
const result_li = await api.get_ae_obj_li_v3({
api_cfg,
obj_type: 'sponsorship',
for_obj_type,
for_obj_id,
enabled,
hidden,
limit,
offset,
order_by_li,
log_lvl
});
ae_promises.load__sponsorship_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'sponsorship',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: false,
use_alt_mdl: false,
use_alt_exp: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (sponsorship_obj_li_get_result) {
if (sponsorship_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__sponsorship_props({
obj_li: sponsorship_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_sponsorships,
table_name: 'sponsorship',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_sponsorship,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return sponsorship_obj_li_get_result;
} else {
return [];
}
if (result_li && try_cache) {
const processed_obj_li = await process_ae_obj__sponsorship_props({
obj_li: result_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_sponsorships,
table_name: 'sponsorship',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_sponsorship,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.load__sponsorship_obj_li:', ae_promises.load__sponsorship_obj_li);
}
return ae_promises.load__sponsorship_obj_li;
return result_li || [];
}
/**
* Create a new sponsorship (V3)
*/
export async function create_ae_obj__sponsorship({
api_cfg,
data,
log_lvl = 0
}: {
api_cfg: any;
data: any;
log_lvl?: number;
}) {
return await api.create_ae_obj_v3({
api_cfg,
obj_type: 'sponsorship',
data,
log_lvl
});
}
/**
* Update sponsorship (V3)
*/
export async function update_ae_obj__sponsorship({
api_cfg,
sponsorship_id,
data,
log_lvl = 0
}: {
api_cfg: any;
sponsorship_id: string;
data: any;
log_lvl?: number;
}) {
return await api.update_ae_obj_v3({
api_cfg,
obj_type: 'sponsorship',
obj_id: sponsorship_id,
data,
log_lvl
});
}
/**
* Delete sponsorship (V3)
*/
export async function delete_ae_obj__sponsorship({
api_cfg,
sponsorship_id,
log_lvl = 0
}: {
api_cfg: any;
sponsorship_id: string;
log_lvl?: number;
}) {
return await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'sponsorship',
obj_id: sponsorship_id,
log_lvl
});
}
export async function download_export__sponsorship({
api_cfg,
account_id,
file_type = 'CSV', // 'CSV' or 'Excel'
return_file = true,
filename = 'no_filename.csv',
auto_download = false,
params = {}, // key value object is expected
file_type = 'CSV',
filename = 'sponsorship_export.csv',
params = {},
log_lvl = 0
}: {
api_cfg: any;
account_id: string;
file_type?: string;
return_file?: boolean;
filename?: string;
auto_download?: boolean;
params?: key_val;
log_lvl?: number;
}) {
console.log('*** stores_event_api.js: get_sponsorship_export() ***');
// V2 still used for exports as V3 generic doesn't have a standardized export wrapper yet
const endpoint = `/v2/crud/sponsorship/list`;
params['for_obj_type'] = 'account';
params['for_obj_id'] = account_id;
const query_params = {
...params,
for_obj_type: 'account',
for_obj_id: account_id,
file_type,
return_file: true
};
if (file_type == 'CSV' || file_type == 'Excel') {
params['file_type'] = file_type;
}
params['return_file'] = true;
ae_promises.download__sponsorship_export_file = await api.get_object({
api_cfg: api_cfg,
endpoint: endpoint,
params: params,
return_blob: return_file,
filename: filename,
auto_download: auto_download,
log_lvl: log_lvl
return await api.get_object({
api_cfg,
endpoint,
params: query_params,
return_blob: true,
filename,
auto_download: true,
log_lvl
});
console.log(
'ae_promises.download__sponsorship_export_file:',
ae_promises.download__sponsorship_export_file
);
return ae_promises.download__sponsorship_export_file;
}
const export_obj = {
load_ae_obj_id__sponsorship_cfg: load_ae_obj_id__sponsorship_cfg,
load_ae_obj_id__sponsorship: load_ae_obj_id__sponsorship,
load_ae_obj_li__sponsorship: load_ae_obj_li__sponsorship,
download_export__sponsorship: download_export__sponsorship
};
export const spons_func = export_obj;
export const spons_func = {
load_ae_obj_id__sponsorship_cfg,
load_ae_obj_id__sponsorship,
load_ae_obj_li__sponsorship,
create_ae_obj__sponsorship,
update_ae_obj__sponsorship,
delete_ae_obj__sponsorship,
download_export__sponsorship
};