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