Implement V3 PATCH/DELETE wrappers and migrate Journals module to full V3 CRUD.

- Added update_ae_obj_v3, update_nested_obj_v3, delete_ae_obj_v3, and delete_nested_ae_obj_v3.
- Refactored Journals and Journal Entries modules to utilize the new V3 API wrappers.
- Standardized data processing and IDB caching for all CRUD operations in Journals.
- Updated testing page with comprehensive V3 CUD test buttons.
This commit is contained in:
Scott Idem
2026-01-05 19:30:12 -05:00
parent d066da9047
commit c6476cd767
6 changed files with 147 additions and 171 deletions

View File

@@ -8,7 +8,7 @@ import { db_journals } from '$lib/ae_journals/db_journals';
const ae_promises: key_val = {};
// Updated 2025-03-15
// Updated 2026-01-05
export async function load_ae_obj_id__journal_entry({
api_cfg,
journal_entry_id,
@@ -24,16 +24,11 @@ export async function load_ae_obj_id__journal_entry({
console.log(`*** load_ae_obj_id__journal_entry() *** journal_entry_id=${journal_entry_id}`);
}
const params = {};
ae_promises.load__journal_entry_obj = await api
.get_ae_obj_id_crud({
.get_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'journal_entry',
obj_id: journal_entry_id, // NOTE: This is the FQDN, not normally the ID.
use_alt_table: true, // 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
params: params,
obj_id: journal_entry_id,
log_lvl: log_lvl
})
.then(async function (journal_entry_obj_get_result) {
@@ -48,9 +43,6 @@ export async function load_ae_obj_id__journal_entry({
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_journals,
table_name: 'journal_entry',
@@ -58,16 +50,6 @@ export async function load_ae_obj_id__journal_entry({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// db_save_ae_obj_li__journal_entry({
// obj_type: 'journal_entry',
// obj_li: [journal_entry_obj_get_result],
// log_lvl: log_lvl
// });
}
return journal_entry_obj_get_result;
} else {
@@ -197,7 +179,7 @@ export async function load_ae_obj_li__journal_entry({
return ae_promises.load__journal_entry_obj_li;
}
// Updated 2025-03-15
// Updated 2026-01-05
export async function create_ae_obj__journal_entry({
api_cfg,
journal_id,
@@ -223,16 +205,13 @@ export async function create_ae_obj__journal_entry({
}
ae_promises.create__journal_entry = await api
.create_ae_obj_crud({
.create_nested_obj_v3({
api_cfg: api_cfg,
obj_type: 'journal_entry',
fields: {
journal_id_random: journal_id,
...data_kv
},
key: api_cfg.api_crud_super_key,
parent_type: 'journal',
parent_id: journal_id,
child_type: 'journal_entry',
fields: data_kv,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (journal_entry_obj_create_result) {
@@ -248,9 +227,6 @@ export async function create_ae_obj__journal_entry({
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_journals,
table_name: 'journal_entry',
@@ -258,16 +234,6 @@ export async function create_ae_obj__journal_entry({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__journal_entry(
// {
// obj_type: 'journal_entry',
// obj_li: [journal_entry_obj_create_result],
// log_lvl: log_lvl
// });
}
return journal_entry_obj_create_result;
} else {
@@ -278,13 +244,10 @@ export async function create_ae_obj__journal_entry({
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log('ae_promises.create__journal_entry:', ae_promises.create__journal_entry);
}
return ae_promises.create__journal_entry;
}
// Updated 2025-03-15
// Updated 2026-01-05
export async function delete_ae_obj_id__journal_entry({
api_cfg,
journal_entry_id,
@@ -295,7 +258,7 @@ export async function delete_ae_obj_id__journal_entry({
}: {
api_cfg: any;
journal_entry_id: string;
method?: string;
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -307,13 +270,12 @@ export async function delete_ae_obj_id__journal_entry({
}
ae_promises.delete__journal_entry_obj = await api
.delete_ae_obj_id_crud({
.delete_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'journal_entry',
obj_id: journal_entry_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
params: params,
log_lvl: log_lvl
})
.catch(function (error: any) {
@@ -330,13 +292,6 @@ export async function delete_ae_obj_id__journal_entry({
}
});
if (log_lvl) {
console.log(
'ae_promises.delete__journal_entry_obj:',
ae_promises.delete__journal_entry_obj
);
}
return ae_promises.delete__journal_entry_obj;
}
@@ -431,12 +386,20 @@ export async function qry__journal_entry({
offset,
log_lvl
})
.then(function (journal_entry_obj_li_get_result) {
.then(async function (journal_entry_obj_li_get_result) {
if (journal_entry_obj_li_get_result) {
if (try_cache) {
db_save_ae_obj_li__journal_entry({
obj_type: 'journal_entry',
obj_li: journal_entry_obj_li_get_result
const processed_obj_li = await process_ae_obj__journal_entry_props({
obj_li: journal_entry_obj_li_get_result,
journal_id,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_journals,
table_name: 'journal_entry',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return journal_entry_obj_li_get_result;
@@ -518,7 +481,7 @@ export async function qry__journal_entry({
// return await ae_promises.update__journal_entry_obj;
// }
// Updated 2025-05-09
// Updated 2026-01-05
export async function update_ae_obj__journal_entry({
api_cfg,
journal_entry_id,
@@ -534,7 +497,6 @@ export async function update_ae_obj__journal_entry({
try_cache?: boolean;
log_lvl?: number;
}) {
// log_lvl = 1;
if (log_lvl) {
console.log(
`*** update_ae_obj__journal_entry() *** journal_entry_id=${journal_entry_id}`,
@@ -543,14 +505,12 @@ export async function update_ae_obj__journal_entry({
}
// Perform the API update
const result = await api.update_ae_obj_id_crud({
const result = await api.update_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'journal_entry',
obj_id: journal_entry_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
});
@@ -566,9 +526,6 @@ export async function update_ae_obj__journal_entry({
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_journals,
table_name: 'journal_entry',
@@ -576,15 +533,6 @@ export async function update_ae_obj__journal_entry({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__journal_entry({
// obj_type: 'journal_entry',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {