I think we are done with the first big rounds of changes by Gemini.
This commit is contained in:
@@ -53,7 +53,7 @@ export interface GenericCrudArgs {
|
||||
export async function load_ae_obj_id(
|
||||
args: GenericCrudArgs
|
||||
): Promise<any> {
|
||||
const { api_cfg, obj_type, obj_id, db_instance, db_field_li, inc_obj_type_li, try_cache = true, log_lvl = 0 } = args;
|
||||
const { api_cfg, obj_type, obj_id, log_lvl = 0 } = args;
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id() *** obj_type=${obj_type} obj_id=${obj_id}`);
|
||||
@@ -67,79 +67,6 @@ export async function load_ae_obj_id(
|
||||
log_lvl
|
||||
});
|
||||
|
||||
let idb_db_instance = null; // You must inject the correct DB instance per module
|
||||
let idb_tbl_name = obj_type;
|
||||
let properties_to_save: string[] = [];
|
||||
if (obj_type === 'journal') {
|
||||
idb_db_instance = 'ae_journals_db';
|
||||
// idb_tbl_name = 'journal';
|
||||
|
||||
result.id = result.journal_id_random; // Ensure we use the correct ID field
|
||||
result.journal_id = result.journal_id_random;
|
||||
result.account_id = result.account_id_random;
|
||||
result.person_id = result.person_id_random;
|
||||
|
||||
// WARNING: This works to populate most of the IDB table fields but it is not ideal. It is sort of a safety net.
|
||||
properties_to_save = Object.keys(db_instance.table('journal').schema.idxByName);
|
||||
}
|
||||
if (obj_type === 'journal_entry') {
|
||||
idb_db_instance = 'ae_journals_db';
|
||||
// idb_tbl_name = 'entry';
|
||||
|
||||
result.id = result.journal_entry_id_random; // Ensure we use the correct ID field
|
||||
result.journal_entry_id = result.journal_entry_id_random; // Ensure we use the correct ID field
|
||||
result.journal_id = result.journal_id_random;
|
||||
|
||||
// WARNING: This works to populate most of the IDB table fields but it is not ideal. It is sort of a safety net.
|
||||
properties_to_save = Object.keys(db_instance.table('journal_entry').schema.idxByName);
|
||||
|
||||
}
|
||||
properties_to_save = [
|
||||
...db_field_li
|
||||
];
|
||||
|
||||
// if (log_lvl) {
|
||||
// console.log('IDB DB Instance:', db_instance);
|
||||
// console.log(db_instance.journal_entry.core.schema);
|
||||
// console.log(db_instance.table('journal_entry'));
|
||||
// console.log(db_instance.table('journal_entry').schema.idxByName);
|
||||
// // Show only the keys of the indexes
|
||||
// console.log(Object.keys(db_instance.table('journal_entry').schema.idxByName));
|
||||
// }
|
||||
|
||||
if (try_cache && result) {
|
||||
// Process and save to DB
|
||||
const processed = await process_ae_obj__props({ obj_li: [result], log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_instance, // You must inject the correct DB instance per module
|
||||
table_name: idb_tbl_name,
|
||||
obj_li: processed,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
if (inc_obj_type_li) {
|
||||
// Load related objects if specified
|
||||
for (const inc_obj_type of inc_obj_type_li) {
|
||||
if (log_lvl) {
|
||||
console.log(`Loading related objects of type: ${inc_obj_type}`);
|
||||
}
|
||||
const related_objects = await load_ae_obj_li({
|
||||
api_cfg,
|
||||
obj_type: inc_obj_type,
|
||||
for_obj_type: obj_type,
|
||||
for_obj_id: obj_id,
|
||||
enabled: 'enabled',
|
||||
hidden: 'not_hidden',
|
||||
limit: 99,
|
||||
try_cache,
|
||||
log_lvl
|
||||
});
|
||||
result[`${inc_obj_type}_li`] = related_objects;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -152,8 +79,6 @@ export async function load_ae_obj_li(
|
||||
obj_type,
|
||||
for_obj_type = '',
|
||||
for_obj_id,
|
||||
db_instance,
|
||||
db_field_li,
|
||||
inc_obj_type_li,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
@@ -186,49 +111,6 @@ export async function load_ae_obj_li(
|
||||
log_lvl
|
||||
});
|
||||
|
||||
// Loop through results a
|
||||
let idb_db_instance = null; // You must inject the correct DB instance per module
|
||||
let idb_tbl_name = obj_type;
|
||||
let properties_to_save: string[] = [];
|
||||
if (obj_type === 'journal') {
|
||||
idb_db_instance = 'ae_journals_db';
|
||||
// idb_tbl_name = 'journal';
|
||||
|
||||
result.id = result.journal_id_random; // Ensure we use the correct ID field
|
||||
result.journal_id = result.journal_id_random;
|
||||
result.account_id = result.account_id_random;
|
||||
result.person_id = result.person_id_random;
|
||||
|
||||
// WARNING: This works to populate most of the IDB table fields but it is not ideal. It is sort of a safety net.
|
||||
properties_to_save = Object.keys(db_instance.table('journal').schema.idxByName);
|
||||
}
|
||||
if (obj_type === 'journal_entry') {
|
||||
idb_db_instance = 'ae_journals_db';
|
||||
// idb_tbl_name = 'entry';
|
||||
|
||||
result.id = result.journal_entry_id_random; // Ensure we use the correct ID field
|
||||
result.journal_entry_id = result.journal_entry_id_random; // Ensure we use the correct ID field
|
||||
result.journal_id = result.journal_id_random;
|
||||
|
||||
// WARNING: This works to populate most of the IDB table fields but it is not ideal. It is sort of a safety net.
|
||||
properties_to_save = Object.keys(db_instance.table('journal_entry').schema.idxByName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (try_cache && result) {
|
||||
// Process and save to DB
|
||||
const processed = await process_ae_obj__props({ obj_li: result, log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_instance,
|
||||
table_name: idb_tbl_name,
|
||||
obj_li: processed,
|
||||
properties_to_save: [],
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -236,7 +118,7 @@ export async function load_ae_obj_li(
|
||||
export async function create_ae_obj(
|
||||
args: GenericCrudArgs
|
||||
): Promise<any> {
|
||||
const { api_cfg, obj_type, data_kv, try_cache = true, log_lvl = 0 } = args;
|
||||
const { api_cfg, obj_type, data_kv, log_lvl = 0 } = args;
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj() *** obj_type=${obj_type}`, data_kv);
|
||||
@@ -252,17 +134,6 @@ export async function create_ae_obj(
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (try_cache && result) {
|
||||
const processed = await process_ae_obj__props({ obj_li: [result], log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: null,
|
||||
table_name: obj_type,
|
||||
obj_li: processed,
|
||||
properties_to_save: [],
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -270,7 +141,7 @@ export async function create_ae_obj(
|
||||
export async function update_ae_obj(
|
||||
args: GenericCrudArgs
|
||||
): Promise<any> {
|
||||
const { api_cfg, obj_type, obj_id, data_kv, try_cache = true, log_lvl = 0 } = args;
|
||||
const { api_cfg, obj_type, obj_id, data_kv, log_lvl = 0 } = args;
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj() *** obj_type=${obj_type} obj_id=${obj_id}`, data_kv);
|
||||
@@ -287,17 +158,6 @@ export async function update_ae_obj(
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (try_cache && result) {
|
||||
const processed = await process_ae_obj__props({ obj_li: [result], log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: null,
|
||||
table_name: obj_type,
|
||||
obj_li: processed,
|
||||
properties_to_save: [],
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -305,7 +165,7 @@ export async function update_ae_obj(
|
||||
export async function delete_ae_obj_id(
|
||||
args: GenericCrudArgs
|
||||
): Promise<any> {
|
||||
const { api_cfg, obj_type, obj_id, method = 'delete', try_cache = true, log_lvl = 0 } = args;
|
||||
const { api_cfg, obj_type, obj_id, method = 'delete', log_lvl = 0 } = args;
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id() *** obj_type=${obj_type} obj_id=${obj_id}`);
|
||||
@@ -321,15 +181,6 @@ export async function delete_ae_obj_id(
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (try_cache) {
|
||||
// Remove from DB regardless of success/failure
|
||||
try {
|
||||
// db_<module>.<obj_type>.delete(obj_id); // You must inject the correct DB here
|
||||
} catch (err) {
|
||||
console.error(`Failed to delete ${obj_id}:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user