Work on making the Journal Entry saving better.

This commit is contained in:
Scott Idem
2025-05-08 19:37:15 -04:00
parent 0e249b2e6d
commit 8c81f6f65e
5 changed files with 437 additions and 133 deletions

View File

@@ -261,27 +261,90 @@ export async function delete_ae_obj_id__journal_entry(
// Updated 2025-03-15
// export async function update_ae_obj__journal_entry(
// {
// api_cfg,
// journal_entry_id,
// data_kv,
// params = {},
// try_cache = true,
// log_lvl = 0
// }: {
// api_cfg: any,
// journal_entry_id: string,
// data_kv: key_val,
// params?: key_val,
// try_cache?: boolean,
// log_lvl?: number
// }
// ) {
// if (log_lvl) {
// console.log(`*** update_ae_obj__journal_entry() *** journal_entry_id=${journal_entry_id}`, data_kv);
// }
// ae_promises.update__journal_entry_obj = api.update_ae_obj_id_crud({
// 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
// })
// .then(async function (journal_entry_obj_update_result) {
// // if (journal_entry_obj_update_result) {
// if (try_cache) {
// db_save_ae_obj_li__journal_entry({
// obj_type: 'journal_entry',
// obj_li: [journal_entry_obj_update_result],
// log_lvl: log_lvl
// })
// .then(function (result) {
// return result;
// })
// .finally(function () {
// return journal_entry_obj_update_result;
// });
// } else {
// return journal_entry_obj_update_result;
// }
// // } else {
// // return null;
// // }
// })
// .catch(function (error) {
// console.log('No results returned or failed.', error);
// })
// .finally(function () {
// });
// if (log_lvl) {
// console.log('ae_promises.update__journal_entry_obj:', ae_promises.update__journal_entry_obj);
// }
// return await ae_promises.update__journal_entry_obj;
// }
export async function update_ae_obj__journal_entry(
{
api_cfg,
journal_entry_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
journal_entry_id: string,
data_kv: key_val,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
{
api_cfg,
journal_entry_id,
data_kv,
params = {},
try_cache = true,
log_lvl = 0,
}: {
api_cfg: any;
journal_entry_id: string;
data_kv: key_val;
params?: key_val,
try_cache?: boolean,
log_lvl?: number;
}) {
if (log_lvl) {
console.log(`*** update_ae_obj__journal_entry() *** journal_entry_id=${journal_entry_id}`, data_kv);
}
ae_promises.update__journal_entry_obj = await api.update_ae_obj_id_crud({
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'journal_entry',
obj_id: journal_entry_id,
@@ -289,31 +352,24 @@ export async function update_ae_obj__journal_entry(
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (journal_entry_obj_update_result) {
if (journal_entry_obj_update_result) {
if (try_cache) {
await db_save_ae_obj_li__journal_entry({
obj_type: 'journal_entry', obj_li: [journal_entry_obj_update_result],
log_lvl: log_lvl
});
}
return journal_entry_obj_update_result;
} else {
return null;
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('ae_promises.update__journal_entry_obj:', ae_promises.update__journal_entry_obj);
if (result) {
if (try_cache) {
console.log('Saving to DB...');
await db_save_ae_obj_li__journal_entry({
obj_type: 'journal_entry',
obj_li: [result],
log_lvl: log_lvl,
});
console.log('DB save completed.');
}
return result;
} else {
console.error('Failed to update journal entry.');
return null;
}
return ae_promises.update__journal_entry_obj;
}
@@ -331,11 +387,14 @@ export async function db_save_ae_obj_li__journal_entry(
}
) {
if (log_lvl) {
console.log(`*** db_save_ae_obj_li__journal_entry() ***`, log_lvl);
console.log(`*** db_save_ae_obj_li__journal_entry() *** obj_type=${obj_type}`, obj_li);
}
if (obj_li && obj_li.length) {
obj_li.forEach(async function (obj: any) {
// let obj_li_id = obj_li.map((obj: any) => obj.journal_entry_id_random);
let obj_li_id: string[] = [];
for (const obj of obj_li) {
// obj_li.forEach(async function (obj: any) {
if (log_lvl) {
console.log(`ae_obj ${obj_type}:`, obj);
}
@@ -501,6 +560,7 @@ export async function db_save_ae_obj_li__journal_entry(
if (log_lvl) {
console.log(`Updated record with ID: ${obj_record.id}`);
}
obj_li_id.push(obj_record.id);
}
if (!id_random) {
console.log(`Failed to save record with ID: ${obj_record.id}`);
@@ -509,8 +569,9 @@ export async function db_save_ae_obj_li__journal_entry(
console.log(`Saved record with ID: ${obj_record.id}`);
}
}
});
// });
}
return true;
return obj_li_id;
}
}

View File

@@ -88,6 +88,7 @@ let journals_session_data_struct: key_val = {
tmp_obj: {},
},
entry: {
decrypt_kv: {}, // Essentially flag that the entry (content and history) can be decrypted.
edit: false,
edit_kv: {},