Now with a working V# GET ID and GET nested ID.

This commit is contained in:
Scott Idem
2026-01-05 18:52:11 -05:00
parent bb6b3b7352
commit 45f7393ee3
3 changed files with 111 additions and 135 deletions

View File

@@ -6,6 +6,8 @@ interface GetAeObjV3Params {
obj_type: string;
obj_id: string;
view?: string;
params?: key_val;
headers?: key_val;
log_lvl?: number;
}
@@ -17,21 +19,68 @@ export async function get_ae_obj_v3({
obj_type,
obj_id,
view = 'default',
params = {},
headers = {},
log_lvl = 0
}: GetAeObjV3Params) {
const endpoint = `/v3/crud/${obj_type}/${obj_id}`;
const params: key_val = { view };
const query_params: key_val = { view, ...params };
if (log_lvl) {
console.log('*** get_ae_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Params:', params);
console.log('Params:', query_params);
}
return await get_object({
api_cfg,
endpoint,
params,
params: query_params,
headers,
log_lvl
});
}
interface GetNestedAeObjV3Params {
api_cfg: any;
parent_type: string;
parent_id: string;
child_type: string;
child_id: string;
view?: string;
params?: key_val;
headers?: key_val;
log_lvl?: number;
}
/**
* Get a single nested object by ID (V3)
*/
export async function get_nested_ae_obj_v3({
api_cfg,
parent_type,
parent_id,
child_type,
child_id,
view = 'default',
params = {},
headers = {},
log_lvl = 0
}: GetNestedAeObjV3Params) {
const endpoint = `/v3/crud/${parent_type}/${parent_id}/${child_type}/${child_id}`;
const query_params: key_val = { view, ...params };
if (log_lvl) {
console.log('*** get_nested_ae_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Params:', query_params);
}
return await get_object({
api_cfg,
endpoint,
params: query_params,
headers,
log_lvl
});
}

View File

@@ -12,7 +12,12 @@ import { post_object } from '$lib/ae_api/api_post_object'; // Exported at the en
import { get_ae_obj_id_crud } from '$lib/ae_api/api_get__crud_obj_id';
import { get_ae_obj_li_for_obj_id_crud } from '$lib/ae_api/api_get__crud_obj_li_v1';
import { get_ae_obj_li_for_obj_id_crud_v2 } from '$lib/ae_api/api_get__crud_obj_li_v2';
import { get_ae_obj_v3, get_ae_obj_li_v3, get_nested_obj_li_v3 } from '$lib/ae_api/api_get__crud_obj_li_v3';
import {
get_ae_obj_v3,
get_nested_ae_obj_v3,
get_ae_obj_li_v3,
get_nested_obj_li_v3
} from '$lib/ae_api/api_get__crud_obj_li_v3';
import { search_ae_obj_v3 } from '$lib/ae_api/api_post__crud_search_v3';
// This new function has not been tested yet!!!
@@ -917,6 +922,7 @@ const obj = {
post_object: post_object,
get_ae_obj_id_crud: get_ae_obj_id_crud,
get_ae_obj_v3: get_ae_obj_v3,
get_nested_ae_obj_v3: get_nested_ae_obj_v3,
get_ae_obj_li_for_obj_id_crud: get_ae_obj_li_for_obj_id_crud,
get_ae_obj_li_for_obj_id_crud_v2: get_ae_obj_li_for_obj_id_crud_v2,
get_ae_obj_li_v3: get_ae_obj_li_v3,

View File

@@ -10,6 +10,7 @@
let ae_account_obj_get_promise;
let ae_sponsorship_obj_li_get_promise;
let v3_test_result: any = $state(null);
onMount(() => {
console.log('Testing: +page.svelte');
@@ -17,145 +18,65 @@
console.log(url);
});
if ($ae_loc.account_id) {
$slct.account_id = $ae_loc.account_id;
// handle_load_ae_account_obj_id({account_id: $slct.account_id, try_cache: false});
handle_load_ae_sponsorship_obj_li({ account_id: $slct.account_id, try_cache: false });
async function test_v3_get_id() {
console.log('*** test_v3_get_id() ***');
v3_test_result = 'loading...';
// Test standard V3 GET ID
const result = await api.get_ae_obj_v3({
api_cfg: $ae_api,
obj_type: 'event',
obj_id: '9dv-IV-iz-LY', // Use a known ID
view: 'base',
log_lvl: 1
});
v3_test_result = result;
console.log('V3 GET ID Result:', result);
}
async function handle_load_ae_account_obj_id({ account_id, try_cache = false }) {
console.log('*** handle_load_account_obj_id() ***');
let params = {};
$ae_sess.hub.account_id_qry_status = 'loading';
ae_account_obj_get_promise = api
.get_ae_obj_id_crud({
api_cfg: $ae_api,
obj_type: 'account',
obj_id: account_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 (account_obj_get_result) {
if (account_obj_get_result) {
$slct.account_obj = account_obj_get_result;
console.log(`account object:`, $slct.account_obj);
}
// Auto show the selected account ID
// Is this pushState needed here?
// Set the URL param "account_id" to the current account ID.
const url = new URL(location.href);
url.searchParams.set('account_id', $slct.account_id);
history.pushState({}, '', url);
// Is this postMessage needed here?
let message = { account_id: $slct.account_id };
window.parent.postMessage(message, '*');
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
return ae_account_obj_get_promise;
}
async function handle_load_ae_sponsorship_obj_li({ account_id, try_cache = true }) {
console.log('*** handle_load_ae_sponsorship_obj_li() ***');
// console.log($ae_loc.mod.sponsorships);
// let fulltext_search_qry_str = ($ae_loc.mod.sponsorships && $ae_loc.mod.sponsorships.fulltext_search_qry_str ? $ae_loc.mod.sponsorships.fulltext_search_qry_str : '');
// let qry_virtual = $ae_loc.mod.sponsorships.qry_virtual;
// let qry_physical = $ae_loc.mod.sponsorships.qry_physical;
// let qry_type = $ae_loc.mod.sponsorships.qry_type;
let enabled = $ae_loc.mod.sponsorships.enabled;
let hidden = $ae_loc.mod.sponsorships.hidden;
let limit = $ae_loc.mod.sponsorships.limit;
let offset = $ae_loc.mod.sponsorships.offset;
let params = {};
// params['example1'] = 'all';
// params['example2'] = false;
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': fulltext_search_qry_str,
// 'contact_li_json': fulltext_search_qry_str,
// 'address_default_qry_str': fulltext_search_qry_str, // NOTE: Remove after going live with OSIT ae?
// 'contact_1_default_qry_str': fulltext_search_qry_str, // NOTE: Remove after going live with OSIT ae?
// };
// }
// if (qry_virtual || qry_physical || qry_type) {
// params_json['and_qry'] = {};
// if (qry_virtual) params_json['and_qry']['virtual'] = true;
// if (qry_physical) params_json['and_qry']['physical'] = true;
// if (qry_type) params_json['and_qry']['type'] = qry_type;
// }
// console.log('params_json:', params_json);
// console.log(params_json);
// NOTE: I am not sure if this is actually needed. It may save a little space in the URL.
// if (JSON.stringify(params_json) == JSON.stringify({})) {
// params_json = null;
// }
$ae_loc.mod.sponsorships.qry_status = 'loading';
ae_sponsorship_obj_li_get_promise = api
.get_ae_obj_li_for_obj_id_crud({
api_cfg: $ae_api,
obj_type: 'sponsorship',
for_obj_type: 'account',
for_obj_id: account_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: 0
})
.then(function (sponsorship_obj_li_get_result) {
if (sponsorship_obj_li_get_result) {
$slct.sponsorship_obj_li = sponsorship_obj_li_get_result;
// console.log(`Sponsorship list:`, $slct.sponsorship_obj_li);
} else {
$slct.sponsorship_obj_li = [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {
$ae_loc.mod.sponsorships.qry_status = 'done';
});
return ae_sponsorship_obj_li_get_promise;
async function test_v3_get_nested_id() {
console.log('*** test_v3_get_nested_id() ***');
v3_test_result = 'loading...';
// Test nested V3 GET ID
const result = await api.get_nested_ae_obj_v3({
api_cfg: $ae_api,
parent_type: 'event',
parent_id: '9dv-IV-iz-LY',
child_type: 'event_badge',
child_id: 'XHTX-23-20-42', // Use a known ID
view: 'base',
log_lvl: 1
});
v3_test_result = result;
console.log('V3 GET Nested ID Result:', result);
}
</script>
<div class="container h-full mx-auto flex justify-center items-center">
<div class="container h-full mx-auto flex flex-col justify-center items-center p-4 gap-4">
<div class="space-y-10 text-center flex flex-col items-center">
<h1 class="h1">Aether - Sponsorships (testing)</h1>
<h1 class="h1">Aether - V3 API Testing</h1>
<div class="flex justify-center space-x-2"></div>
<div class="flex justify-center space-x-2">
<button class="btn variant-filled-primary" onclick={test_v3_get_id}>
Test V3 GET ID
</button>
<button class="btn variant-filled-secondary" onclick={test_v3_get_nested_id}>
Test V3 GET Nested ID
</button>
</div>
</div>
{#if v3_test_result}
<div class="card p-4 w-full max-w-2xl bg-surface-100-800-token">
<h3 class="h3">Test Result:</h3>
<pre class="text-xs text-left overflow-auto max-h-96">
{JSON.stringify(v3_test_result, null, 2)}
</pre>
</div>
{/if}
</div>
<style lang="postcss">