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 = {};
|
const ae_promises: key_val = {};
|
||||||
|
|
||||||
// Updated 2025-10-06
|
// Updated 2026-01-02
|
||||||
export async function load_ae_obj_id__event_badge({
|
export async function load_ae_obj_id__event_badge({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
event_badge_id,
|
event_badge_id,
|
||||||
|
view = 'default',
|
||||||
inc_template = true,
|
inc_template = true,
|
||||||
try_cache = true,
|
try_cache = true,
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
event_badge_id: string;
|
event_badge_id: string;
|
||||||
|
view?: string;
|
||||||
inc_template?: boolean;
|
inc_template?: boolean;
|
||||||
try_cache?: boolean;
|
try_cache?: boolean;
|
||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
@@ -25,15 +27,13 @@ export async function load_ae_obj_id__event_badge({
|
|||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** load_ae_obj_id__event_badge() *** event_badge_id=${event_badge_id}`);
|
console.log(`*** load_ae_obj_id__event_badge() *** event_badge_id=${event_badge_id}`);
|
||||||
}
|
}
|
||||||
const params = {};
|
|
||||||
ae_promises.load__event_badge_obj = await api
|
ae_promises.load__event_badge_obj = await api
|
||||||
.get_ae_obj_id_crud({
|
.get_ae_obj_v3({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
obj_type: 'event_badge',
|
obj_type: 'event_badge',
|
||||||
obj_id: event_badge_id,
|
obj_id: event_badge_id,
|
||||||
use_alt_table: false,
|
view,
|
||||||
use_alt_base: false,
|
|
||||||
params,
|
|
||||||
log_lvl
|
log_lvl
|
||||||
})
|
})
|
||||||
.then(async function (badge_obj_get_result) {
|
.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;
|
return ae_promises.load__event_badge_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updated 2025-10-06
|
// Updated 2026-01-02
|
||||||
export async function load_ae_obj_li__event_badge({
|
export async function load_ae_obj_li__event_badge({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
event_id,
|
event_id,
|
||||||
inc_template = true, // This should probably be false.
|
inc_template = true, // This should probably be false.
|
||||||
enabled = 'enabled',
|
enabled = 'enabled',
|
||||||
hidden = 'not_hidden',
|
hidden = 'not_hidden',
|
||||||
|
view = 'default',
|
||||||
limit = 99,
|
limit = 99,
|
||||||
offset = 0,
|
offset = 0,
|
||||||
order_by_li = { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' },
|
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;
|
inc_template?: boolean;
|
||||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||||
|
view?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
order_by_li?: key_val;
|
order_by_li?: key_val;
|
||||||
@@ -116,23 +118,19 @@ export async function load_ae_obj_li__event_badge({
|
|||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** load_ae_obj_li__event_badge() *** event_id=${event_id}`);
|
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
|
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,
|
api_cfg: api_cfg,
|
||||||
obj_type: 'event_badge',
|
obj_type: 'event_badge',
|
||||||
for_obj_type: 'event',
|
for_obj_type: 'event',
|
||||||
for_obj_id: event_id,
|
for_obj_id: event_id,
|
||||||
// use_alt_tbl: false,
|
|
||||||
// use_alt_mdl: false,
|
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
hidden: hidden,
|
hidden: hidden,
|
||||||
|
view: view,
|
||||||
order_by_li: order_by_li,
|
order_by_li: order_by_li,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
params_json: params_json,
|
|
||||||
params: params,
|
|
||||||
log_lvl: log_lvl
|
log_lvl: log_lvl
|
||||||
})
|
})
|
||||||
.then(async function (badge_obj_li_get_result) {
|
.then(async function (badge_obj_li_get_result) {
|
||||||
@@ -345,13 +343,14 @@ export async function update_ae_obj__event_badge({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Is this needed?
|
// Is this needed?
|
||||||
// Updated 2025-10-06
|
// Updated 2026-01-02
|
||||||
export async function qry__event_badge({
|
export async function qry__event_badge({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
event_id,
|
event_id,
|
||||||
qry_str = null,
|
qry_str = null,
|
||||||
enabled = 'enabled',
|
enabled = 'enabled',
|
||||||
hidden = 'not_hidden',
|
hidden = 'not_hidden',
|
||||||
|
view = 'default',
|
||||||
limit = 99,
|
limit = 99,
|
||||||
offset = 0,
|
offset = 0,
|
||||||
order_by_li = { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' },
|
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;
|
qry_str?: null | string;
|
||||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||||
|
view?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
order_by_li?: key_val;
|
order_by_li?: key_val;
|
||||||
@@ -372,38 +372,66 @@ export async function qry__event_badge({
|
|||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
}) {
|
}) {
|
||||||
if (log_lvl) {
|
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) {
|
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,
|
ae_promises.qry__event_badge_obj_li = await api
|
||||||
event_id,
|
.search_ae_obj_v3({
|
||||||
enabled,
|
api_cfg,
|
||||||
hidden,
|
obj_type: 'event_badge',
|
||||||
limit,
|
search_query,
|
||||||
offset,
|
for_obj_type: 'event',
|
||||||
// order_by_li, params: { ...params, ...params_json },
|
for_obj_id: event_id,
|
||||||
try_cache,
|
enabled,
|
||||||
log_lvl
|
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;
|
return ae_promises.qry__event_badge_obj_li;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updated 2025-10-06
|
// Updated 2026-01-02
|
||||||
export async function search__event_badge({
|
export async function search__event_badge({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
event_id,
|
event_id,
|
||||||
type_code = null,
|
type_code = null,
|
||||||
printed_status = 'all', // 'all', 'printed', 'not_printed'
|
printed_status = 'all', // 'all', 'printed', 'not_printed'
|
||||||
affiliations_qry_str = null,
|
affiliations_qry_str = null,
|
||||||
fulltext_search_qry_str,
|
fulltext_search_qry_str = null,
|
||||||
like_search_qry_str = null,
|
like_search_qry_str = null,
|
||||||
external_event_id,
|
external_event_id = null,
|
||||||
enabled = 'enabled',
|
enabled = 'enabled',
|
||||||
hidden = 'not_hidden',
|
hidden = 'not_hidden',
|
||||||
|
view = 'default',
|
||||||
limit = 25,
|
limit = 25,
|
||||||
offset = 0,
|
offset = 0,
|
||||||
order_by_li = {
|
order_by_li = {
|
||||||
@@ -429,6 +457,7 @@ export async function search__event_badge({
|
|||||||
like_search_qry_str?: null | string;
|
like_search_qry_str?: null | string;
|
||||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||||
|
view?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
order_by_li?: key_val;
|
order_by_li?: key_val;
|
||||||
@@ -437,74 +466,74 @@ export async function search__event_badge({
|
|||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
}) {
|
}) {
|
||||||
if (log_lvl) {
|
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) {
|
if (!fulltext_search_qry_str && !like_search_qry_str && !affiliations_qry_str && !type_code && !external_event_id && printed_status === 'all') {
|
||||||
console.log('No search string provided!!!');
|
console.log('No search criteria provided!!!');
|
||||||
return false; // Returning false instead of [] because no search was performed.
|
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) {
|
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
|
||||||
params_json['ft_qry'] = { default_qry_str: fulltext_search_qry_str };
|
search_query.q = 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add specific filters
|
||||||
if (like_search_qry_str && like_search_qry_str.length > 2) {
|
if (like_search_qry_str && like_search_qry_str.length > 2) {
|
||||||
// Old Python version that needs to be in JS
|
and_filters.push({
|
||||||
// # Strip (left right) whitespace then commas then semicolons
|
field: 'default_qry_str',
|
||||||
// query_str = query_str.strip().strip(',').strip(';')
|
op: 'like',
|
||||||
// # Replace commas, semicolons, and then spaces with %
|
value: `%${like_search_qry_str.trim()}%`
|
||||||
// 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 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (affiliations_qry_str && affiliations_qry_str.length > 2) {
|
if (affiliations_qry_str && affiliations_qry_str.length > 2) {
|
||||||
if (!params_json['and_like']) {
|
and_filters.push({
|
||||||
params_json['and_like'] = {};
|
field: 'affiliations',
|
||||||
}
|
op: 'like',
|
||||||
params_json['and_like']['affiliations'] = affiliations_qry_str;
|
value: `%${affiliations_qry_str.trim()}%`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
params_json['and_qry'] = {};
|
|
||||||
if (external_event_id) {
|
if (external_event_id) {
|
||||||
params_json['and_qry']['external_event_id'] = external_event_id;
|
and_filters.push({ field: 'external_event_id', op: 'eq', value: 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.
|
if (type_code) {
|
||||||
params_json['and_qry']['badge_type_code'] = type_code;
|
and_filters.push({ field: 'badge_type_code', op: 'eq', value: type_code });
|
||||||
}
|
}
|
||||||
if (printed_status === 'printed') {
|
|
||||||
params_json['and_qry']['print_count_gte'] = 1;
|
if (printed_status === 'printed') {
|
||||||
} else if (printed_status === 'not_printed') {
|
and_filters.push({ field: 'print_count', op: 'gt', value: 0 });
|
||||||
params_json['and_qry']['print_count_eq'] = 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
|
ae_promises.search__event_badge_obj_li = await api
|
||||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
.search_ae_obj_v3({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
obj_type: 'event_badge',
|
obj_type: 'event_badge',
|
||||||
|
search_query,
|
||||||
for_obj_type: 'event',
|
for_obj_type: 'event',
|
||||||
for_obj_id: event_id,
|
for_obj_id: event_id,
|
||||||
use_alt_tbl: false,
|
|
||||||
use_alt_mdl: false,
|
|
||||||
enabled,
|
enabled,
|
||||||
hidden,
|
hidden,
|
||||||
// order_by_li,
|
view,
|
||||||
|
order_by_li,
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
params_json,
|
|
||||||
params,
|
|
||||||
log_lvl
|
log_lvl
|
||||||
})
|
})
|
||||||
.then(async function (badge_obj_li_get_result) {
|
.then(async function (badge_obj_li_get_result) {
|
||||||
@@ -603,6 +632,8 @@ export const properties_to_save = [
|
|||||||
'created_on',
|
'created_on',
|
||||||
'updated_on',
|
'updated_on',
|
||||||
|
|
||||||
|
'print_count',
|
||||||
|
|
||||||
// Generated fields for sorting locally only
|
// Generated fields for sorting locally only
|
||||||
'tmp_sort_1',
|
'tmp_sort_1',
|
||||||
'tmp_sort_2',
|
'tmp_sort_2',
|
||||||
@@ -656,7 +687,7 @@ async function _process_generic_props<T extends Record<string, any>>({
|
|||||||
for (const key in processed_obj) {
|
for (const key in processed_obj) {
|
||||||
if (key.endsWith('_random')) {
|
if (key.endsWith('_random')) {
|
||||||
const newKey = key.slice(0, -7); // Remove '_random' suffix
|
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'
|
// Ensure 'id' is set from '[obj_type]_id_random'
|
||||||
|
|||||||
Reference in New Issue
Block a user