Modernize(Events/Sponsorships): Full V3 API Migration and ID Hardening
- API Migration: Refactored Event (Device, Location, Session, Presentation, Presenter, File, Exhibit, BadgeTemplate) and Sponsorship modules to use AE API CRUD V3. - ID Hardening: Ensured all nested collection loads and searches use 'id_random' string identifiers to resolve 404 errors. - Logic Consolidation: Unified property processing via '_process_generic_props'. - Cleanup: Removed redundant '/admin' routes. - Stability: Maintained V2 isolation for IDAA search.
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { api } from '$lib/api/api';
|
||||
|
||||
import { db_sponsorships } from '$lib/ae_sponsorships/db_sponsorships';
|
||||
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
|
||||
|
||||
// import { liveQuery } from "dexie";
|
||||
// import { db_core } from "$lib/db_core";
|
||||
import type { ae_Sponsorship, ae_Sponsorship_Cfg } from '$lib/types/ae_types';
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
@@ -46,7 +43,7 @@ export async function process_ae_obj__sponsorship_cfg_props({
|
||||
obj_type: 'sponsorship_cfg',
|
||||
log_lvl,
|
||||
specific_processor: (obj) => {
|
||||
// Sponsorship Cfg-specific computed sort fields, overriding generic ones if needed
|
||||
// Sponsorship Cfg-specific computed sort fields
|
||||
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
|
||||
obj.sort?.toString().padStart(3, '0') ?? ''
|
||||
}_${obj.updated_on ?? obj.created_on}`;
|
||||
@@ -112,7 +109,7 @@ export async function process_ae_obj__sponsorship_props({
|
||||
obj_type: 'sponsorship',
|
||||
log_lvl,
|
||||
specific_processor: (obj) => {
|
||||
// Sponsorship-specific computed sort fields, overriding generic ones if needed
|
||||
// Sponsorship-specific computed sort fields
|
||||
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
|
||||
obj.sort?.toString().padStart(3, '0') ?? ''
|
||||
}_${obj.updated_on ?? obj.created_on}`;
|
||||
@@ -156,13 +153,10 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
for (const original_obj of obj_li) {
|
||||
let processed_obj = { ...original_obj };
|
||||
|
||||
// --- Common Transformations ---
|
||||
|
||||
// 1. Standardize ID and other '_random' fields
|
||||
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7); // Remove '_random' suffix
|
||||
const newKey = key.slice(0, -7);
|
||||
(processed_obj as any)[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
@@ -172,7 +166,7 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
(processed_obj as any).id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
// 2. Create common computed properties for client-side sorting.
|
||||
// 2. Create common computed properties
|
||||
const group = processed_obj.group ?? '0';
|
||||
const priority = processed_obj.priority ? 1 : 0;
|
||||
const sort = processed_obj.sort ?? '0';
|
||||
@@ -182,7 +176,6 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
|
||||
// --- Specific Transformations ---
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
}
|
||||
@@ -193,8 +186,8 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
// Updated 2024-03-29
|
||||
async function load_ae_obj_id__sponsorship_cfg({
|
||||
// Updated 2026-01-20 to V3
|
||||
export async function load_ae_obj_id__sponsorship_cfg({
|
||||
api_cfg,
|
||||
sponsorship_cfg_id,
|
||||
try_cache = false,
|
||||
@@ -202,85 +195,41 @@ async function load_ae_obj_id__sponsorship_cfg({
|
||||
}: {
|
||||
api_cfg: any;
|
||||
sponsorship_cfg_id: string;
|
||||
try_cache: boolean;
|
||||
log_lvl: number;
|
||||
}) {
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}): Promise<ae_Sponsorship_Cfg | null> {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`*** load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}`
|
||||
);
|
||||
console.log(`*** load_ae_obj_id__sponsorship_cfg() *** [V3] id=${sponsorship_cfg_id}`);
|
||||
}
|
||||
|
||||
const params = {};
|
||||
const sponsorship_cfg_obj_get_result = await api.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'sponsorship_cfg',
|
||||
obj_id: sponsorship_cfg_id,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
ae_promises.load__sponsorship_cfg_obj = api
|
||||
.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'sponsorship_cfg',
|
||||
obj_id: sponsorship_cfg_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: log_lvl
|
||||
})
|
||||
.then(async function (sponsorship_cfg_obj_get_result) {
|
||||
if (sponsorship_cfg_obj_get_result) {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}`
|
||||
);
|
||||
} else if (log_lvl > 1) {
|
||||
console.log(
|
||||
`*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}:`,
|
||||
sponsorship_cfg_obj_get_result
|
||||
);
|
||||
}
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({
|
||||
obj_li: [sponsorship_cfg_obj_get_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_sponsorships,
|
||||
table_name: 'cfg',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save_sponsorship_cfg,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
}
|
||||
return sponsorship_cfg_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
'ae_promises.load__sponsorship_cfg_obj:',
|
||||
ae_promises.load__sponsorship_cfg_obj
|
||||
);
|
||||
if (sponsorship_cfg_obj_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({
|
||||
obj_li: [sponsorship_cfg_obj_get_result],
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_sponsorships,
|
||||
table_name: 'cfg',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save_sponsorship_cfg,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return sponsorship_cfg_obj_get_result;
|
||||
}
|
||||
|
||||
return ae_promises.load__sponsorship_cfg_obj;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Updated 2024-03-29
|
||||
async function load_ae_obj_id__sponsorship({
|
||||
// Updated 2026-01-20 to V3
|
||||
export async function load_ae_obj_id__sponsorship({
|
||||
api_cfg,
|
||||
sponsorship_id,
|
||||
try_cache = false,
|
||||
@@ -288,78 +237,41 @@ async function load_ae_obj_id__sponsorship({
|
||||
}: {
|
||||
api_cfg: any;
|
||||
sponsorship_id: string;
|
||||
try_cache: boolean;
|
||||
log_lvl: number;
|
||||
}) {
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}): Promise<ae_Sponsorship | null> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__sponsorship() *** sponsorship_id=${sponsorship_id}`);
|
||||
console.log(`*** load_ae_obj_id__sponsorship() *** [V3] id=${sponsorship_id}`);
|
||||
}
|
||||
|
||||
const params = {};
|
||||
const sponsorship_obj_get_result = await api.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
obj_id: sponsorship_id,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
ae_promises.load__sponsorship_obj = api
|
||||
.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
obj_id: sponsorship_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: log_lvl
|
||||
})
|
||||
.then(async function (sponsorship_obj_get_result) {
|
||||
if (sponsorship_obj_get_result) {
|
||||
if (log_lvl) {
|
||||
console.log(`*spons_func* Got a result for sponsorship_id ${sponsorship_id}`);
|
||||
} else if (log_lvl > 1) {
|
||||
console.log(
|
||||
`*spons_func* Got a result for sponsorship_id ${sponsorship_id}:`,
|
||||
sponsorship_obj_get_result
|
||||
);
|
||||
}
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
const processed_obj_li = await process_ae_obj__sponsorship_props({
|
||||
obj_li: [sponsorship_obj_get_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_sponsorships,
|
||||
table_name: 'sponsorship',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save_sponsorship,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
}
|
||||
return sponsorship_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__sponsorship_obj:', ae_promises.load__sponsorship_obj);
|
||||
if (sponsorship_obj_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__sponsorship_props({
|
||||
obj_li: [sponsorship_obj_get_result],
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_sponsorships,
|
||||
table_name: 'sponsorship',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save_sponsorship,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return sponsorship_obj_get_result;
|
||||
}
|
||||
|
||||
return ae_promises.load__sponsorship_obj;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Updated 2025-01-15
|
||||
async function load_ae_obj_li__sponsorship({
|
||||
// Updated 2026-01-20 to V3
|
||||
export async function load_ae_obj_li__sponsorship({
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
@@ -367,146 +279,165 @@ async function load_ae_obj_li__sponsorship({
|
||||
hidden = 'not_hidden',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = {
|
||||
priority: 'DESC',
|
||||
sort: 'DESC',
|
||||
name: 'ASC',
|
||||
updated_on: 'DESC',
|
||||
created_on: 'DESC'
|
||||
},
|
||||
params = {},
|
||||
order_by_li = [
|
||||
{ priority: 'DESC' },
|
||||
{ sort: 'DESC' },
|
||||
{ name: 'ASC' },
|
||||
{ updated_on: 'DESC' }
|
||||
],
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
for_obj_type: string;
|
||||
for_obj_id: string;
|
||||
inc_content_li?: boolean;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: key_val;
|
||||
params?: key_val;
|
||||
order_by_li?: any;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
}): Promise<ae_Sponsorship[]> {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`*** load_ae_obj_li__sponsorship() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
|
||||
);
|
||||
console.log(`*** load_ae_obj_li__sponsorship() *** [V3] for=${for_obj_type}:${for_obj_id}`);
|
||||
}
|
||||
|
||||
const params_json: key_val = {};
|
||||
const result_li = await api.get_ae_obj_li_v3({
|
||||
api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
ae_promises.load__sponsorship_obj_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
for_obj_type: for_obj_type,
|
||||
for_obj_id: for_obj_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
use_alt_exp: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (sponsorship_obj_li_get_result) {
|
||||
if (sponsorship_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
const processed_obj_li = await process_ae_obj__sponsorship_props({
|
||||
obj_li: sponsorship_obj_li_get_result,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_sponsorships,
|
||||
table_name: 'sponsorship',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save_sponsorship,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
}
|
||||
return sponsorship_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
if (result_li && try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__sponsorship_props({
|
||||
obj_li: result_li,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_sponsorships,
|
||||
table_name: 'sponsorship',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save_sponsorship,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__sponsorship_obj_li:', ae_promises.load__sponsorship_obj_li);
|
||||
}
|
||||
|
||||
return ae_promises.load__sponsorship_obj_li;
|
||||
return result_li || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new sponsorship (V3)
|
||||
*/
|
||||
export async function create_ae_obj__sponsorship({
|
||||
api_cfg,
|
||||
data,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
data: any;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return await api.create_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
data,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update sponsorship (V3)
|
||||
*/
|
||||
export async function update_ae_obj__sponsorship({
|
||||
api_cfg,
|
||||
sponsorship_id,
|
||||
data,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
sponsorship_id: string;
|
||||
data: any;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return await api.update_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
obj_id: sponsorship_id,
|
||||
data,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete sponsorship (V3)
|
||||
*/
|
||||
export async function delete_ae_obj__sponsorship({
|
||||
api_cfg,
|
||||
sponsorship_id,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
sponsorship_id: string;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return await api.delete_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
obj_id: sponsorship_id,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
export async function download_export__sponsorship({
|
||||
api_cfg,
|
||||
account_id,
|
||||
file_type = 'CSV', // 'CSV' or 'Excel'
|
||||
return_file = true,
|
||||
filename = 'no_filename.csv',
|
||||
auto_download = false,
|
||||
params = {}, // key value object is expected
|
||||
file_type = 'CSV',
|
||||
filename = 'sponsorship_export.csv',
|
||||
params = {},
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id: string;
|
||||
file_type?: string;
|
||||
return_file?: boolean;
|
||||
filename?: string;
|
||||
auto_download?: boolean;
|
||||
params?: key_val;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
console.log('*** stores_event_api.js: get_sponsorship_export() ***');
|
||||
|
||||
// V2 still used for exports as V3 generic doesn't have a standardized export wrapper yet
|
||||
const endpoint = `/v2/crud/sponsorship/list`;
|
||||
params['for_obj_type'] = 'account';
|
||||
params['for_obj_id'] = account_id;
|
||||
const query_params = {
|
||||
...params,
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: account_id,
|
||||
file_type,
|
||||
return_file: true
|
||||
};
|
||||
|
||||
if (file_type == 'CSV' || file_type == 'Excel') {
|
||||
params['file_type'] = file_type;
|
||||
}
|
||||
params['return_file'] = true;
|
||||
|
||||
ae_promises.download__sponsorship_export_file = await api.get_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
params: params,
|
||||
return_blob: return_file,
|
||||
filename: filename,
|
||||
auto_download: auto_download,
|
||||
log_lvl: log_lvl
|
||||
return await api.get_object({
|
||||
api_cfg,
|
||||
endpoint,
|
||||
params: query_params,
|
||||
return_blob: true,
|
||||
filename,
|
||||
auto_download: true,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
console.log(
|
||||
'ae_promises.download__sponsorship_export_file:',
|
||||
ae_promises.download__sponsorship_export_file
|
||||
);
|
||||
return ae_promises.download__sponsorship_export_file;
|
||||
}
|
||||
|
||||
const export_obj = {
|
||||
load_ae_obj_id__sponsorship_cfg: load_ae_obj_id__sponsorship_cfg,
|
||||
load_ae_obj_id__sponsorship: load_ae_obj_id__sponsorship,
|
||||
load_ae_obj_li__sponsorship: load_ae_obj_li__sponsorship,
|
||||
download_export__sponsorship: download_export__sponsorship
|
||||
};
|
||||
export const spons_func = export_obj;
|
||||
export const spons_func = {
|
||||
load_ae_obj_id__sponsorship_cfg,
|
||||
load_ae_obj_id__sponsorship,
|
||||
load_ae_obj_li__sponsorship,
|
||||
create_ae_obj__sponsorship,
|
||||
update_ae_obj__sponsorship,
|
||||
delete_ae_obj__sponsorship,
|
||||
download_export__sponsorship
|
||||
};
|
||||
Reference in New Issue
Block a user