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-07-02 export async function handle_load_ae_obj_id__event( { api_cfg, event_id, try_cache = true, log_lvl = 0 }: { api_cfg: any, event_id: string, try_cache?: boolean, log_lvl?: number } ) { console.log(`*** handle_load_ae_obj_id__event() *** event_id=${event_id}`); let params = {}; // $events_sess.badges.status_load__event_obj = 'loading'; ae_promises.load__event_obj = await api.get_ae_obj_id_crud({ api_cfg: api_cfg, obj_type: 'event', obj_id: event_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 in the API config. params: params, log_lvl: log_lvl }) .then(function (event_obj_get_result) { if (event_obj_get_result) { if (try_cache) { // This is expecting a list handle_db_save_ae_obj_li__event({ obj_type: 'event', obj_li: [event_obj_get_result] }); } return event_obj_get_result; } else { console.log('No results returned.'); return null; } }) .catch(function (error) { console.log('No results returned or failed.', error); }); return ae_promises.load__event_obj; } // Updated 2024-05-24 export async function handle_load_ae_obj_li__event( { api_cfg, account_id, params={}, try_cache=true, log_lvl=0 }: { api_cfg: any, account_id: string, params?: key_val, try_cache?: boolean, log_lvl?: number } ) { console.log(`*** handle_load_ae_obj_li__event() *** account_id=${account_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.log('params_json:', params_json); ae_promises.load__event_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ api_cfg: api_cfg, obj_type: 'event', for_obj_type: 'account', for_obj_id: account_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 enabled: enabled, hidden: hidden, order_by_li: {'start_datetime': 'DESC', '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_obj_li_get_result) { if (event_obj_li_get_result) { if (try_cache) { handle_db_save_ae_obj_li__event({obj_type: 'event', obj_li: event_obj_li_get_result}); } return event_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_obj_li:', ae_promises.load__event_obj_li); } return ae_promises.load__event_obj_li; } // This function will loop through the event_obj_li and save each one to the DB. export function handle_db_save_ae_obj_li__event( { obj_type, obj_li, log_lvl = 0 }: { obj_type: string, obj_li: any, log_lvl?: number } ) { if (log_lvl) { console.log(`*** handle_db_save_ae_obj_li__event() ***`); } 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.events.put({ id: obj.event_id_random, // id_random: obj.event_id_random, event_id: obj.event_id_random, event_id_random: obj.event_id_random, code: obj.event_code, account_id: obj.account_id_random, account_id_random: obj.account_id_random, conference: obj.conference, type: obj.type, name: obj.name, summary: obj.summary, description: obj.description, start_datetime: obj.start_datetime, end_datetime: obj.end_datetime, timezone: obj.timezone, location_address_json: obj.location_address_json, mod_abstracts_json: obj.mod_abstracts_json, mod_badges_json: obj.mod_badges_json, mod_exhibits_json: obj.mod_exhibits_json, mod_pres_mgmt_json: obj.mod_pres_mgmt_json, cfg_json: obj.cfg_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, }); // console.log(`Put obj with ID: ${obj.event_id_random} or ${id_random}`); } catch (error) { let status = `Failed to put ${obj.event_id_random}: ${error}`; console.log(status); } // const id_random = await db_events.events.put(obj); // console.log(`Put obj with ID: ${obj.event_id_random}`); }); return true; } }