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) {