Code clean up
This commit is contained in:
@@ -77,6 +77,7 @@ export async function load_ae_obj_id__journal(
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
@@ -228,6 +229,7 @@ export async function load_ae_obj_li__journal(
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
// obj_li: journal_obj_li_get_result,
|
||||
@@ -348,6 +350,7 @@ export async function create_ae_obj__journal(
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// db_save_ae_obj_li__journal(
|
||||
// {
|
||||
// obj_type: 'journal',
|
||||
@@ -483,6 +486,7 @@ export async function update_ae_obj__journal({
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// await db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
// obj_li: [result],
|
||||
@@ -622,6 +626,7 @@ export async function qry__journal(
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
}
|
||||
|
||||
// db_save_ae_obj_li__journal({
|
||||
// obj_type: 'journal',
|
||||
// obj_li: journal_obj_li_get_result
|
||||
@@ -640,154 +645,154 @@ export async function qry__journal(
|
||||
|
||||
|
||||
// This function will loop through the journal_obj_li and save each one to the DB.
|
||||
// Updated 2025-05-09
|
||||
export async function db_save_ae_obj_li__journal(
|
||||
{
|
||||
obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_type: string,
|
||||
obj_li: any,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__journal() *** obj_type=${obj_type}`, obj_li);
|
||||
}
|
||||
// Removed 2025-06-04
|
||||
// export async function db_save_ae_obj_li__journal(
|
||||
// {
|
||||
// obj_type,
|
||||
// obj_li,
|
||||
// log_lvl = 0
|
||||
// }: {
|
||||
// obj_type: string,
|
||||
// obj_li: any,
|
||||
// log_lvl?: number
|
||||
// }
|
||||
// ) {
|
||||
// if (log_lvl) {
|
||||
// console.log(`*** db_save_ae_obj_li__journal() *** obj_type=${obj_type}`, obj_li);
|
||||
// }
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
let obj_li_id: string[] = [];
|
||||
// if (obj_li && obj_li.length) {
|
||||
// let obj_li_id: string[] = [];
|
||||
|
||||
for (const obj of obj_li) {
|
||||
// obj_li.forEach(async function (obj: any) {
|
||||
if (log_lvl) {
|
||||
console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||
}
|
||||
// for (const obj of obj_li) {
|
||||
// // obj_li.forEach(async function (obj: any) {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||
// }
|
||||
|
||||
let description = obj.description ?? '';
|
||||
// remove the most common zerowidth characters from the start of the file
|
||||
let description_cleaned: string = description.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,"");
|
||||
let description_md_html: null|string = await marked.parse(description_cleaned ?? '') ?? null;
|
||||
// let description_md_html_alt: null|string = await marked.parse(description_cleaned ?? '', { gfm: false }) ?? null;
|
||||
// let description = obj.description ?? '';
|
||||
// // remove the most common zerowidth characters from the start of the file
|
||||
// let description_cleaned: string = description.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,"");
|
||||
// let description_md_html: null|string = await marked.parse(description_cleaned ?? '') ?? null;
|
||||
// // let description_md_html_alt: null|string = await marked.parse(description_cleaned ?? '', { gfm: false }) ?? null;
|
||||
|
||||
let obj_record = {
|
||||
id: obj.journal_id_random,
|
||||
journal_id: obj.journal_id_random,
|
||||
// let obj_record = {
|
||||
// id: obj.journal_id_random,
|
||||
// journal_id: obj.journal_id_random,
|
||||
|
||||
code: obj.code,
|
||||
// code: obj.code,
|
||||
|
||||
for_type: obj.for_type,
|
||||
for_id: obj.for_id,
|
||||
// for_type: obj.for_type,
|
||||
// for_id: obj.for_id,
|
||||
|
||||
type_code: obj.type_code,
|
||||
// type_code: obj.type_code,
|
||||
|
||||
account_id: obj.account_id_random,
|
||||
person_id: obj.person_id_random,
|
||||
// account_id: obj.account_id_random,
|
||||
// person_id: obj.person_id_random,
|
||||
|
||||
name: obj.name,
|
||||
short_name: obj.short_name,
|
||||
summary: obj.summary,
|
||||
outline: obj.outline,
|
||||
// name: obj.name,
|
||||
// short_name: obj.short_name,
|
||||
// summary: obj.summary,
|
||||
// outline: obj.outline,
|
||||
|
||||
description: obj.description,
|
||||
description_md_html: description_md_html, // Use the markdown parser to generate HTML
|
||||
description_html: obj.description_html,
|
||||
description_json: obj.description_json,
|
||||
// description: obj.description,
|
||||
// description_md_html: description_md_html, // Use the markdown parser to generate HTML
|
||||
// description_html: obj.description_html,
|
||||
// description_json: obj.description_json,
|
||||
|
||||
// start_datetime: obj.start_datetime,
|
||||
// end_datetime: obj.end_datetime,
|
||||
timezone: obj.timezone,
|
||||
// // start_datetime: obj.start_datetime,
|
||||
// // end_datetime: obj.end_datetime,
|
||||
// timezone: obj.timezone,
|
||||
|
||||
alert: obj.alert,
|
||||
alert_msg: obj.alert_msg,
|
||||
// alert: obj.alert,
|
||||
// alert_msg: obj.alert_msg,
|
||||
|
||||
sort_by: obj.sort_by,
|
||||
sort_by_desc: obj.sort_by_desc,
|
||||
// sort_by: obj.sort_by,
|
||||
// sort_by_desc: obj.sort_by_desc,
|
||||
|
||||
cfg_json: obj.cfg_json ?? {},
|
||||
// cfg_json: obj.cfg_json ?? {},
|
||||
|
||||
data_json: obj.data_json ?? {},
|
||||
// data_json: obj.data_json ?? {},
|
||||
|
||||
// ux_mode: obj.ux_mode,
|
||||
// // ux_mode: obj.ux_mode,
|
||||
|
||||
// This only allows for basic access to the data.
|
||||
passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
|
||||
passcode_read_expire: obj.passcode_read_expire,
|
||||
passcode_write: obj.passcode_write,
|
||||
passcode_write_expire: obj.passcode_write_expire,
|
||||
// // This only allows for basic access to the data.
|
||||
// passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
|
||||
// passcode_read_expire: obj.passcode_read_expire,
|
||||
// passcode_write: obj.passcode_write,
|
||||
// passcode_write_expire: obj.passcode_write_expire,
|
||||
|
||||
passcode: obj.passcode, // For Journal Entry encryption password
|
||||
passcode_timeout: obj.passcode_timeout,
|
||||
// passcode: obj.passcode, // For Journal Entry encryption password
|
||||
// passcode_timeout: obj.passcode_timeout,
|
||||
|
||||
private_passcode: obj.private_passcode, // Combine with Journal passcode to encrypt and decrypt Entries
|
||||
// private_passcode: obj.private_passcode, // Combine with Journal passcode to encrypt and decrypt Entries
|
||||
|
||||
auth_key: obj.auth_key, // For Journal authorization without sign in
|
||||
// auth_key: obj.auth_key, // For Journal authorization without sign in
|
||||
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
group: obj.group,
|
||||
notes: obj.notes,
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
// enable: obj.enable,
|
||||
// hide: obj.hide,
|
||||
// priority: obj.priority,
|
||||
// sort: obj.sort,
|
||||
// group: obj.group,
|
||||
// notes: obj.notes,
|
||||
// created_on: obj.created_on,
|
||||
// updated_on: obj.updated_on,
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
tmp_sort_1: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on}_${obj.created_on}`,
|
||||
tmp_sort_2: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on ?? obj.created_on}`,
|
||||
tmp_sort_3: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.name}_${obj.updated_on ?? obj.created_on}`,
|
||||
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
// // Generated fields for sorting locally only
|
||||
// tmp_sort_1: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on}_${obj.created_on}`,
|
||||
// tmp_sort_2: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on ?? obj.created_on}`,
|
||||
// tmp_sort_3: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.name}_${obj.updated_on ?? obj.created_on}`,
|
||||
// // tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// // tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
combined_passcode: `${obj.passcode}:${obj.private_passcode ?? ''}`, // Combined Journal passcode and Journal private passcode to encrypt and decrypt Entries
|
||||
// combined_passcode: `${obj.passcode}:${obj.private_passcode ?? ''}`, // Combined Journal passcode and Journal private passcode to encrypt and decrypt Entries
|
||||
|
||||
// From SQL view
|
||||
journal_entry_count: obj.journal_entry_count,
|
||||
// // From SQL view
|
||||
// journal_entry_count: obj.journal_entry_count,
|
||||
|
||||
// A key value list of the others
|
||||
// journal_other_kv: obj.journal_other_kv,
|
||||
// journal_other_li: obj.journal_other_li,
|
||||
};
|
||||
// // A key value list of the others
|
||||
// // journal_other_kv: obj.journal_other_kv,
|
||||
// // journal_other_li: obj.journal_other_li,
|
||||
// };
|
||||
|
||||
let id_random = null;
|
||||
// let id_random = null;
|
||||
|
||||
try {
|
||||
id_random = await db_journals.journal.update(obj_record.id, obj_record);
|
||||
} catch (error) {
|
||||
console.log(`Error: Failed to update ${obj_record.id}: ${error}`);
|
||||
}
|
||||
if (!id_random) {
|
||||
if (log_lvl) {
|
||||
console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
|
||||
}
|
||||
try {
|
||||
id_random = await db_journals.journal.put(obj_record);
|
||||
} catch (error) {
|
||||
console.log(`Error: Failed to put ${obj.journal_id_random}: ${error}`);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(`Updated record with ID: ${obj_record.id}`);
|
||||
}
|
||||
}
|
||||
if (!id_random) {
|
||||
console.log(`Failed to save record with ID: ${obj_record.id}`);
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(`Saved record with ID: ${obj_record.id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// id_random = await db_journals.journal.update(obj_record.id, obj_record);
|
||||
// } catch (error) {
|
||||
// console.log(`Error: Failed to update ${obj_record.id}: ${error}`);
|
||||
// }
|
||||
// if (!id_random) {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
|
||||
// }
|
||||
// try {
|
||||
// id_random = await db_journals.journal.put(obj_record);
|
||||
// } catch (error) {
|
||||
// console.log(`Error: Failed to put ${obj.journal_id_random}: ${error}`);
|
||||
// }
|
||||
// } else {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Updated record with ID: ${obj_record.id}`);
|
||||
// }
|
||||
// }
|
||||
// if (!id_random) {
|
||||
// console.log(`Failed to save record with ID: ${obj_record.id}`);
|
||||
// } else {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Saved record with ID: ${obj_record.id}`);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return obj_li_id;
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log('No objects to save.');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
// return obj_li_id;
|
||||
// } else {
|
||||
// if (log_lvl) {
|
||||
// console.log('No objects to save.');
|
||||
// }
|
||||
// return [];
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// Updated 2025-05-09
|
||||
|
||||
@@ -64,6 +64,7 @@ export async function load_ae_obj_id__journal_entry(
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__journal_entry({
|
||||
// obj_type: 'journal_entry',
|
||||
@@ -168,6 +169,7 @@ export async function load_ae_obj_li__journal_entry(
|
||||
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_li_get_result,
|
||||
@@ -255,6 +257,7 @@ export async function create_ae_obj__journal_entry(
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// await db_save_ae_obj_li__journal_entry(
|
||||
// {
|
||||
// obj_type: 'journal_entry',
|
||||
@@ -450,6 +453,7 @@ export async function update_ae_obj__journal_entry(
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
|
||||
// await db_save_ae_obj_li__journal_entry({
|
||||
// obj_type: 'journal_entry',
|
||||
// obj_li: [result],
|
||||
@@ -745,7 +749,7 @@ let properties_to_save = [
|
||||
// Generated fields for sorting locally only
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2',
|
||||
// 'tmp_sort_3',
|
||||
'tmp_sort_3',
|
||||
// 'tmp_sort_a',
|
||||
// 'tmp_sort_b',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user