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:
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user