Files
OSIT-AE-App-Svelte/src/lib/ae_events__event_presentation.ts

310 lines
10 KiB
TypeScript

import type { key_val } from '$lib/ae_stores';
import { api } from '$lib/api';
import { db_events } from "$lib/db_events";
let ae_promises: key_val = {};
// Updated 2024-06-20
export async function load_ae_obj_id__event_presentation(
{
api_cfg,
event_presentation_id,
inc_file_li = false,
inc_presenter_li = false,
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
event_presentation_id: string,
inc_file_li?: boolean,
inc_presenter_li?: boolean
try_cache?: boolean,
log_lvl?: number
}
) {
console.log(`*** load_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}`);
let params = {};
ae_promises.load__event_presentation_obj = await api.get_ae_obj_id_crud({
api_cfg: 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(function (event_presentation_obj_get_result) {
if (event_presentation_obj_get_result) {
if (try_cache) {
// 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) {
console.log('No results returned or failed.', error);
});
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.`);
}
}
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.`);
}
}
return ae_promises.load__event_presentation_obj;
}
// Updated 2024-06-10
export async function load_ae_obj_li__event_presentation(
{
api_cfg,
for_obj_type,
for_obj_id,
inc_file_li = false,
inc_presenter_li = false,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
for_obj_type: string,
for_obj_id: string,
inc_file_li?: boolean,
inc_presenter_li?: boolean
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
console.log(`*** load_ae_obj_li__event_presentation() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
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
let 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({
api_cfg: api_cfg,
obj_type: 'event_presentation',
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
enabled: enabled,
hidden: hidden,
order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(function (event_presentation_obj_li_get_result) {
if (event_presentation_obj_li_get_result) {
if (try_cache) {
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) {
console.log('No results returned or failed.', error);
});
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.`);
}
}
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.`);
}
}
return ae_promises.load__event_presentation_obj_li;
}
// Updated 2024-06-24
export async function create_ae_obj__event_presentation(
{
api_cfg,
event_id,
event_session_id,
data_kv,
params={},
log_lvl=0
}: {
api_cfg: any,
event_id: string,
event_session_id: string,
data_kv: key_val,
params?: key_val,
log_lvl?: number
}
) {
console.log(`*** create_ae_obj__event_presentation() *** event_id=${event_id} event_session_id=${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(function (event_presentation_obj_create_result) {
if (event_presentation_obj_create_result) {
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) {
console.log('No results returned or failed.', error);
})
.finally(function () {
});
if (log_lvl) {
console.log('ae_promises.create__event_presentation:', ae_promises.create__event_presentation);
}
return ae_promises.create__event_presentation;
}
// This function will loop through the event_presentation_obj_li and save each one to the DB.
// Updated 2024-06-10
export function db_save_ae_obj_li__event_presentation(
{
obj_type,
obj_li,
log_lvl=0
}: {
obj_type: string,
obj_li: any,
log_lvl?: number
}
) {
if (log_lvl) {
console.log(`*** db_save_ae_obj_li__event_presentation() ***`);
}
if (obj_li && obj_li.length) {
obj_li.forEach(async function (obj: any) {
if (log_lvl) {
console.log(`ae_obj ${obj_type}:`, obj);
}
try {
const id_random = await db_events.presentations.put({
id: obj.event_presentation_id_random,
// id_random: obj.event_presentation_id_random,
event_presentation_id: obj.event_presentation_id_random,
event_presentation_id_random: obj.event_presentation_id_random,
external_id: obj.external_id,
code: obj.code,
for_type: obj.for_type,
for_id: obj.for_id_random,
for_id_random: obj.for_id_random,
type_code: obj.type_code,
event_id: 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_abstract_id: obj.event_abstract_id_random,
event_abstract_id_random: obj.event_abstract_id_random,
abstract_code: obj.abstract_code,
name: obj.name,
description: obj.description,
start_datetime: obj.start_datetime,
end_datetime: obj.end_datetime,
passcode: obj.passcode,
hide_event_launcher: obj.hide_event_launcher,
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
event_session_code: obj.event_session_code,
event_session_name: obj.event_session_name,
// A key value list of the presenters
// event_presenter_kv: obj.event_presenter_kv,
});
// console.log(`Put obj with ID: ${obj.event_presentation_id_random} or ${id_random}`);
} catch (error) {
let status = `Failed to put ${obj.event_presentation_id_random}: ${error}`;
console.log(status);
}
// const id_random = await db_events.presentations.put(obj);
// console.log(`Put obj with ID: ${obj.event_presentation_id_random}`);
});
return true;
}
}