Code clean up. Journal IDB save has been updated to properly await.
This commit is contained in:
@@ -115,6 +115,7 @@ export async function load_ae_obj_li__journal(
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
qry_person_id = null,
|
||||
inc_entry_li = false,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
@@ -128,6 +129,7 @@ export async function load_ae_obj_li__journal(
|
||||
api_cfg: any,
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
qry_person_id?: string|null,
|
||||
inc_entry_li?: boolean,
|
||||
enabled?: string, // all, disabled, enabled
|
||||
hidden?: string, // all, hidden, not_hidden
|
||||
@@ -145,7 +147,20 @@ export async function load_ae_obj_li__journal(
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
if (qry_person_id) {
|
||||
let qry_param =
|
||||
{
|
||||
type: "AND",
|
||||
field: "person_id_random",
|
||||
operator: "=",
|
||||
value: qry_person_id
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
}
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('params_json:', params_json);
|
||||
}
|
||||
|
||||
ae_promises.load__journal_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
@@ -341,28 +356,28 @@ export async function delete_ae_obj_id__journal(
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-03-15
|
||||
export async function update_ae_obj__journal(
|
||||
{
|
||||
api_cfg,
|
||||
journal_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
journal_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
// Updated 2025-05-09
|
||||
export async function update_ae_obj__journal({
|
||||
api_cfg,
|
||||
journal_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0,
|
||||
}: {
|
||||
api_cfg: any;
|
||||
journal_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__journal() *** journal_id=${journal_id}`, data_kv);
|
||||
}
|
||||
ae_promises.update__journal_obj = await api.update_ae_obj_id_crud({
|
||||
|
||||
// Perform the API update
|
||||
const result = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal',
|
||||
obj_id: journal_id,
|
||||
@@ -370,31 +385,25 @@ export async function update_ae_obj__journal(
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (journal_obj_update_result) {
|
||||
if (journal_obj_update_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal', obj_li: [journal_obj_update_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return journal_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_obj:', ae_promises.update__journal_obj);
|
||||
// Handle the result
|
||||
if (result) {
|
||||
if (try_cache) {
|
||||
console.log('Saving to DB...');
|
||||
await db_save_ae_obj_li__journal({
|
||||
obj_type: 'journal',
|
||||
obj_li: [result],
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
console.error('Failed to update journal.');
|
||||
return null;
|
||||
}
|
||||
return ae_promises.update__journal_obj;
|
||||
}
|
||||
|
||||
|
||||
@@ -517,8 +526,8 @@ export async function qry__journal(
|
||||
|
||||
|
||||
// This function will loop through the journal_obj_li and save each one to the DB.
|
||||
// Updated 2025-03-15
|
||||
export function db_save_ae_obj_li__journal(
|
||||
// Updated 2025-05-09
|
||||
export async function db_save_ae_obj_li__journal(
|
||||
{
|
||||
obj_type,
|
||||
obj_li,
|
||||
@@ -530,11 +539,13 @@ export function db_save_ae_obj_li__journal(
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__journal() ***`);
|
||||
console.log(`*** db_save_ae_obj_li__journal() *** obj_type=${obj_type}`, obj_li);
|
||||
}
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
obj_li.forEach(async function (obj: any) {
|
||||
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);
|
||||
}
|
||||
@@ -648,8 +659,8 @@ export function db_save_ae_obj_li__journal(
|
||||
console.log(`Saved record with ID: ${obj_record.id}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
return obj_li_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,6 +324,8 @@ export async function delete_ae_obj_id__journal_entry(
|
||||
// return await ae_promises.update__journal_entry_obj;
|
||||
// }
|
||||
|
||||
|
||||
// Updated 2025-05-09
|
||||
export async function update_ae_obj__journal_entry(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -344,6 +346,7 @@ export async function update_ae_obj__journal_entry(
|
||||
console.log(`*** update_ae_obj__journal_entry() *** journal_entry_id=${journal_entry_id}`, data_kv);
|
||||
}
|
||||
|
||||
// Perform the API update
|
||||
const result = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'journal_entry',
|
||||
@@ -355,6 +358,7 @@ export async function update_ae_obj__journal_entry(
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
|
||||
// Handle the result
|
||||
if (result) {
|
||||
if (try_cache) {
|
||||
console.log('Saving to DB...');
|
||||
@@ -374,7 +378,7 @@ export async function update_ae_obj__journal_entry(
|
||||
|
||||
|
||||
// This function will loop through the journal_entry_obj_li and save each one to the DB.
|
||||
// Updated 2025-03-15
|
||||
// Updated 2025-05-09
|
||||
export async function db_save_ae_obj_li__journal_entry(
|
||||
{
|
||||
obj_type,
|
||||
|
||||
Reference in New Issue
Block a user