Saving work after rounds of updates to the event object type functions.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_save_ae_obj_li__ae_obj } from "$lib/ae_core/core__idb_dexie";
|
||||
import { db_events } from "$lib/ae_events/db_events";
|
||||
|
||||
import { load_ae_obj_li__event_device } from "$lib/ae_events/ae_events__event_device";
|
||||
@@ -10,7 +11,7 @@ import { load_ae_obj_li__event_session } from './ae_events__event_session';
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
|
||||
// Updated 2024-06-10
|
||||
// Updated 2025-05-23
|
||||
export async function load_ae_obj_id__event_location(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -43,14 +44,33 @@ export async function load_ae_obj_id__event_location(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_location_obj_get_result) {
|
||||
.then(async function (event_location_obj_get_result) {
|
||||
if (event_location_obj_get_result) {
|
||||
if (try_cache) {
|
||||
// This is expecting a list
|
||||
db_save_ae_obj_li__event_location({
|
||||
obj_type: 'event_location',
|
||||
obj_li: [event_location_obj_get_result]
|
||||
let processed_obj_li = await process_ae_obj__event_location_props({
|
||||
obj_li: [event_location_obj_get_result],
|
||||
log_lvl
|
||||
});
|
||||
// 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: 'locations',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save,
|
||||
log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__event_location({
|
||||
// obj_type: 'event_location',
|
||||
// obj_li: [event_location_obj_get_result]
|
||||
// });
|
||||
}
|
||||
return event_location_obj_get_result;
|
||||
} else {
|
||||
@@ -66,6 +86,11 @@ export async function load_ae_obj_id__event_location(
|
||||
console.log('ae_promises.load__event_location_obj:', ae_promises.load__event_location_obj);
|
||||
}
|
||||
|
||||
if (ae_promises?.load__event_location_obj === null) {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (inc_file_li) {
|
||||
// Load the files for the location
|
||||
if (log_lvl) {
|
||||
@@ -116,7 +141,7 @@ export async function load_ae_obj_id__event_location(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-09-24
|
||||
// Updated 2025-05-23
|
||||
export async function load_ae_obj_li__event_location(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -142,7 +167,9 @@ export async function load_ae_obj_li__event_location(
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
console.log(`*** load_ae_obj_li__event_location() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__event_location() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
|
||||
let hidden: string = (params.qry__hidden ?? 'all'); // all, hidden, not_hidden
|
||||
@@ -153,13 +180,14 @@ export async function load_ae_obj_li__event_location(
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
// ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
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_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
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
@@ -169,13 +197,36 @@ export async function load_ae_obj_li__event_location(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_location_obj_li_get_result) {
|
||||
.then(async function (event_location_obj_li_get_result) {
|
||||
if (event_location_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__event_location({
|
||||
obj_type: 'event_location',
|
||||
obj_li: event_location_obj_li_get_result
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__event_location_props({
|
||||
obj_li: event_location_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: 'locations',
|
||||
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_location({
|
||||
// obj_type: 'event_location',
|
||||
// obj_li: event_location_obj_li_get_result
|
||||
// });
|
||||
}
|
||||
return event_location_obj_li_get_result;
|
||||
} else {
|
||||
@@ -284,23 +335,27 @@ export async function load_ae_obj_li__event_location(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-25
|
||||
// Updated 2025-05-23
|
||||
export async function create_ae_obj__event_location(
|
||||
{
|
||||
api_cfg,
|
||||
event_id,
|
||||
data_kv,
|
||||
params={},
|
||||
log_lvl=0
|
||||
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
|
||||
}
|
||||
) {
|
||||
console.log(`*** create_ae_obj__event_location() *** event_id=${event_id}`);
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__event_location() *** event_id=${event_id}`);
|
||||
}
|
||||
|
||||
ae_promises.create__event_location = await api.create_ae_obj_crud({
|
||||
api_cfg: api_cfg,
|
||||
@@ -314,13 +369,38 @@ export async function create_ae_obj__event_location(
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_location_obj_create_result) {
|
||||
.then(async function (event_location_obj_create_result) {
|
||||
if (event_location_obj_create_result) {
|
||||
db_save_ae_obj_li__event_location(
|
||||
{
|
||||
obj_type: 'event_location',
|
||||
obj_li: [event_location_obj_create_result]
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
let 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: 'locations',
|
||||
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_location(
|
||||
// {
|
||||
// obj_type: 'event_location',
|
||||
// obj_li: [event_location_obj_create_result]
|
||||
// });
|
||||
}
|
||||
return event_location_obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
@@ -339,7 +419,7 @@ export async function create_ae_obj__event_location(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-11-08
|
||||
// Updated 2025-05-23
|
||||
export async function delete_ae_obj_id__event_location(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -370,14 +450,6 @@ export async function delete_ae_obj_id__event_location(
|
||||
method: method,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_location_obj_delete_result) {
|
||||
// if (event_location_obj_delete_result) {
|
||||
// // db_save_ae_obj_li__event_location({obj_type: 'event_location', obj_li: [event_location_obj_delete_result]});
|
||||
// return event_location_obj_delete_result;
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
@@ -398,7 +470,7 @@ export async function delete_ae_obj_id__event_location(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-09-25
|
||||
// Updated 2025-05-23
|
||||
export async function update_ae_obj__event_location(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -429,12 +501,35 @@ export async function update_ae_obj__event_location(
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (event_location_obj_update_result) {
|
||||
.then(async function (event_location_obj_update_result) {
|
||||
if (event_location_obj_update_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__event_location({
|
||||
obj_type: 'event_location', obj_li: [event_location_obj_update_result]
|
||||
// Process the results first
|
||||
let 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: 'locations',
|
||||
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_location({
|
||||
// obj_type: 'event_location', obj_li: [event_location_obj_update_result]
|
||||
// });
|
||||
}
|
||||
return event_location_obj_update_result;
|
||||
} else {
|
||||
@@ -454,6 +549,7 @@ export async function update_ae_obj__event_location(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-05-23
|
||||
export async function search__event_location(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -479,7 +575,9 @@ export async function search__event_location(
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
console.log(`*** search__event_location() *** event_id=${event_id}`);
|
||||
if (log_lvl) {
|
||||
console.log(`*** search__event_location() *** event_id=${event_id}`);
|
||||
}
|
||||
|
||||
let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
|
||||
let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
|
||||
@@ -537,13 +635,14 @@ export async function search__event_location(
|
||||
|
||||
let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'};
|
||||
|
||||
ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
// ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
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_table: true, // NOTE: We want to use the alt table for location searching
|
||||
use_alt_base: false,
|
||||
use_alt_tbl: true, // NOTE: We want to use the alt table for location searching
|
||||
// use_alt_mdl: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
@@ -660,3 +759,120 @@ export function db_save_ae_obj_li__event_location(
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-05-23
|
||||
export const properties_to_save = [
|
||||
'id',
|
||||
'event_location_id',
|
||||
'event_location_id_random',
|
||||
|
||||
'external_id',
|
||||
'code',
|
||||
|
||||
'type_code',
|
||||
|
||||
'event_id',
|
||||
'event_id_random',
|
||||
|
||||
'name',
|
||||
'description',
|
||||
|
||||
'passcode',
|
||||
|
||||
'hide_event_launcher',
|
||||
|
||||
'alert',
|
||||
'alert_msg',
|
||||
|
||||
'data_json',
|
||||
|
||||
'enable',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
|
||||
// From SQL view
|
||||
'file_count',
|
||||
'file_count_all',
|
||||
'internal_use_count',
|
||||
'event_file_id_li_json',
|
||||
|
||||
'event_name',
|
||||
];
|
||||
|
||||
|
||||
// Updated 2025-05-23
|
||||
export async function process_ae_obj__event_location_props({
|
||||
obj_li,
|
||||
log_lvl = 0,
|
||||
}: {
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** process_ae_obj__event_location_props() ***`, obj_li);
|
||||
}
|
||||
|
||||
if (!obj_li || obj_li.length === 0) {
|
||||
if (log_lvl) console.log('No objects to process.');
|
||||
return [];
|
||||
}
|
||||
|
||||
const processed_obj_li = [];
|
||||
|
||||
for (const obj of obj_li) {
|
||||
if (log_lvl) console.log(`Processing ae_obj event_location:`, obj);
|
||||
|
||||
let processed_obj = {
|
||||
id: obj.event_location_id_random,
|
||||
event_location_id: obj.event_location_id_random,
|
||||
event_location_id_random: obj.event_location_id_random,
|
||||
|
||||
external_id: obj.external_id,
|
||||
code: obj.code,
|
||||
|
||||
type_code: obj.type_code,
|
||||
|
||||
event_id: obj.event_id_random,
|
||||
event_id_random: obj.event_id_random,
|
||||
|
||||
name: obj.name,
|
||||
description: obj.description,
|
||||
|
||||
passcode: obj.passcode,
|
||||
|
||||
hide_event_launcher: obj.hide_event_launcher,
|
||||
|
||||
alert: obj.alert,
|
||||
alert_msg: obj.alert_msg,
|
||||
|
||||
data_json: obj.data_json,
|
||||
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
group: obj.group,
|
||||
notes: obj.notes,
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
|
||||
// From SQL view
|
||||
file_count: obj.file_count,
|
||||
file_count_all: obj.file_count_all,
|
||||
internal_use_count: obj.internal_use_count,
|
||||
event_file_id_li_json: obj.event_file_id_li_json,
|
||||
|
||||
event_name: obj.event_name,
|
||||
};
|
||||
|
||||
processed_obj_li.push(processed_obj);
|
||||
}
|
||||
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user