927 lines
29 KiB
TypeScript
927 lines
29 KiB
TypeScript
import type { key_val } from '$lib/stores/ae_stores';
|
|
import { api } from '$lib/api/api';
|
|
import { get_ae_obj_li_for_obj_id_crud_v2 } from '$lib/ae_api/api_get__crud_obj_li_v2';
|
|
|
|
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
|
|
import { db_events } from '$lib/ae_events/db_events';
|
|
import type { ae_Event } from '$lib/types/ae_types';
|
|
|
|
import { load_ae_obj_li__event_device } from './ae_events__event_device';
|
|
import { load_ae_obj_li__event_location } from './ae_events__event_location';
|
|
import { load_ae_obj_li__event_session } from './ae_events__event_session';
|
|
import { load_ae_obj_li__event_badge_template } from '$lib/ae_events/ae_events__event_badge_template';
|
|
|
|
const ae_promises: key_val = {};
|
|
|
|
// Updated 2026-01-16
|
|
export async function load_ae_obj_id__event({
|
|
api_cfg,
|
|
event_id,
|
|
view = 'default',
|
|
inc_device_li = false,
|
|
inc_location_li = false,
|
|
inc_session_li = false,
|
|
inc_template_li = false,
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
event_id: string;
|
|
view?: string;
|
|
inc_device_li?: boolean;
|
|
inc_location_li?: boolean;
|
|
inc_session_li?: boolean;
|
|
inc_template_li?: boolean;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}): Promise<ae_Event | null> {
|
|
if (log_lvl) {
|
|
console.log(`*** load_ae_obj_id__event() *** event_id=${event_id}`);
|
|
}
|
|
|
|
// Check if offline
|
|
if (typeof navigator !== 'undefined' && !navigator.onLine) {
|
|
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.');
|
|
ae_promises.load__event_obj = await db_events.event.get(event_id);
|
|
if (ae_promises.load__event_obj) {
|
|
return await _handle_nested_loads(ae_promises.load__event_obj, { api_cfg, inc_device_li, inc_location_li, inc_session_li, inc_template_li, log_lvl });
|
|
}
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
const event_obj_get_result = await api.get_ae_obj_v3({
|
|
api_cfg: api_cfg,
|
|
obj_type: 'event',
|
|
obj_id: event_id,
|
|
view,
|
|
log_lvl: log_lvl
|
|
});
|
|
|
|
if (event_obj_get_result) {
|
|
if (try_cache) {
|
|
const processed_obj_li = await process_ae_obj__event_props({
|
|
obj_li: [event_obj_get_result],
|
|
log_lvl: log_lvl
|
|
});
|
|
await db_save_ae_obj_li__ae_obj({
|
|
db_instance: db_events,
|
|
table_name: 'event',
|
|
obj_li: processed_obj_li,
|
|
properties_to_save: properties_to_save,
|
|
log_lvl: log_lvl
|
|
});
|
|
}
|
|
ae_promises.load__event_obj = event_obj_get_result;
|
|
} else {
|
|
console.log('No results returned from API.');
|
|
if (try_cache) {
|
|
if (log_lvl) console.log('Attempting to load from local cache...');
|
|
ae_promises.load__event_obj = await db_events.event.get(event_id);
|
|
} else {
|
|
ae_promises.load__event_obj = null;
|
|
}
|
|
}
|
|
} catch (error: any) {
|
|
console.log('API request failed.', error);
|
|
if (try_cache) {
|
|
if (log_lvl) console.log('Attempting to load from local cache after error...');
|
|
ae_promises.load__event_obj = await db_events.event.get(event_id);
|
|
} else {
|
|
ae_promises.load__event_obj = null;
|
|
}
|
|
}
|
|
|
|
if (!ae_promises?.load__event_obj) {
|
|
return null;
|
|
}
|
|
|
|
return await _handle_nested_loads(ae_promises.load__event_obj, { api_cfg, inc_device_li, inc_location_li, inc_session_li, inc_template_li, log_lvl });
|
|
}
|
|
|
|
/**
|
|
* Shared logic for loading nested child collections
|
|
*/
|
|
async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, inc_location_li, inc_session_li, inc_template_li, log_lvl }: any) {
|
|
const current_event_id = event_obj.event_id || event_obj.id;
|
|
|
|
if (inc_device_li) {
|
|
event_obj.event_device_obj_li = await load_ae_obj_li__event_device({
|
|
api_cfg,
|
|
for_obj_type: 'event',
|
|
for_obj_id: current_event_id,
|
|
log_lvl
|
|
});
|
|
}
|
|
if (inc_location_li) {
|
|
event_obj.event_location_obj_li = await load_ae_obj_li__event_location({
|
|
api_cfg,
|
|
for_obj_type: 'event',
|
|
for_obj_id: current_event_id,
|
|
log_lvl
|
|
});
|
|
}
|
|
if (inc_session_li) {
|
|
event_obj.event_session_obj_li = await load_ae_obj_li__event_session({
|
|
api_cfg,
|
|
for_obj_type: 'event',
|
|
for_obj_id: current_event_id,
|
|
log_lvl
|
|
});
|
|
}
|
|
if (inc_template_li) {
|
|
event_obj.event_badge_template_obj_li =
|
|
await load_ae_obj_li__event_badge_template({
|
|
api_cfg,
|
|
event_id: current_event_id,
|
|
log_lvl
|
|
});
|
|
}
|
|
return event_obj;
|
|
}
|
|
|
|
// Updated 2026-01-06
|
|
export async function load_ae_obj_li__event({
|
|
api_cfg,
|
|
for_obj_type = 'account',
|
|
for_obj_id,
|
|
qry_conference = null,
|
|
enabled = 'enabled',
|
|
hidden = 'not_hidden',
|
|
view = 'default',
|
|
inc_session_li = false,
|
|
limit = 99,
|
|
offset = 0,
|
|
order_by_li = { start_datetime: 'DESC' } as const,
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
for_obj_type?: string;
|
|
for_obj_id: string;
|
|
qry_conference?: boolean | null;
|
|
enabled?: 'enabled' | 'all' | 'not_enabled';
|
|
hidden?: 'hidden' | 'all' | 'not_hidden';
|
|
view?: string;
|
|
inc_session_li?: boolean;
|
|
limit?: number;
|
|
offset?: number;
|
|
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
|
|
params?: key_val;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}): Promise<ae_Event[]> {
|
|
|
|
// Check if offline
|
|
if (typeof navigator !== 'undefined' && !navigator.onLine) {
|
|
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.');
|
|
ae_promises.load__event_obj_li = await db_events.event
|
|
.where('account_id').equals(for_obj_id)
|
|
.toArray();
|
|
return ae_promises.load__event_obj_li || [];
|
|
}
|
|
|
|
let promise;
|
|
|
|
if (qry_conference !== null) {
|
|
// V3 Search now permits 'conference' field.
|
|
const search_query: any = {
|
|
and: [{ field: 'conference', op: 'eq', value: qry_conference }]
|
|
};
|
|
|
|
// Fix for "Integer Trap": Inject account context directly into search body and remove from URL params
|
|
if (for_obj_id) {
|
|
search_query.and.push({ field: 'account_id_random', op: 'eq', value: for_obj_id });
|
|
}
|
|
|
|
promise = api.search_ae_obj_v3({
|
|
api_cfg,
|
|
obj_type: 'event',
|
|
// Headers for Auth context
|
|
headers: { 'x-account-id': for_obj_id },
|
|
search_query,
|
|
enabled,
|
|
hidden,
|
|
view,
|
|
limit,
|
|
offset,
|
|
order_by_li,
|
|
log_lvl
|
|
});
|
|
} else {
|
|
promise = api.get_ae_obj_li_v3({
|
|
api_cfg,
|
|
obj_type: 'event',
|
|
for_obj_type,
|
|
for_obj_id,
|
|
enabled,
|
|
hidden,
|
|
view,
|
|
limit,
|
|
offset,
|
|
order_by_li,
|
|
log_lvl
|
|
});
|
|
}
|
|
|
|
try {
|
|
const event_obj_li_get_result = await promise;
|
|
if (event_obj_li_get_result) {
|
|
let filtered_results = event_obj_li_get_result;
|
|
|
|
// Optional: Keep local filter as a fallback safety
|
|
if (qry_conference !== null) {
|
|
filtered_results = event_obj_li_get_result.filter((ev: any) => ev.conference === qry_conference);
|
|
}
|
|
|
|
if (try_cache) {
|
|
const processed_obj_li = await process_ae_obj__event_props({
|
|
obj_li: filtered_results,
|
|
log_lvl: log_lvl
|
|
});
|
|
await db_save_ae_obj_li__ae_obj({
|
|
db_instance: db_events,
|
|
table_name: 'event',
|
|
obj_li: processed_obj_li,
|
|
properties_to_save: properties_to_save,
|
|
log_lvl: log_lvl
|
|
});
|
|
}
|
|
ae_promises.load__event_obj_li = filtered_results;
|
|
} else {
|
|
console.log('No results returned from API.');
|
|
if (try_cache) {
|
|
if (log_lvl) console.log('Attempting to load from local cache...');
|
|
ae_promises.load__event_obj_li = await db_events.event
|
|
.where('account_id').equals(for_obj_id)
|
|
.toArray();
|
|
} else {
|
|
ae_promises.load__event_obj_li = [];
|
|
}
|
|
}
|
|
} catch (error: any) {
|
|
console.log('API request failed.', error);
|
|
if (try_cache) {
|
|
if (log_lvl) console.log('Attempting to load from local cache after error...');
|
|
ae_promises.load__event_obj_li = await db_events.event
|
|
.where('account_id').equals(for_obj_id)
|
|
.toArray();
|
|
} else {
|
|
ae_promises.load__event_obj_li = [];
|
|
}
|
|
}
|
|
|
|
if (inc_session_li && ae_promises.load__event_obj_li) {
|
|
for (const event_obj of ae_promises.load__event_obj_li) {
|
|
const current_event_id = event_obj.event_id || event_obj.id;
|
|
event_obj.event_session_obj_li = await load_ae_obj_li__event_session({
|
|
api_cfg,
|
|
for_obj_type: 'event',
|
|
for_obj_id: current_event_id,
|
|
log_lvl
|
|
});
|
|
}
|
|
}
|
|
|
|
return ae_promises.load__event_obj_li;
|
|
}
|
|
|
|
// Updated 2026-01-06
|
|
export async function create_ae_obj__event({
|
|
api_cfg,
|
|
account_id,
|
|
data_kv,
|
|
params = {},
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
account_id: string;
|
|
data_kv: key_val;
|
|
params?: key_val;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}): Promise<ae_Event | null> {
|
|
const result = await api.create_ae_obj_v3({
|
|
api_cfg,
|
|
obj_type: 'event',
|
|
fields: {
|
|
account_id_random: account_id,
|
|
...data_kv
|
|
},
|
|
params,
|
|
log_lvl
|
|
});
|
|
|
|
if (result && try_cache) {
|
|
const processed_obj_li = await process_ae_obj__event_props({
|
|
obj_li: [result],
|
|
log_lvl: log_lvl
|
|
});
|
|
await db_save_ae_obj_li__ae_obj({
|
|
db_instance: db_events,
|
|
table_name: 'event',
|
|
obj_li: processed_obj_li,
|
|
properties_to_save: properties_to_save,
|
|
log_lvl: log_lvl
|
|
});
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// Updated 2026-01-06
|
|
export async function delete_ae_obj_id__event({
|
|
api_cfg,
|
|
event_id,
|
|
method = 'delete',
|
|
params = {},
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
event_id: string;
|
|
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
|
|
params?: key_val;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}) {
|
|
const result = await api.delete_ae_obj_v3({
|
|
api_cfg,
|
|
obj_type: 'event',
|
|
obj_id: event_id,
|
|
method,
|
|
params,
|
|
log_lvl
|
|
});
|
|
|
|
if (try_cache) {
|
|
await db_events.event.delete(event_id);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// Updated 2026-01-06
|
|
export async function update_ae_obj__event({
|
|
api_cfg,
|
|
event_id,
|
|
data_kv,
|
|
params = {},
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
event_id: string;
|
|
data_kv: key_val;
|
|
params?: key_val;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}): Promise<ae_Event | null> {
|
|
const result = await api.update_ae_obj_v3({
|
|
api_cfg,
|
|
obj_type: 'event',
|
|
obj_id: event_id,
|
|
fields: data_kv,
|
|
params,
|
|
log_lvl
|
|
});
|
|
|
|
if (result && try_cache) {
|
|
const processed_obj_li = await process_ae_obj__event_props({
|
|
obj_li: [result],
|
|
log_lvl: log_lvl
|
|
});
|
|
await db_save_ae_obj_li__ae_obj({
|
|
db_instance: db_events,
|
|
table_name: 'event',
|
|
obj_li: processed_obj_li,
|
|
properties_to_save: properties_to_save,
|
|
log_lvl: log_lvl
|
|
});
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// Updated 2026-01-20
|
|
export async function qry_ae_obj_li__event({
|
|
api_cfg,
|
|
for_obj_type = 'account',
|
|
for_obj_id,
|
|
qry_str,
|
|
qry_person_id = null,
|
|
qry_conference = null,
|
|
qry_physical = null,
|
|
qry_virtual = null,
|
|
qry_type = null,
|
|
enabled = 'enabled',
|
|
hidden = 'not_hidden',
|
|
view = 'default',
|
|
limit = 99,
|
|
offset = 0,
|
|
order_by_li = { start_datetime: 'DESC' } as const,
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
for_obj_type?: string;
|
|
for_obj_id: string;
|
|
qry_str?: string;
|
|
qry_person_id?: string | null;
|
|
qry_conference?: boolean | null;
|
|
qry_physical?: boolean | null;
|
|
qry_virtual?: boolean | null;
|
|
qry_type?: string | null;
|
|
enabled?: 'enabled' | 'all' | 'not_enabled';
|
|
hidden?: 'hidden' | 'all' | 'not_hidden';
|
|
view?: string;
|
|
limit?: number;
|
|
offset?: number;
|
|
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}) {
|
|
const search_query: any = { and: [] };
|
|
|
|
if (qry_str) {
|
|
// Use reserved 'q' property for global full-text search as per V3 Guide
|
|
search_query.q = qry_str;
|
|
}
|
|
|
|
<<<<<<< HEAD
|
|
// Use raw field name to bypass backend mapping conflicts (Integer Trap)
|
|
if (for_obj_id) {
|
|
search_query.and.push({ field: 'account_id_random', op: 'eq', value: for_obj_id });
|
|
}
|
|
=======
|
|
// Use raw field name to bypass backend mapping conflicts
|
|
// if (for_obj_id) {
|
|
// search_query.and.push({ field: 'account_id_random', op: 'eq', value: for_obj_id });
|
|
// }
|
|
>>>>>>> 63c633f5 (Fix(Events): Revert to URL-based account context for V3 Search)
|
|
|
|
const result_li = await api.search_ae_obj_v3({
|
|
api_cfg,
|
|
obj_type: 'event',
|
|
<<<<<<< HEAD
|
|
// Inject header context for Auth but keep body context for Filtering
|
|
headers: { 'x-account-id': for_obj_id },
|
|
=======
|
|
for_obj_type,
|
|
for_obj_id,
|
|
// Pass account context via search query body instead of query params to avoid duplicate mapping
|
|
>>>>>>> 63c633f5 (Fix(Events): Revert to URL-based account context for V3 Search)
|
|
search_query,
|
|
enabled,
|
|
hidden,
|
|
view,
|
|
limit: (qry_person_id || qry_conference !== null || qry_physical !== null || qry_virtual !== null || qry_type !== null) ? 500 : limit,
|
|
offset,
|
|
order_by_li,
|
|
log_lvl
|
|
});
|
|
|
|
if (!result_li) return [];
|
|
|
|
<<<<<<< HEAD
|
|
const processed_obj_li = await process_ae_obj__event_props({
|
|
obj_li: result_li,
|
|
log_lvl: log_lvl
|
|
});
|
|
=======
|
|
if (try_cache) {
|
|
const processed_obj_li = await process_ae_obj__event_props({
|
|
obj_li: result_li,
|
|
log_lvl: log_lvl
|
|
});
|
|
await db_save_ae_obj_li__ae_obj({
|
|
db_instance: db_events,
|
|
table_name: 'event',
|
|
obj_li: processed_obj_li,
|
|
properties_to_save: properties_to_save,
|
|
log_lvl: log_lvl
|
|
});
|
|
}
|
|
|
|
// Client-side Filter Layer
|
|
return result_li.filter((ev: any) => {
|
|
// 1. Conference filter - normalize 0/1 to boolean
|
|
if (qry_conference !== null && !!ev.conference !== !!qry_conference) return false;
|
|
|
|
// 2. Physical filter
|
|
if (qry_physical !== null && !!ev.physical !== !!qry_physical) return false;
|
|
|
|
// 3. Virtual filter
|
|
if (qry_virtual !== null && !!ev.virtual !== !!qry_virtual) return false;
|
|
|
|
// 4. Type filter (string)
|
|
if (qry_type !== null && ev.type !== qry_type) return false;
|
|
>>>>>>> ef26a01b (Fix(IDAA): Revert account_id body injection for Events V3 search)
|
|
|
|
if (try_cache) {
|
|
await db_save_ae_obj_li__ae_obj({
|
|
db_instance: db_events,
|
|
table_name: 'event',
|
|
obj_li: processed_obj_li,
|
|
properties_to_save: properties_to_save,
|
|
log_lvl: log_lvl
|
|
});
|
|
}
|
|
|
|
// Client-side Filter Layer
|
|
const filtered_obj_li = processed_obj_li.filter((ev: any) => {
|
|
// Handle conference filter
|
|
if (qry_conference != null) {
|
|
const ev_conf = ev.conference === true || ev.conference === 1 || ev.conference === '1';
|
|
if (ev_conf !== !!qry_conference) return false;
|
|
}
|
|
|
|
// Location Filtering (Inclusive OR logic)
|
|
// If either filter is explicitly true, we restrict results.
|
|
// If both are false or null, we show everything.
|
|
if (qry_physical === true || qry_virtual === true) {
|
|
const ev_physical = ev.physical === true || ev.physical === 1 || ev.physical === '1';
|
|
const ev_virtual = ev.virtual === true || ev.virtual === 1 || ev.virtual === '1';
|
|
|
|
let match = false;
|
|
if (qry_physical === true && ev_physical) match = true;
|
|
if (qry_virtual === true && ev_virtual) match = true;
|
|
|
|
if (!match) return false;
|
|
}
|
|
|
|
// Handle type filter (skip if null, undefined, 'all', or empty string)
|
|
if (qry_type != null && qry_type !== 'all' && qry_type !== '') {
|
|
if (ev.type !== qry_type) return false;
|
|
}
|
|
|
|
// Handle person ID filter
|
|
if (qry_person_id) {
|
|
const match = (
|
|
ev.external_person_id === qry_person_id ||
|
|
ev.poc_person_id === qry_person_id ||
|
|
ev.poc_person_id_random === qry_person_id ||
|
|
ev.poc_event_person_id === qry_person_id ||
|
|
ev.poc_event_person_id_random === qry_person_id
|
|
);
|
|
if (!match) return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (log_lvl) {
|
|
console.log(`Filter results (V3): Input=${processed_obj_li.length}, Output=${filtered_obj_li.length}`);
|
|
}
|
|
|
|
return filtered_obj_li;
|
|
}
|
|
|
|
/**
|
|
* Specialized search function for IDAA module using legacy V2 endpoints.
|
|
* This is isolated to prevent V3 migration bugs from affecting Recovery Meetings.
|
|
*/
|
|
// Updated 2026-01-20
|
|
export async function qry_ae_obj_li__event_v2({
|
|
api_cfg,
|
|
for_obj_type = 'account',
|
|
for_obj_id,
|
|
qry_str,
|
|
qry_person_id = null,
|
|
qry_conference = null,
|
|
qry_physical = null,
|
|
qry_virtual = null,
|
|
qry_type = null,
|
|
enabled = 'enabled',
|
|
hidden = 'not_hidden',
|
|
view = 'default',
|
|
limit = 99,
|
|
offset = 0,
|
|
order_by_li = { start_datetime: 'DESC' } as const,
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
for_obj_type?: string;
|
|
for_obj_id: string;
|
|
qry_str?: string;
|
|
qry_person_id?: string | null;
|
|
qry_conference?: boolean | null;
|
|
qry_physical?: boolean | null;
|
|
qry_virtual?: boolean | null;
|
|
qry_type?: string | null;
|
|
enabled?: 'enabled' | 'all' | 'not_enabled';
|
|
hidden?: 'hidden' | 'all' | 'not_hidden';
|
|
view?: string;
|
|
limit?: number;
|
|
offset?: number;
|
|
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}) {
|
|
if (log_lvl) console.log('*** qry_ae_obj_li__event_v2() ***');
|
|
|
|
const params_json: any = { qry: { and: [] } };
|
|
|
|
if (qry_str) {
|
|
// Use default_qry_str for searching as requested
|
|
params_json.qry.and.push({ field: 'default_qry_str', op: 'like', value: `%${qry_str}%` });
|
|
}
|
|
|
|
const result_li = await get_ae_obj_li_for_obj_id_crud_v2({
|
|
api_cfg,
|
|
obj_type: 'event',
|
|
for_obj_type,
|
|
for_obj_id,
|
|
enabled,
|
|
hidden,
|
|
limit: (qry_person_id || qry_conference !== null || qry_physical !== null || qry_virtual !== null || qry_type !== null) ? 500 : limit,
|
|
offset,
|
|
order_by_li,
|
|
params_json,
|
|
log_lvl
|
|
});
|
|
|
|
if (!result_li) return [];
|
|
|
|
const processed_obj_li = await process_ae_obj__event_props({
|
|
obj_li: result_li,
|
|
log_lvl: log_lvl
|
|
});
|
|
|
|
if (try_cache) {
|
|
await db_save_ae_obj_li__ae_obj({
|
|
db_instance: db_events,
|
|
table_name: 'event',
|
|
obj_li: processed_obj_li,
|
|
properties_to_save: properties_to_save,
|
|
log_lvl: log_lvl
|
|
});
|
|
}
|
|
|
|
// Client-side Filter Layer
|
|
const filtered_obj_li = processed_obj_li.filter((ev: any) => {
|
|
// Handle conference filter
|
|
if (qry_conference != null) {
|
|
const ev_conf = ev.conference === true || ev.conference === 1 || ev.conference === '1';
|
|
if (ev_conf !== !!qry_conference) return false;
|
|
}
|
|
|
|
// Location Filtering (Inclusive OR logic)
|
|
// If either filter is explicitly true, we restrict results.
|
|
// If both are false or null, we show everything.
|
|
if (qry_physical === true || qry_virtual === true) {
|
|
const ev_physical = ev.physical === true || ev.physical === 1 || ev.physical === '1';
|
|
const ev_virtual = ev.virtual === true || ev.virtual === 1 || ev.virtual === '1';
|
|
|
|
let match = false;
|
|
if (qry_physical === true && ev_physical) match = true;
|
|
if (qry_virtual === true && ev_virtual) match = true;
|
|
|
|
if (!match) return false;
|
|
}
|
|
|
|
// Handle type filter (skip if null, undefined, 'all', or empty string)
|
|
if (qry_type != null && qry_type !== 'all' && qry_type !== '') {
|
|
if (ev.type !== qry_type) return false;
|
|
}
|
|
|
|
// Handle person ID filter
|
|
if (qry_person_id) {
|
|
const match = (
|
|
ev.external_person_id === qry_person_id ||
|
|
ev.poc_person_id === qry_person_id ||
|
|
ev.poc_person_id_random === qry_person_id ||
|
|
ev.poc_event_person_id === qry_person_id ||
|
|
ev.poc_event_person_id_random === qry_person_id
|
|
);
|
|
if (!match) return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (log_lvl) {
|
|
console.log(`Filter results (V2): Input=${processed_obj_li.length}, Output=${filtered_obj_li.length}`);
|
|
}
|
|
|
|
return filtered_obj_li;
|
|
}
|
|
|
|
// Updated 2025-05-09
|
|
export const properties_to_save = [
|
|
'id',
|
|
'event_id',
|
|
'event_id_random',
|
|
'code',
|
|
'account_id',
|
|
'account_id_random',
|
|
'conference',
|
|
'type',
|
|
'name',
|
|
'summary',
|
|
'description',
|
|
'start_datetime',
|
|
'end_datetime',
|
|
'timezone',
|
|
'location_address_json',
|
|
'location_text',
|
|
'attend_json',
|
|
'attend_text',
|
|
'status',
|
|
'mod_abstracts_json',
|
|
'mod_badges_json',
|
|
'mod_exhibits_json',
|
|
'mod_meetings_json',
|
|
'mod_pres_mgmt_json',
|
|
'cfg_json',
|
|
'enable',
|
|
'hide',
|
|
'priority',
|
|
'sort',
|
|
'group',
|
|
'notes',
|
|
'created_on',
|
|
'updated_on',
|
|
'contact_li_json',
|
|
'external_person_id',
|
|
'physical',
|
|
'virtual',
|
|
'recurring',
|
|
'recurring_pattern',
|
|
'recurring_start_time',
|
|
'recurring_end_time',
|
|
'recurring_text',
|
|
'weekday_sunday',
|
|
'weekday_monday',
|
|
'weekday_tuesday',
|
|
'weekday_wednesday',
|
|
'weekday_thursday',
|
|
'weekday_friday',
|
|
'weekday_saturday',
|
|
'attend_url',
|
|
'attend_url_text',
|
|
'attend_url_code',
|
|
'attend_url_passcode',
|
|
'attend_phone',
|
|
'attend_phone_passcode',
|
|
'tmp_sort_1',
|
|
'tmp_sort_2',
|
|
'file_count',
|
|
'file_count_all',
|
|
'internal_use_count',
|
|
'event_file_id_li_json'
|
|
];
|
|
|
|
async function _process_generic_props<T extends Record<string, any>>({
|
|
obj_li,
|
|
obj_type,
|
|
log_lvl = 0,
|
|
specific_processor
|
|
}: {
|
|
obj_li: T[];
|
|
obj_type: string;
|
|
log_lvl?: number;
|
|
specific_processor?: (obj: T) => Promise<T> | T;
|
|
}): Promise<T[]> {
|
|
if (!obj_li || obj_li.length === 0) return [];
|
|
|
|
const processed_obj_li: T[] = [];
|
|
|
|
for (const original_obj of obj_li) {
|
|
let processed_obj = { ...original_obj };
|
|
|
|
for (const key in processed_obj) {
|
|
if (key.endsWith('_random')) {
|
|
const newKey = key.slice(0, -7);
|
|
(processed_obj as any)[newKey] = processed_obj[key];
|
|
}
|
|
}
|
|
const randomIdKey = `${obj_type}_id_random`;
|
|
if (processed_obj[randomIdKey]) {
|
|
(processed_obj as any).id = processed_obj[randomIdKey];
|
|
}
|
|
|
|
const group = processed_obj.group ?? '0';
|
|
const priority = processed_obj.priority ? 1 : 0;
|
|
const sort = processed_obj.sort ?? '0';
|
|
const updated = processed_obj.updated_on ?? processed_obj.created_on;
|
|
const name = processed_obj.name ?? '';
|
|
|
|
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
|
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
|
|
|
if (specific_processor) {
|
|
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
|
}
|
|
|
|
processed_obj_li.push(processed_obj as T);
|
|
}
|
|
|
|
return processed_obj_li;
|
|
}
|
|
|
|
// Updated 2026-01-20
|
|
export async function process_ae_obj__event_props({
|
|
obj_li,
|
|
log_lvl = 0
|
|
}: {
|
|
obj_li: any[];
|
|
log_lvl?: number;
|
|
}) {
|
|
return _process_generic_props({
|
|
obj_li,
|
|
obj_type: 'event',
|
|
log_lvl,
|
|
specific_processor: (obj) => {
|
|
if (obj.event_code) {
|
|
obj.code = obj.event_code;
|
|
}
|
|
// Ensure ID consistency for components relying on specific ID fields
|
|
if (!obj.event_id_random && obj.id_random) {
|
|
obj.event_id_random = obj.id_random;
|
|
}
|
|
if (obj.event_id_random && !obj.id) {
|
|
obj.id = obj.event_id_random;
|
|
}
|
|
return obj;
|
|
}
|
|
});
|
|
}
|
|
|
|
export function sync_config__event_pres_mgmt({
|
|
pres_mgmt_cfg_remote,
|
|
pres_mgmt_cfg_local,
|
|
log_lvl = 0
|
|
}: {
|
|
pres_mgmt_cfg_remote: key_val;
|
|
pres_mgmt_cfg_local: key_val;
|
|
log_lvl?: number;
|
|
}) {
|
|
if (log_lvl) {
|
|
console.log(
|
|
`*** sync_config__event_pres_mgmt() *** pres_mgmt_cfg_remote:`,
|
|
pres_mgmt_cfg_remote
|
|
);
|
|
}
|
|
|
|
pres_mgmt_cfg_local.label__person_external_id =
|
|
pres_mgmt_cfg_remote?.label__person_external_id ?? 'External ID';
|
|
pres_mgmt_cfg_local.label__presenter_external_id =
|
|
pres_mgmt_cfg_remote?.label__presenter_external_id ?? 'External ID';
|
|
pres_mgmt_cfg_local.label__session_poc_type =
|
|
pres_mgmt_cfg_remote?.label__session_poc_type ?? 'poc';
|
|
pres_mgmt_cfg_local.label__session_poc_name =
|
|
pres_mgmt_cfg_remote?.label__session_poc_name_short ?? 'POC';
|
|
pres_mgmt_cfg_local.label__session_poc_name =
|
|
pres_mgmt_cfg_remote?.label__session_poc_name ?? 'Point of Contact';
|
|
pres_mgmt_cfg_local.hide__session_poc = pres_mgmt_cfg_remote?.hide__session_poc ?? false;
|
|
pres_mgmt_cfg_local.require__presenter_agree =
|
|
pres_mgmt_cfg_remote?.require__presenter_agree ?? false;
|
|
pres_mgmt_cfg_local.require__session_agree =
|
|
pres_mgmt_cfg_remote?.require__session_agree ?? false;
|
|
pres_mgmt_cfg_local.show__copy_access_link =
|
|
pres_mgmt_cfg_remote?.show__copy_access_link ?? false;
|
|
pres_mgmt_cfg_local.show__email_access_link =
|
|
pres_mgmt_cfg_remote?.show__email_access_link ?? false;
|
|
pres_mgmt_cfg_local.file_purpose_option_kv =
|
|
pres_mgmt_cfg_remote?.file_purpose_option_kv ?? null;
|
|
|
|
if (pres_mgmt_cfg_local.lock_config) {
|
|
console.log(`The config should be locked! Forcing the sync!`);
|
|
pres_mgmt_cfg_local.sync_local_config = true;
|
|
}
|
|
|
|
if (pres_mgmt_cfg_local?.sync_local_config) {
|
|
pres_mgmt_cfg_local.hide__location_code =
|
|
pres_mgmt_cfg_remote?.hide__location_code ?? false;
|
|
pres_mgmt_cfg_local.hide__presentation_code =
|
|
pres_mgmt_cfg_remote?.hide__presentation_code ?? false;
|
|
pres_mgmt_cfg_local.hide__presentation_datetime =
|
|
pres_mgmt_cfg_remote?.hide__presentation_datetime ?? false;
|
|
pres_mgmt_cfg_local.show_content__presentation_description =
|
|
pres_mgmt_cfg_remote?.show_content__presentation_description ?? false;
|
|
pres_mgmt_cfg_local.hide__presenter_code =
|
|
pres_mgmt_cfg_remote?.hide__presenter_code ?? false;
|
|
pres_mgmt_cfg_local.hide__presenter_biography =
|
|
pres_mgmt_cfg_remote?.hide__presenter_biography ?? false;
|
|
pres_mgmt_cfg_local.hide__session_code = pres_mgmt_cfg_remote?.hide__session_code ?? false;
|
|
pres_mgmt_cfg_local.hide__session_description =
|
|
pres_mgmt_cfg_remote?.hide__session_description ?? false;
|
|
pres_mgmt_cfg_local.hide__session_location =
|
|
pres_mgmt_cfg_remote?.hide__session_location ?? false;
|
|
pres_mgmt_cfg_local.hide__session_msg = pres_mgmt_cfg_remote?.hide__session_msg ?? false;
|
|
pres_mgmt_cfg_local.hide__session_poc_profile =
|
|
pres_mgmt_cfg_remote?.hide__session_poc_profile ?? false;
|
|
pres_mgmt_cfg_local.hide__session_poc_biography =
|
|
pres_mgmt_cfg_remote?.hide__session_poc_biography ?? false;
|
|
pres_mgmt_cfg_local.hide__session_poc_profile_pic =
|
|
pres_mgmt_cfg_remote?.hide__session_poc_profile_pic ?? false;
|
|
pres_mgmt_cfg_local.hide_launcher_link = pres_mgmt_cfg_remote?.hide_launcher_link ?? false;
|
|
pres_mgmt_cfg_local.hide_launcher_link_legacy =
|
|
pres_mgmt_cfg_remote?.hide_launcher_link_legacy ?? false;
|
|
}
|
|
|
|
return pres_mgmt_cfg_local;
|
|
} |