Finally working Events - Leads for exhibitors

This commit is contained in:
Scott Idem
2024-03-12 19:28:10 -04:00
parent 7d1a4b735b
commit fd4f2bdf35
14 changed files with 716 additions and 34 deletions

View File

@@ -0,0 +1,332 @@
import type { key_val } from '$lib/ae_stores';
import { api } from '$lib/api';
// import { liveQuery } from "dexie";
import { db_events } from "$lib/db_events";
// let event_badge_li = liveQuery(
// () => db_events.badges.toArray()
// );
let ae_promises: key_val = {}; // Promise<any>;
async function handle_load_ae_obj_id__event({api_cfg, event_id, try_cache=false}) {
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: 0
})
.then(function (event_obj_get_result) {
if (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-03-06
async function handle_load_ae_obj_li__badge({api_cfg, event_id, try_cache=true}) {
console.log(`*** handle_load_ae_obj_li__badge() *** event_id=${event_id}`);
let fulltext_search_qry_str = ''; // $events_sess.badges.fulltext_search_qry_str;
let enabled = 'enabled'; // $events_loc.qry_enabled;
let hidden = 'not_hidden'; // $events_loc.qry__hidden;
let limit = 25; // $events_loc.qry__limit;
let offset = 0; // $events_loc.qry__offset;
// if ($ae_loc.administrator_access) {
// enabled = 'all';
// hidden = 'all';
// limit = 500;
// } else if ($ae_loc.trusted_access) {
// // enabled = 'all';
// hidden = 'all';
// limit = 50;
// }
let params = {};
let params_json: key_val = {};
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
params_json['ft_qry'] = {
'default_qry_str': fulltext_search_qry_str,
// 'location_address_json_ext': fulltext_search_qry_str, // JSON extracted text DB field
// 'contact_li_json_ext': fulltext_search_qry_str, // JSON extracted text DB field
};
}
// console.log('params_json:', params_json);
// console.log(params_json);
// $events_sess.badges.status_qry__search = 'loading';
ae_promises.load__event_badge_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_badge',
for_obj_type: 'event',
for_obj_id: event_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.
enabled: enabled,
hidden: hidden,
order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'},
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'created_on': 'DESC', 'updated_on': 'DESC'},
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: 2
})
.then(function (badge_obj_li_get_result) {
// console.log('Badge list:', badge_obj_li_get_result);
if (badge_obj_li_get_result) {
// $slct.badge_obj_li = badge_obj_li_get_result;
handle_db_save_ae_obj_li__badge({obj_type: 'event_badge', obj_li: badge_obj_li_get_result});
return badge_obj_li_get_result;
} else {
// $slct.badge_obj_li = [];
return [];
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
// $events_sess.badges.status_qry__search = 'done';
// console.log('Badge list:', badge_obj_li_get_result);
// return badge_obj_li_get_result;
});
console.log('ae_promises.load__event_badge_obj_li:', ae_promises.load__event_badge_obj_li);
return ae_promises.load__event_badge_obj_li;
}
// Updated 2024-03-06
async function handle_load_ae_obj_li__exhibitor({api_cfg, event_id, try_cache=true}) {
console.log(`*** handle_load_ae_obj_li__exhibitor() *** event_id=${event_id}`);
let enabled = 'enabled'; // $events_loc.qry_enabled;
let hidden = 'not_hidden'; // $events_loc.qry__hidden;
let limit = 50; // $events_loc.qry__limit;
let offset = 0; // $events_loc.qry__offset;
// if ($ae_loc.administrator_access) {
// enabled = 'all';
// hidden = 'all';
// limit = 500;
// } else if ($ae_loc.trusted_access) {
// // enabled = 'all';
// hidden = 'all';
// limit = 50;
// }
let params = {};
let params_json: key_val = {};
// if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
// params_json['ft_qry'] = {
// 'default_qry_str': fulltext_search_qry_str,
// // 'location_address_json_ext': fulltext_search_qry_str, // JSON extracted text DB field
// // 'contact_li_json_ext': fulltext_search_qry_str, // JSON extracted text DB field
// };
// }
// console.log('params_json:', params_json);
// console.log(params_json);
// $events_sess.exhibits.status_qry__search = 'loading';
ae_promises.load__event_exhibit_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_exhibit',
for_obj_type: 'event',
for_obj_id: event_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.
enabled: enabled,
hidden: hidden,
order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'},
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'created_on': 'DESC', 'updated_on': 'DESC'},
limit: limit,
offset: offset,
// params_json: params_json,
params: params,
log_lvl: 2
})
.then(function (exhibit_obj_li_get_result) {
// console.log('Badge list:', exhibit_obj_li_get_result);
if (exhibit_obj_li_get_result) {
// $slct.exhibit_obj_li = exhibit_obj_li_get_result;
handle_db_save_ae_obj_li__exhibitor({obj_type: 'event_exhibit', obj_li: exhibit_obj_li_get_result});
return exhibit_obj_li_get_result;
} else {
// $slct.exhibit_obj_li = [];
return [];
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
// $events_sess.exhibits.status_qry__search = 'done';
// console.log('Badge list:', exhibit_obj_li_get_result);
// return exhibit_obj_li_get_result;
});
console.log('ae_promises.load__event_exhibit_obj_li:', ae_promises.load__event_exhibit_obj_li);
return ae_promises.load__event_exhibit_obj_li;
}
// // This function will loop through the badge_obj_li and save each one to the DB.
// function handle_db_save_ae_obj_li({obj_type, obj_li}) {
// console.log(`*** handle_db_save_ae_obj_li() ***`);
// if (obj_li && obj_li.length) {
// obj_li.forEach(async function (obj) {
// // console.log(`ae_obj ${obj_type}:`, obj);
// try {
// const id_random = await db_events.badges.put({
// id_random: obj.event_badge_id_random,
// full_name: obj.full_name,
// full_name_override: obj.full_name_override,
// email: obj.email,
// email_override: obj.email_override,
// affiliations: obj.affiliations,
// affiliations_override: obj.affiliations_override,
// badge_type: obj.badge_type,
// badge_type_override: obj.badge_type_override,
// badge_type_code: obj.badge_type_code,
// badge_type_code_override: obj.badge_type_code_override,
// external_event_id: obj.external_event_id,
// external_id: obj.external_id,
// external_person_id: obj.external_person_id,
// created_on: obj.created_on,
// updated_on: obj.updated_on,
// });
// console.log(`Put obj with ID: ${obj.event_badge_id_random} or ${id_random}`);
// } catch (error) {
// let status = `Failed to put ${obj.event_badge_id_random}: ${error}`;
// console.log(status);
// }
// // const id_random = await db_events.badges.put(obj);
// // console.log(`Put obj with ID: ${obj.event_badge_id_random}`);
// });
// return true;
// }
// }
// This function will loop through the badge_obj_li and save each one to the DB.
function handle_db_save_ae_obj_li__badge({obj_type, obj_li}) {
console.log(`*** handle_db_save_ae_obj_li__badge() ***`);
if (obj_li && obj_li.length) {
obj_li.forEach(async function (obj) {
// console.log(`ae_obj ${obj_type}:`, obj);
try {
const id_random = await db_events.badges.put({
id_random: obj.event_badge_id_random,
full_name: obj.full_name,
full_name_override: obj.full_name_override,
email: obj.email,
email_override: obj.email_override,
affiliations: obj.affiliations,
affiliations_override: obj.affiliations_override,
badge_type: obj.badge_type,
badge_type_override: obj.badge_type_override,
badge_type_code: obj.badge_type_code,
badge_type_code_override: obj.badge_type_code_override,
external_event_id: obj.external_event_id,
external_id: obj.external_id,
external_person_id: obj.external_person_id,
created_on: obj.created_on,
updated_on: obj.updated_on,
});
console.log(`Put obj with ID: ${obj.event_badge_id_random} or ${id_random}`);
} catch (error) {
let status = `Failed to put ${obj.event_badge_id_random}: ${error}`;
console.log(status);
}
// const id_random = await db_events.badges.put(obj);
// console.log(`Put obj with ID: ${obj.event_badge_id_random}`);
});
return true;
}
}
// This function will loop through the event_exhibit_obj_li and save each one to the DB.
function handle_db_save_ae_obj_li__exhibitor({obj_type, obj_li}) {
console.log(`*** handle_db_save_ae_obj_li__exhibitor() ***`);
if (obj_li && obj_li.length) {
obj_li.forEach(async function (obj) {
// console.log(`ae_obj ${obj_type}:`, obj);
try {
const id_random = await db_events.exhibits.put({
id_random: obj.event_exhibit_id_random,
code: obj.code,
name: obj.name,
description: obj.description,
staff_passcode: obj.staff_passcode,
data_json: obj.data_json,
license_max: obj.license_max,
license_li_json: obj.license_li_json,
cfg_json: obj.cfg_json,
created_on: obj.created_on,
updated_on: obj.updated_on,
});
console.log(`Put obj with ID: ${obj.event_exhibit_id_random} or ${id_random}`);
} catch (error) {
let status = `Failed to put ${obj.event_exhibit_id_random}: ${error}`;
console.log(status);
}
// const id_random = await db_events.exhibits.put(obj);
// console.log(`Put obj with ID: ${obj.event_exhibit_id_random}`);
});
return true;
}
}
let export_obj = {
handle_load_ae_obj_id__event: handle_load_ae_obj_id__event,
handle_load_ae_obj_li__badge: handle_load_ae_obj_li__badge,
handle_load_ae_obj_li__exhibitor: handle_load_ae_obj_li__exhibitor,
};
export let events_func = export_obj;

View File

@@ -8,7 +8,7 @@ import type { key_val } from '$lib/ae_stores';
// Longer-term app data. This should be stored to *local* storage.
// Updated 2024-03-06
let events_local_data_struct: key_val = {
'ver': '2024-03-06_17',
'ver': '2024-03-12_19',
// Shared
'name': 'Aether - Events (SvelteKit 2.x Svelte 4.x)',
'title': `OSIT's Æ Events`, // - Dev SvelteKit`, // &AElig;
@@ -40,6 +40,9 @@ let events_local_data_struct: key_val = {
},
// Lead Retrievals (Exhibit)
'leads': {
auto_view: true,
},
// Presentation Management (Distributing)

View File

@@ -59,7 +59,7 @@ export let temp_get_object_percent_completed = 0;
export let get_object_percent_completed = temp_get_object_percent_completed;
// Updated 2022-10-28
export let get_object = async function get_object({api_cfg=null, endpoint='', headers={}, params={}, data={}, timeout=600000, return_meta=false, return_blob=false, filename=null, auto_download=false, as_list=false, log_lvl=0}) {
export let get_object = async function get_object({api_cfg, endpoint='', headers={}, params={}, data={}, timeout=600000, return_meta=false, return_blob=false, filename=null, auto_download=false, as_list=false, log_lvl=0}) {
if (log_lvl) {
console.log('*** get_object() ***');
}
@@ -81,6 +81,11 @@ export let get_object = async function get_object({api_cfg=null, endpoint='', he
}
}
if (!api_cfg) {
console.log('No API Config was provided. Returning false.');
return false;
}
let axios_api = axios.create({
baseURL: api_cfg['base_url'],
timeout: timeout, // in milliseconds; 60000 = 60 seconds

View File

@@ -16,20 +16,39 @@ export interface Badge {
external_event_id: string;
external_id: string;
external_person_id: string;
created_on: Date;
updated_on: Date;
}
export interface Exhibit {
// id?: number;
id_random: string;
code: string;
name: string;
description: null|string;
staff_passcode: null
data_json: string;
license_max: number;
license_li_json: string;
cfg_json: string;
created_on: Date;
updated_on: Date;
}
export class MySubClassedDexie extends Dexie {
// 'badges' is added by dexie when declaring the stores()
// We just tell the typing system this is the case
badges!: Table<Badge>;
// 'badges' is added by dexie when declaring the stores()
// We just tell the typing system this is the case
badges!: Table<Badge>;
exhibits!: Table<Exhibit>;
constructor() {
super('ae_events_db');
this.version(1).stores({
// badges: '++id, full_name, email' // Primary key and indexed props
badges: 'id_random, full_name, full_name_override, email, email_override, affiliations, affiliations_override, badge_type, badge_type_code, badge_type_code_override, badge_type_override, external_event_id, external_id, external_person_id' // Primary key and indexed props
});
}
constructor() {
super('ae_events_db');
this.version(1).stores({
// badges: '++id, full_name, email' // Primary key and indexed props
badges: 'id_random, full_name, full_name_override, email, email_override, affiliations, affiliations_override, badge_type, badge_type_code, badge_type_code_override, badge_type_override, external_event_id, external_id, external_person_id, created_on, updated_on', // Primary key and indexed props
exhibits: 'id_random, code, name, description, staff_passcode, data_json, license_max, license_li_json, cfg_json, created_on, updated_on',
});
}
}
export const db_events = new MySubClassedDexie();