The ability to use V3 Create Nested works.

This commit is contained in:
Scott Idem
2026-01-05 19:10:07 -05:00
parent 45f7393ee3
commit d066da9047
4 changed files with 237 additions and 6 deletions

View File

@@ -0,0 +1,190 @@
import type { key_val } from '$lib/stores/ae_stores';
import { post_object } from './api_post_object';
import { patch_object } from './api_patch_object';
import { delete_object } from './api_delete_object';
/**
* --- POST (CREATE) WRAPPERS ---
*/
interface CreateAeObjV3Params {
api_cfg: any;
obj_type: string;
fields: key_val;
params?: key_val;
log_lvl?: number;
}
export async function create_ae_obj_v3({
api_cfg,
obj_type,
fields,
params = {},
log_lvl = 0
}: CreateAeObjV3Params) {
const endpoint = `/v3/crud/${obj_type}/`;
if (log_lvl) {
console.log('*** create_ae_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Fields:', fields);
}
return await post_object({
api_cfg,
endpoint,
params,
data: fields,
log_lvl
});
}
interface CreateNestedObjV3Params {
api_cfg: any;
parent_type: string;
parent_id: string;
child_type: string;
fields: key_val;
params?: key_val;
log_lvl?: number;
}
export async function create_nested_obj_v3({
api_cfg,
parent_type,
parent_id,
child_type,
fields,
params = {},
log_lvl = 0
}: CreateNestedObjV3Params) {
const endpoint = `/v3/crud/${parent_type}/${parent_id}/${child_type}/`;
if (log_lvl) {
console.log('*** create_nested_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Fields:', fields);
}
return await post_object({
api_cfg,
endpoint,
params,
data: fields,
log_lvl
});
}
/**
* --- PATCH (UPDATE) WRAPPERS ---
*/
interface UpdateAeObjV3Params {
api_cfg: any;
obj_type: string;
obj_id: string;
fields: key_val;
params?: key_val;
log_lvl?: number;
}
export async function update_ae_obj_v3({
api_cfg,
obj_type,
obj_id,
fields,
params = {},
log_lvl = 0
}: UpdateAeObjV3Params) {
const endpoint = `/v3/crud/${obj_type}/${obj_id}`;
if (log_lvl) {
console.log('*** update_ae_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Fields:', fields);
}
return await patch_object({
api_cfg,
endpoint,
params,
data: fields,
log_lvl
});
}
interface UpdateNestedObjV3Params {
api_cfg: any;
parent_type: string;
parent_id: string;
child_type: string;
child_id: string;
fields: key_val;
params?: key_val;
log_lvl?: number;
}
export async function update_nested_obj_v3({
api_cfg,
parent_type,
parent_id,
child_type,
child_id,
fields,
params = {},
log_lvl = 0
}: UpdateNestedObjV3Params) {
const endpoint = `/v3/crud/${parent_type}/${parent_id}/${child_type}/${child_id}`;
if (log_lvl) {
console.log('*** update_nested_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Fields:', fields);
}
return await patch_object({
api_cfg,
endpoint,
params,
data: fields,
log_lvl
});
}
/**
* --- DELETE WRAPPERS ---
*/
interface DeleteAeObjV3Params {
api_cfg: any;
obj_type: string;
obj_id: string;
method?: 'delete' | 'soft_delete';
params?: key_val;
log_lvl?: number;
}
export async function delete_ae_obj_v3({
api_cfg,
obj_type,
obj_id,
method = 'delete',
params = {},
log_lvl = 0
}: DeleteAeObjV3Params) {
const endpoint = `/v3/crud/${obj_type}/${obj_id}`;
const query_params = { ...params, method };
if (log_lvl) {
console.log('*** delete_ae_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Params:', query_params);
}
return await delete_object({
api_cfg,
endpoint,
params: query_params,
log_lvl
});
}

View File

@@ -124,7 +124,10 @@ export const post_object = async function post_object({
console.warn('404 Not Found. Returning null.');
return null; // Returning null since there were no results
}
throw new Error(`HTTP error! status: ${response.status}`);
const errorBody = await response.text();
console.error(`HTTP error! status: ${response.status}`, errorBody);
throw new Error(`HTTP error! status: ${response.status} - ${errorBody}`);
}
if (!return_blob) {

View File

@@ -19,6 +19,13 @@ import {
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';
import {
create_ae_obj_v3,
create_nested_obj_v3,
update_ae_obj_v3,
update_nested_obj_v3,
delete_ae_obj_v3
} from '$lib/ae_api/api_post__crud_obj_v3';
// This new function has not been tested yet!!!
// Updated 2024-08-07
@@ -928,6 +935,11 @@ const obj = {
get_ae_obj_li_v3: get_ae_obj_li_v3,
get_nested_obj_li_v3: get_nested_obj_li_v3,
search_ae_obj_v3: search_ae_obj_v3,
create_ae_obj_v3: create_ae_obj_v3,
create_nested_obj_v3: create_nested_obj_v3,
update_ae_obj_v3: update_ae_obj_v3,
update_nested_obj_v3: update_nested_obj_v3,
delete_ae_obj_v3: delete_ae_obj_v3,
create_ae_obj_crud: create_ae_obj_crud,
update_ae_obj_id_crud: update_ae_obj_id_crud,
delete_ae_obj_id_crud: delete_ae_obj_id_crud,

View File

@@ -21,7 +21,7 @@
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,
@@ -30,7 +30,7 @@
view: 'base',
log_lvl: 1
});
v3_test_result = result;
console.log('V3 GET ID Result:', result);
}
@@ -38,7 +38,7 @@
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,
@@ -49,23 +49,49 @@
view: 'base',
log_lvl: 1
});
v3_test_result = result;
console.log('V3 GET Nested ID Result:', result);
}
async function test_v3_create_nested() {
console.log('*** test_v3_create_nested() ***');
v3_test_result = 'loading...';
// Test creating a journal entry under the test journal
const result = await api.create_nested_obj_v3({
api_cfg: $ae_api,
parent_type: 'journal',
parent_id: 'JGEB-80-92-50',
child_type: 'journal_entry',
fields: {
account_id_random: 'nqOzejLCDXM',
name: 'Test V3 Nested Create',
content: 'This was created using the new V3 nested create wrapper!',
enable: true
},
log_lvl: 1
});
v3_test_result = result;
console.log('V3 Create Nested Result:', result);
}
</script>
<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 - V3 API Testing</h1>
<div class="flex justify-center space-x-2">
<div class="flex justify-center flex-wrap gap-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>
<button class="btn variant-filled-tertiary" onclick={test_v3_create_nested}>
Test V3 Create Nested
</button>
</div>
</div>