360 lines
13 KiB
TypeScript
360 lines
13 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-03
|
|
export async function handle_load_ae_obj_id__badge(
|
|
{
|
|
api_cfg,
|
|
badge_id,
|
|
try_cache=false,
|
|
log_lvl=0
|
|
}: {
|
|
api_cfg: any,
|
|
badge_id: string,
|
|
try_cache?: boolean,
|
|
log_lvl?: number
|
|
}
|
|
) {
|
|
console.log(`*** handle_load_ae_obj_id__badge() *** badge_id=${badge_id}`);
|
|
|
|
let params = {};
|
|
|
|
// $events_sess.badges.status_load__badge_obj = 'loading';
|
|
ae_promises.load__badge_obj = await api.get_ae_obj_id_crud({
|
|
api_cfg: api_cfg,
|
|
obj_type: 'event_badge',
|
|
obj_id: badge_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 (badge_obj_get_result) {
|
|
if (badge_obj_get_result) {
|
|
// This is expecting a list
|
|
handle_db_save_ae_obj_li__badge({obj_type: 'event_badge', obj_li: [badge_obj_get_result]});
|
|
return badge_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__badge_obj;
|
|
}
|
|
|
|
|
|
// Updated 2024-03-06
|
|
export async function handle_load_ae_obj_li__badge(
|
|
{
|
|
api_cfg,
|
|
event_id,
|
|
params={},
|
|
try_cache=true,
|
|
log_lvl=0
|
|
}: {
|
|
api_cfg: any,
|
|
event_id: any,
|
|
params: any,
|
|
try_cache?: boolean,
|
|
log_lvl: number
|
|
}) {
|
|
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: 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
|
|
|
|
// 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: log_lvl
|
|
})
|
|
|
|
.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;
|
|
});
|
|
|
|
if (log_lvl) {
|
|
console.log('ae_promises.load__event_badge_obj_li:', ae_promises.load__event_badge_obj_li);
|
|
}
|
|
return ae_promises.load__event_badge_obj_li;
|
|
}
|
|
|
|
|
|
export async function handle_search__event_badge(
|
|
{
|
|
api_cfg,
|
|
event_id,
|
|
type_code = null,
|
|
fulltext_search_qry_str,
|
|
like_search_qry_str = null,
|
|
external_event_id,
|
|
params = {},
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any,
|
|
event_id: any,
|
|
type_code: any,
|
|
fulltext_search_qry_str: any,
|
|
like_search_qry_str: any,
|
|
external_event_id: any,
|
|
params: any,
|
|
try_cache: boolean,
|
|
log_lvl: number
|
|
}
|
|
) {
|
|
console.log(`*** handle_search__event_badge() *** 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
|
|
let limit: number = (params.qry__limit ?? 25); // 99
|
|
let offset: number = (params.qry__offset ?? 0); // 0
|
|
|
|
let params_json: key_val = {};
|
|
|
|
if (!fulltext_search_qry_str && !like_search_qry_str) {
|
|
console.log('No search string provided!!!');
|
|
return false; // Returning false instead of [] because no search was performed.
|
|
}
|
|
|
|
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
|
|
};
|
|
}
|
|
|
|
if (like_search_qry_str && like_search_qry_str.length > 2) {
|
|
// Old Python version that needs to be in JS
|
|
// # Strip (left right) whitespace then commas then semicolons
|
|
// query_str = query_str.strip().strip(',').strip(';')
|
|
// # Replace commas, semicolons, and then spaces with %
|
|
// query_str_like = query_str.replace(',', ' ').replace(';', ' ').replace(' ', '%').replace(' ', '%')
|
|
// # data['query_str'] = f'%{query_str}%'
|
|
// log.debug(query_str_like)
|
|
// data['query_str'] = f'%{query_str_like}%'
|
|
|
|
// let like_search_qry_str_new = like_search_qry_str.trim().replace(',', ' ').replace(';', ' ').replace(' ', '%').replace(' ', '%');
|
|
// like_search_qry_str_new = `%${like_search_qry_str_new}%`;
|
|
// console.log('like_search_qry_str_new:', like_search_qry_str_new);
|
|
|
|
params_json['and_like'] = {
|
|
'default_qry_str': like_search_qry_str,
|
|
};
|
|
}
|
|
|
|
params_json['and_qry'] = {};
|
|
if (external_event_id) {
|
|
params_json['and_qry']['external_event_id'] = external_event_id;
|
|
}
|
|
|
|
if (type_code) { // This is the event_badge.badge_type_code. There is also a member_type_code and registration_type_code that could be referenced in the future.
|
|
params_json['and_qry']['badge_type_code'] = type_code;
|
|
}
|
|
|
|
let order_by_li = {'print_count': 'ASC', 'priority': 'DESC', 'sort': 'DESC', 'given_name': 'ASC', 'family_name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'};
|
|
|
|
// $events_sess.badges.status_qry__search = 'loading';
|
|
ae_promises.search__event_badge = 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: order_by_li,
|
|
// 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: log_lvl
|
|
})
|
|
.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;
|
|
});
|
|
|
|
if (log_lvl) {
|
|
console.log('ae_promises.search__event_badge:', ae_promises.search__event_badge);
|
|
}
|
|
return ae_promises.search__event_badge;
|
|
}
|
|
|
|
|
|
// This function will loop through the badge_obj_li and save each one to the DB.
|
|
export function handle_db_save_ae_obj_li__badge(
|
|
{
|
|
obj_type,
|
|
obj_li
|
|
}: {
|
|
obj_type: string,
|
|
obj_li: any
|
|
}
|
|
) {
|
|
console.log(`*** handle_db_save_ae_obj_li__badge() ***`);
|
|
|
|
if (obj_li && obj_li.length) {
|
|
obj_li.forEach(async function (obj: any) {
|
|
// console.log(`ae_obj ${obj_type}:`, obj);
|
|
|
|
try {
|
|
const id_random = await db_events.badges.put({
|
|
id_random: obj.event_badge_id_random,
|
|
event_badge_id_random: obj.event_badge_id_random,
|
|
|
|
event_id_random: obj.event_id_random,
|
|
|
|
pronouns: obj.pronouns,
|
|
informal_name: obj.informal_name,
|
|
title_names: obj.title_names,
|
|
given_name: obj.given_name,
|
|
middle_name: obj.middle_name,
|
|
family_name: obj.family_name,
|
|
designations: obj.designations,
|
|
|
|
professional_title: obj.professional_title,
|
|
professional_title_override: obj.professional_title_override,
|
|
|
|
full_name: obj.full_name,
|
|
full_name_override: obj.full_name_override,
|
|
|
|
affiliations: obj.affiliations,
|
|
affiliations_override: obj.affiliations_override,
|
|
|
|
email: obj.email,
|
|
email_override: obj.email_override,
|
|
|
|
address_line_1: obj.address_line_1,
|
|
address_line_2: obj.address_line_2,
|
|
address_line_3: obj.address_line_3,
|
|
city: obj.city,
|
|
country_subdivision_code: obj.country_subdivision_code,
|
|
state_province: obj.state_province,
|
|
state_province_abb: obj.state_province_abb,
|
|
postal_code: obj.postal_code,
|
|
country_alpha_2_code: obj.country_alpha_2_code,
|
|
country: obj.country,
|
|
full_address: obj.full_address,
|
|
location: obj.location,
|
|
location_override: obj.location_override,
|
|
|
|
query_str: obj.query_str,
|
|
|
|
badge_type: obj.badge_type,
|
|
badge_type_code: obj.badge_type_code,
|
|
badge_type_override: obj.badge_type_override,
|
|
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,
|
|
|
|
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,
|
|
});
|
|
// 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;
|
|
}
|
|
}
|