Work on switching to the new CRUD V3.
This commit is contained in:
@@ -8,16 +8,18 @@ import { load_ae_obj_id__event_badge_template } from '$lib/ae_events/ae_events__
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
// Updated 2025-10-06
|
||||
// Updated 2026-01-02
|
||||
export async function load_ae_obj_id__event_badge({
|
||||
api_cfg,
|
||||
event_badge_id,
|
||||
view = 'default',
|
||||
inc_template = true,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
event_badge_id: string;
|
||||
view?: string;
|
||||
inc_template?: boolean;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
@@ -25,15 +27,13 @@ export async function load_ae_obj_id__event_badge({
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__event_badge() *** event_badge_id=${event_badge_id}`);
|
||||
}
|
||||
const params = {};
|
||||
|
||||
ae_promises.load__event_badge_obj = await api
|
||||
.get_ae_obj_id_crud({
|
||||
.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge',
|
||||
obj_id: event_badge_id,
|
||||
use_alt_table: false,
|
||||
use_alt_base: false,
|
||||
params,
|
||||
view,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (badge_obj_get_result) {
|
||||
@@ -87,13 +87,14 @@ export async function load_ae_obj_id__event_badge({
|
||||
return ae_promises.load__event_badge_obj;
|
||||
}
|
||||
|
||||
// Updated 2025-10-06
|
||||
// Updated 2026-01-02
|
||||
export async function load_ae_obj_li__event_badge({
|
||||
api_cfg,
|
||||
event_id,
|
||||
inc_template = true, // This should probably be false.
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' },
|
||||
@@ -106,6 +107,7 @@ export async function load_ae_obj_li__event_badge({
|
||||
inc_template?: boolean;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: key_val;
|
||||
@@ -116,23 +118,19 @@ export async function load_ae_obj_li__event_badge({
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__event_badge() *** event_id=${event_id}`);
|
||||
}
|
||||
const params_json: key_val = {};
|
||||
// ae_promises.load__event_badge_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
|
||||
ae_promises.load__event_badge_obj_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
.get_ae_obj_li_v3({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'event_badge',
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
// use_alt_tbl: false,
|
||||
// use_alt_mdl: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
view: view,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (badge_obj_li_get_result) {
|
||||
@@ -345,13 +343,14 @@ export async function update_ae_obj__event_badge({
|
||||
}
|
||||
|
||||
// Is this needed?
|
||||
// Updated 2025-10-06
|
||||
// Updated 2026-01-02
|
||||
export async function qry__event_badge({
|
||||
api_cfg,
|
||||
event_id,
|
||||
qry_str = null,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' },
|
||||
@@ -364,6 +363,7 @@ export async function qry__event_badge({
|
||||
qry_str?: null | string;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: key_val;
|
||||
@@ -372,38 +372,66 @@ export async function qry__event_badge({
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** qry__event_badge() *** event_id=${event_id}`);
|
||||
console.log(`*** qry__event_badge() *** event_id=${event_id} qry_str=${qry_str}`);
|
||||
}
|
||||
const params_json: key_val = {};
|
||||
|
||||
const search_query: any = { and: [] };
|
||||
if (qry_str) {
|
||||
params_json['ft_qry'] = { default_qry_str: qry_str };
|
||||
search_query.q = qry_str;
|
||||
}
|
||||
ae_promises.qry__event_badge_obj_li = await load_ae_obj_li__event_badge({
|
||||
api_cfg,
|
||||
event_id,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
// order_by_li, params: { ...params, ...params_json },
|
||||
try_cache,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
ae_promises.qry__event_badge_obj_li = await api
|
||||
.search_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge',
|
||||
search_query,
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
enabled,
|
||||
hidden,
|
||||
view,
|
||||
order_by_li,
|
||||
limit,
|
||||
offset,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (badge_obj_li_get_result) {
|
||||
if (badge_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__event_badge_props({
|
||||
obj_li: badge_obj_li_get_result,
|
||||
event_id,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'badge',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return badge_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
return ae_promises.qry__event_badge_obj_li;
|
||||
}
|
||||
|
||||
// Updated 2025-10-06
|
||||
// Updated 2026-01-02
|
||||
export async function search__event_badge({
|
||||
api_cfg,
|
||||
event_id,
|
||||
type_code = null,
|
||||
printed_status = 'all', // 'all', 'printed', 'not_printed'
|
||||
affiliations_qry_str = null,
|
||||
fulltext_search_qry_str,
|
||||
fulltext_search_qry_str = null,
|
||||
like_search_qry_str = null,
|
||||
external_event_id,
|
||||
external_event_id = null,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
limit = 25,
|
||||
offset = 0,
|
||||
order_by_li = {
|
||||
@@ -429,6 +457,7 @@ export async function search__event_badge({
|
||||
like_search_qry_str?: null | string;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: key_val;
|
||||
@@ -437,74 +466,74 @@ export async function search__event_badge({
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** search__event_badge() *** event_id=${event_id}`);
|
||||
console.log(`*** search__event_badge() *** event_id=${event_id} printed_status=${printed_status} affiliations=${affiliations_qry_str}`);
|
||||
}
|
||||
|
||||
if (!fulltext_search_qry_str && !like_search_qry_str && !affiliations_qry_str) {
|
||||
console.log('No search string provided!!!');
|
||||
return false; // Returning false instead of [] because no search was performed.
|
||||
if (!fulltext_search_qry_str && !like_search_qry_str && !affiliations_qry_str && !type_code && !external_event_id && printed_status === 'all') {
|
||||
console.log('No search criteria provided!!!');
|
||||
return false;
|
||||
}
|
||||
|
||||
const params_json: key_val = {};
|
||||
const search_query: any = {};
|
||||
const and_filters: any[] = [];
|
||||
|
||||
// Set Global Search
|
||||
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
|
||||
search_query.q = fulltext_search_qry_str;
|
||||
}
|
||||
|
||||
// Add specific filters
|
||||
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 };
|
||||
and_filters.push({
|
||||
field: 'default_qry_str',
|
||||
op: 'like',
|
||||
value: `%${like_search_qry_str.trim()}%`
|
||||
});
|
||||
}
|
||||
|
||||
if (affiliations_qry_str && affiliations_qry_str.length > 2) {
|
||||
if (!params_json['and_like']) {
|
||||
params_json['and_like'] = {};
|
||||
}
|
||||
params_json['and_like']['affiliations'] = affiliations_qry_str;
|
||||
and_filters.push({
|
||||
field: 'affiliations',
|
||||
op: 'like',
|
||||
value: `%${affiliations_qry_str.trim()}%`
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (printed_status === 'printed') {
|
||||
params_json['and_qry']['print_count_gte'] = 1;
|
||||
} else if (printed_status === 'not_printed') {
|
||||
params_json['and_qry']['print_count_eq'] = 0;
|
||||
and_filters.push({ field: 'external_event_id', op: 'eq', value: external_event_id });
|
||||
}
|
||||
|
||||
if (type_code) {
|
||||
and_filters.push({ field: 'badge_type_code', op: 'eq', value: type_code });
|
||||
}
|
||||
|
||||
if (printed_status === 'printed') {
|
||||
and_filters.push({ field: 'print_count', op: 'gt', value: 0 });
|
||||
} else if (printed_status === 'not_printed') {
|
||||
and_filters.push({ field: 'print_count', op: 'eq', value: 0 });
|
||||
}
|
||||
|
||||
if (and_filters.length > 0) {
|
||||
search_query.and = and_filters;
|
||||
}
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('Final search_query object:', JSON.stringify(search_query, null, 2));
|
||||
}
|
||||
|
||||
// ae_promises.search__event_badge_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
ae_promises.search__event_badge_obj_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
.search_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge',
|
||||
search_query,
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
enabled,
|
||||
hidden,
|
||||
// order_by_li,
|
||||
view,
|
||||
order_by_li,
|
||||
limit,
|
||||
offset,
|
||||
params_json,
|
||||
params,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (badge_obj_li_get_result) {
|
||||
@@ -603,6 +632,8 @@ export const properties_to_save = [
|
||||
'created_on',
|
||||
'updated_on',
|
||||
|
||||
'print_count',
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2',
|
||||
@@ -656,7 +687,7 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7); // Remove '_random' suffix
|
||||
processed_obj[newKey] = processed_obj[key];
|
||||
(processed_obj as any)[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
// Ensure 'id' is set from '[obj_type]_id_random'
|
||||
|
||||
Reference in New Issue
Block a user