More code clean up.
This commit is contained in:
@@ -7,7 +7,7 @@ import { db_events } from "$lib/ae_events/db_events";
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
|
||||
// Updated 2024-06-14
|
||||
// Updated 2025-07-21
|
||||
export async function load_ae_obj_id__event_file(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -36,10 +36,35 @@ export async function load_ae_obj_id__event_file(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_file_obj_get_result) {
|
||||
.then(async function (event_file_obj_get_result) {
|
||||
if (event_file_obj_get_result) {
|
||||
// This is expecting a list
|
||||
db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: [event_file_obj_get_result]});
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
let 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: 'files',
|
||||
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.');
|
||||
@@ -54,7 +79,7 @@ export async function load_ae_obj_id__event_file(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-07-03
|
||||
// Updated 2025-07-21
|
||||
export async function load_ae_obj_li__event_file(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -97,13 +122,14 @@ export async function load_ae_obj_li__event_file(
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__event_file_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
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: for_obj_type,
|
||||
for_obj_id: for_obj_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
|
||||
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,
|
||||
@@ -113,10 +139,33 @@ export async function load_ae_obj_li__event_file(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_file_obj_li_get_result) {
|
||||
.then(async function (event_file_obj_li_get_result) {
|
||||
if (event_file_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result});
|
||||
// Process the results first
|
||||
let 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: 'files',
|
||||
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 {
|
||||
@@ -135,7 +184,8 @@ export async function load_ae_obj_li__event_file(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-14
|
||||
// Updated 2025-07-21
|
||||
// This may need to be reviewed again???
|
||||
export async function create_event_file_obj_from_hosted_file_async(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -158,7 +208,14 @@ export async function create_event_file_obj_from_hosted_file_async(
|
||||
}
|
||||
|
||||
) {
|
||||
console.log('*** ae_events_functions.js: create_event_file_obj_from_hosted_file() ***');
|
||||
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;
|
||||
}
|
||||
|
||||
let endpoint = `/event/file/from_hosted_file/${hosted_file_id}`;
|
||||
if (return_obj) {
|
||||
@@ -197,7 +254,7 @@ export async function create_event_file_obj_from_hosted_file_async(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-11-08
|
||||
// Updated 2025-07-21
|
||||
export async function delete_ae_obj_id__event_file(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -246,19 +303,21 @@ export async function delete_ae_obj_id__event_file(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-13
|
||||
// Updated 2025-07-21
|
||||
export async function update_ae_obj__event_file(
|
||||
{
|
||||
api_cfg,
|
||||
event_file_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
event_file_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
@@ -266,7 +325,8 @@ export async function update_ae_obj__event_file(
|
||||
console.log(`*** update_ae_obj__event_file() *** event_file_id=${event_file_id}`);
|
||||
}
|
||||
|
||||
ae_promises.update__event_file_obj = await api.update_ae_obj_id_crud({
|
||||
// Perform the API update
|
||||
const result = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'event_file',
|
||||
obj_id: event_file_id, // NOTE: This is the FQDN, not normally the ID.
|
||||
@@ -276,31 +336,48 @@ export async function update_ae_obj__event_file(
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_file_obj_update_result) {
|
||||
if (event_file_obj_update_result) {
|
||||
// db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: [event_file_obj_update_result]});
|
||||
// Very important: The results returned from the API does not include fields from the DB views. It is the actual table fields only.
|
||||
db_update_ae_obj_id__event_file({obj_type: 'event_file', obj_id: event_file_id, data_kv: event_file_obj_update_result});
|
||||
return event_file_obj_update_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
});
|
||||
// Handle the result
|
||||
if (result) {
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
let 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: 'files',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.update__event_file_obj:', ae_promises.update__event_file_obj);
|
||||
// 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;
|
||||
}
|
||||
return ae_promises.update__event_file_obj;
|
||||
}
|
||||
|
||||
|
||||
// This new function is using CRUD v2. This should allow for more flexibility in the queries.
|
||||
// Updated 2024-10-15
|
||||
// Updated 2025-07-21
|
||||
export async function qry__event_file(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -380,7 +457,34 @@ export async function qry__event_file(
|
||||
})
|
||||
.then(function (event_file_obj_li_get_result) {
|
||||
if (event_file_obj_li_get_result) {
|
||||
db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: 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: 'files',
|
||||
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 [];
|
||||
@@ -394,7 +498,7 @@ export async function qry__event_file(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-05-23
|
||||
// Updated 2025-07-21
|
||||
export async function search__event_file(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -504,10 +608,33 @@ export async function search__event_file(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_file_obj_li_get_result) {
|
||||
.then(async function (event_file_obj_li_get_result) {
|
||||
if (event_file_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result});
|
||||
// Process the results first
|
||||
let 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: 'files',
|
||||
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 {
|
||||
@@ -719,7 +846,7 @@ export function db_update_ae_obj_id__event_file(
|
||||
// Updated 2025-05-23
|
||||
export const properties_to_save = [
|
||||
'id',
|
||||
'id_random',
|
||||
// 'id_random',
|
||||
'event_file_id',
|
||||
'event_file_id_random',
|
||||
|
||||
@@ -732,15 +859,15 @@ export const properties_to_save = [
|
||||
'for_id_random',
|
||||
|
||||
'event_id',
|
||||
'event_id_random',
|
||||
// 'event_id_random',
|
||||
'event_session_id',
|
||||
'event_session_id_random',
|
||||
// 'event_session_id_random',
|
||||
'event_presentation_id',
|
||||
'event_presentation_id_random',
|
||||
// 'event_presentation_id_random',
|
||||
'event_presenter_id',
|
||||
'event_presenter_id_random',
|
||||
// 'event_presenter_id_random',
|
||||
'event_location_id',
|
||||
'event_location_id_random',
|
||||
// 'event_location_id_random',
|
||||
|
||||
'filename',
|
||||
'extension',
|
||||
@@ -815,7 +942,7 @@ export async function process_ae_obj__event_file_props({
|
||||
|
||||
let processed_obj = {
|
||||
id: obj.event_file_id_random,
|
||||
id_random: obj.event_file_id_random,
|
||||
// id_random: obj.event_file_id_random,
|
||||
event_file_id: obj.event_file_id_random,
|
||||
event_file_id_random: obj.event_file_id_random,
|
||||
|
||||
@@ -828,15 +955,15 @@ export async function process_ae_obj__event_file_props({
|
||||
for_id_random: obj.for_id_random,
|
||||
|
||||
event_id: obj.event_id_random,
|
||||
event_id_random: obj.event_id_random,
|
||||
// event_id_random: obj.event_id_random,
|
||||
event_session_id: obj.event_session_id_random,
|
||||
event_session_id_random: obj.event_session_id_random,
|
||||
// event_session_id_random: obj.event_session_id_random,
|
||||
event_presentation_id: obj.event_presentation_id_random,
|
||||
event_presentation_id_random: obj.event_presentation_id_random,
|
||||
// event_presentation_id_random: obj.event_presentation_id_random,
|
||||
event_presenter_id: obj.event_presenter_id_random,
|
||||
event_presenter_id_random: obj.event_presenter_id_random,
|
||||
// event_presenter_id_random: obj.event_presenter_id_random,
|
||||
event_location_id: obj.event_location_id_random,
|
||||
event_location_id_random: obj.event_location_id_random,
|
||||
// event_location_id_random: obj.event_location_id_random,
|
||||
|
||||
filename: obj.filename,
|
||||
extension: obj.extension,
|
||||
|
||||
Reference in New Issue
Block a user