More updates related to replacing the forEach loop with the for loop. Async... await...
This commit is contained in:
@@ -519,114 +519,133 @@ export async function db_save_ae_obj_li__event(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** db_save_ae_obj_li__event() ***`);
|
console.log(`*** db_save_ae_obj_li__event() *** 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) {
|
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`ae_obj ${obj_type}:`, obj);
|
console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let obj_record = {
|
||||||
|
id: obj.event_id_random,
|
||||||
|
event_id: obj.event_id_random,
|
||||||
|
event_id_random: obj.event_id_random,
|
||||||
|
|
||||||
|
code: obj.event_code,
|
||||||
|
|
||||||
|
account_id: obj.account_id_random,
|
||||||
|
account_id_random: obj.account_id_random,
|
||||||
|
|
||||||
|
conference: obj.conference,
|
||||||
|
type: obj.type,
|
||||||
|
name: obj.name,
|
||||||
|
summary: obj.summary,
|
||||||
|
description: obj.description,
|
||||||
|
|
||||||
|
start_datetime: obj.start_datetime,
|
||||||
|
end_datetime: obj.end_datetime,
|
||||||
|
timezone: obj.timezone,
|
||||||
|
location_address_json: obj.location_address_json,
|
||||||
|
location_text: obj.location_text,
|
||||||
|
|
||||||
|
attend_json: obj.attend_json,
|
||||||
|
attend_text: obj.attend_text,
|
||||||
|
|
||||||
|
status: obj.status, // draft, active, inactive, archived, unknown; currently only used with IDAA
|
||||||
|
// review: obj.review,
|
||||||
|
// approve: obj.approve,
|
||||||
|
// ready: obj.ready,
|
||||||
|
// ready_on: obj.ready_on,
|
||||||
|
// archive: obj.archive,
|
||||||
|
// archive_on: obj.archive_on,
|
||||||
|
|
||||||
|
mod_abstracts_json: obj.mod_abstracts_json,
|
||||||
|
mod_badges_json: obj.mod_badges_json,
|
||||||
|
mod_exhibits_json: obj.mod_exhibits_json,
|
||||||
|
mod_pres_mgmt_json: obj.mod_pres_mgmt_json,
|
||||||
|
cfg_json: obj.cfg_json,
|
||||||
|
|
||||||
|
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,
|
||||||
|
|
||||||
|
// IDAA Recovery Meetings:
|
||||||
|
// Currently only really used for IDAA
|
||||||
|
contact_li_json: obj.contact_li_json,
|
||||||
|
external_person_id: obj.external_person_id,
|
||||||
|
|
||||||
|
physical: obj.physical,
|
||||||
|
virtual: obj.virtual,
|
||||||
|
|
||||||
|
recurring: obj.recurring,
|
||||||
|
recurring_pattern: obj.recurring_pattern,
|
||||||
|
recurring_start_time: obj.recurring_start_time,
|
||||||
|
recurring_end_time: obj.recurring_end_time,
|
||||||
|
recurring_text: obj.recurring_text,
|
||||||
|
|
||||||
|
weekday_sunday: obj.weekday_sunday,
|
||||||
|
weekday_monday: obj.weekday_monday,
|
||||||
|
weekday_tuesday: obj.weekday_tuesday,
|
||||||
|
weekday_wednesday: obj.weekday_wednesday,
|
||||||
|
weekday_thursday: obj.weekday_thursday,
|
||||||
|
weekday_friday: obj.weekday_friday,
|
||||||
|
weekday_saturday: obj.weekday_saturday,
|
||||||
|
|
||||||
|
attend_url: obj.attend_url,
|
||||||
|
attend_url_text: obj.attend_url_text,
|
||||||
|
attend_url_passcode: obj.attend_url_passcode,
|
||||||
|
attend_phone: obj.attend_phone,
|
||||||
|
attend_phone_passcode: obj.attend_phone_passcode,
|
||||||
|
|
||||||
|
// From SQL view
|
||||||
|
file_count: obj.file_count,
|
||||||
|
file_count_all: obj.file_count_all,
|
||||||
|
internal_use_count: obj.internal_use_count,
|
||||||
|
event_file_id_li_json: obj.event_file_id_li_json,
|
||||||
|
};
|
||||||
|
|
||||||
|
let id_random = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const id_random = await db_events.events.put({
|
id_random = await db_events.events.update(obj_record.id, obj_record);
|
||||||
id: obj.event_id_random,
|
|
||||||
// id_random: obj.event_id_random,
|
|
||||||
event_id: obj.event_id_random,
|
|
||||||
event_id_random: obj.event_id_random,
|
|
||||||
|
|
||||||
code: obj.event_code,
|
|
||||||
|
|
||||||
account_id: obj.account_id_random,
|
|
||||||
account_id_random: obj.account_id_random,
|
|
||||||
|
|
||||||
conference: obj.conference,
|
|
||||||
type: obj.type,
|
|
||||||
name: obj.name,
|
|
||||||
summary: obj.summary,
|
|
||||||
description: obj.description,
|
|
||||||
|
|
||||||
start_datetime: obj.start_datetime,
|
|
||||||
end_datetime: obj.end_datetime,
|
|
||||||
timezone: obj.timezone,
|
|
||||||
location_address_json: obj.location_address_json,
|
|
||||||
location_text: obj.location_text,
|
|
||||||
|
|
||||||
attend_json: obj.attend_json,
|
|
||||||
attend_text: obj.attend_text,
|
|
||||||
|
|
||||||
status: obj.status, // draft, active, inactive, archived, unknown; currently only used with IDAA
|
|
||||||
// review: obj.review,
|
|
||||||
// approve: obj.approve,
|
|
||||||
// ready: obj.ready,
|
|
||||||
// ready_on: obj.ready_on,
|
|
||||||
// archive: obj.archive,
|
|
||||||
// archive_on: obj.archive_on,
|
|
||||||
|
|
||||||
mod_abstracts_json: obj.mod_abstracts_json,
|
|
||||||
mod_badges_json: obj.mod_badges_json,
|
|
||||||
mod_exhibits_json: obj.mod_exhibits_json,
|
|
||||||
mod_pres_mgmt_json: obj.mod_pres_mgmt_json,
|
|
||||||
cfg_json: obj.cfg_json,
|
|
||||||
|
|
||||||
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,
|
|
||||||
|
|
||||||
// IDAA Recovery Meetings:
|
|
||||||
// Currently only really used for IDAA
|
|
||||||
contact_li_json: obj.contact_li_json,
|
|
||||||
external_person_id: obj.external_person_id,
|
|
||||||
|
|
||||||
physical: obj.physical,
|
|
||||||
virtual: obj.virtual,
|
|
||||||
|
|
||||||
recurring: obj.recurring,
|
|
||||||
recurring_pattern: obj.recurring_pattern,
|
|
||||||
recurring_start_time: obj.recurring_start_time,
|
|
||||||
recurring_end_time: obj.recurring_end_time,
|
|
||||||
recurring_text: obj.recurring_text,
|
|
||||||
|
|
||||||
weekday_sunday: obj.weekday_sunday,
|
|
||||||
weekday_monday: obj.weekday_monday,
|
|
||||||
weekday_tuesday: obj.weekday_tuesday,
|
|
||||||
weekday_wednesday: obj.weekday_wednesday,
|
|
||||||
weekday_thursday: obj.weekday_thursday,
|
|
||||||
weekday_friday: obj.weekday_friday,
|
|
||||||
weekday_saturday: obj.weekday_saturday,
|
|
||||||
|
|
||||||
attend_url: obj.attend_url,
|
|
||||||
attend_url_text: obj.attend_url_text,
|
|
||||||
attend_url_passcode: obj.attend_url_passcode,
|
|
||||||
attend_phone: obj.attend_phone,
|
|
||||||
attend_phone_passcode: obj.attend_phone_passcode,
|
|
||||||
|
|
||||||
// From SQL view
|
|
||||||
file_count: obj.file_count,
|
|
||||||
file_count_all: obj.file_count_all,
|
|
||||||
internal_use_count: obj.internal_use_count,
|
|
||||||
event_file_id_li_json: obj.event_file_id_li_json,
|
|
||||||
});
|
|
||||||
// console.log(`Put obj with ID: ${obj.event_id_random} or ${id_random}`);
|
|
||||||
|
|
||||||
// obj_li_id.push(obj_record.id);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let status = `Failed to put ${obj.event_id_random}: ${error}`;
|
console.error(`Error: Failed to update ${obj_record.id}: ${error}`);
|
||||||
console.log(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// const id_random = await db_events.events.put(obj);
|
if (!id_random) {
|
||||||
// console.log(`Put obj with ID: ${obj.event_id_random}`);
|
if (log_lvl) {
|
||||||
}
|
console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
id_random = await db_events.events.put(obj_record);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error: Failed to put ${obj.event_id_random}: ${error}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log(`Updated record with ID: ${obj_record.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
if (!id_random) {
|
||||||
|
console.error(`Failed to save record with ID: ${obj_record.id}`);
|
||||||
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log(`Saved record with ID: ${obj_record.id}`);
|
||||||
|
}
|
||||||
|
obj_li_id.push(obj_record.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj_li_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -778,7 +778,8 @@ export async function search__event_session(
|
|||||||
|
|
||||||
|
|
||||||
// This function will loop through the event_session_obj_li and save each one to the DB.
|
// This function will loop through the event_session_obj_li and save each one to the DB.
|
||||||
export function db_save_ae_obj_li__event_session(
|
// Updated 2025-05-09
|
||||||
|
export async function db_save_ae_obj_li__event_session(
|
||||||
{
|
{
|
||||||
obj_type,
|
obj_type,
|
||||||
obj_li,
|
obj_li,
|
||||||
@@ -790,98 +791,128 @@ export function db_save_ae_obj_li__event_session(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** db_save_ae_obj_li__event_session() ***`);
|
console.log(`*** db_save_ae_obj_li__event_session() *** obj_type=${obj_type}`, obj_li);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj_li && obj_li.length) {
|
if (obj_li && obj_li.length) {
|
||||||
obj_li.forEach(async function (obj: any) {
|
let obj_li_id: string[] = [];
|
||||||
|
|
||||||
|
for (const obj of obj_li) {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`ae_obj ${obj_type}:`, obj);
|
console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let obj_record = {
|
||||||
|
id: obj.event_session_id_random,
|
||||||
|
event_session_id: obj.event_session_id_random,
|
||||||
|
event_session_id_random: obj.event_session_id_random,
|
||||||
|
|
||||||
|
external_id: obj.external_id,
|
||||||
|
code: obj.code,
|
||||||
|
|
||||||
|
for_type: obj.for_type,
|
||||||
|
for_id: obj.for_id_id_random,
|
||||||
|
for_id_random: obj.for_id_random,
|
||||||
|
|
||||||
|
type_code: obj.type_code,
|
||||||
|
|
||||||
|
event_id: obj.event_id_random,
|
||||||
|
event_id_random: obj.event_id_random,
|
||||||
|
event_location_id: obj.event_location_id_random,
|
||||||
|
event_location_id_random: obj.event_location_id_random,
|
||||||
|
|
||||||
|
poc_person_id: obj.poc_person_id_random,
|
||||||
|
poc_person_id_random: obj.poc_person_id_random,
|
||||||
|
poc_agree: obj.poc_agree,
|
||||||
|
poc_kv_json: obj.poc_kv_json ?? {},
|
||||||
|
|
||||||
|
name: obj.name,
|
||||||
|
description: obj.description,
|
||||||
|
|
||||||
|
start_datetime: obj.start_datetime,
|
||||||
|
end_datetime: obj.end_datetime,
|
||||||
|
|
||||||
|
passcode: obj.passcode,
|
||||||
|
|
||||||
|
hide_event_launcher: obj.hide_event_launcher,
|
||||||
|
|
||||||
|
alert: obj.alert,
|
||||||
|
alert_msg: obj.alert_msg,
|
||||||
|
|
||||||
|
data_json: obj.data_json,
|
||||||
|
|
||||||
|
ux_mode: obj.ux_mode,
|
||||||
|
|
||||||
|
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,
|
||||||
|
|
||||||
|
// From SQL view
|
||||||
|
file_count: obj.file_count,
|
||||||
|
file_count_all: obj.file_count_all,
|
||||||
|
internal_use_count: obj.internal_use_count,
|
||||||
|
event_file_id_li_json: obj.event_file_id_li_json,
|
||||||
|
|
||||||
|
poc_person_given_name: obj.poc_person_given_name,
|
||||||
|
poc_person_family_name: obj.poc_person_family_name,
|
||||||
|
poc_person_full_name: obj.poc_person_full_name,
|
||||||
|
poc_person_primary_email: obj.poc_person_primary_email,
|
||||||
|
poc_person_passcode: obj.poc_person_passcode,
|
||||||
|
|
||||||
|
event_name: obj.event_name,
|
||||||
|
|
||||||
|
event_location_code: obj.event_location_code,
|
||||||
|
event_location_name: obj.event_location_name,
|
||||||
|
|
||||||
|
// A key value list of the presentations
|
||||||
|
event_presentation_kv: obj.event_presentation_kv,
|
||||||
|
event_presentation_li: obj.event_presentation_li,
|
||||||
|
};
|
||||||
|
|
||||||
|
let id_random = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const id_random = await db_events.sessions.put({
|
id_random = await db_events.event_sessions.update(obj_record.id, obj_record);
|
||||||
id: obj.event_session_id_random,
|
|
||||||
event_session_id: obj.event_session_id_random,
|
|
||||||
event_session_id_random: obj.event_session_id_random,
|
|
||||||
|
|
||||||
external_id: obj.external_id,
|
|
||||||
code: obj.code,
|
|
||||||
|
|
||||||
for_type: obj.for_type,
|
|
||||||
for_id: obj.for_id_id_random,
|
|
||||||
for_id_random: obj.for_id_random,
|
|
||||||
|
|
||||||
type_code: obj.type_code,
|
|
||||||
|
|
||||||
event_id: obj.event_id_random,
|
|
||||||
event_id_random: obj.event_id_random,
|
|
||||||
event_location_id: obj.event_location_id_random,
|
|
||||||
event_location_id_random: obj.event_location_id_random,
|
|
||||||
|
|
||||||
poc_person_id: obj.poc_person_id_random,
|
|
||||||
poc_person_id_random: obj.poc_person_id_random,
|
|
||||||
poc_agree: obj.poc_agree,
|
|
||||||
poc_kv_json: obj.poc_kv_json ?? {},
|
|
||||||
|
|
||||||
name: obj.name,
|
|
||||||
description: obj.description,
|
|
||||||
|
|
||||||
start_datetime: obj.start_datetime,
|
|
||||||
end_datetime: obj.end_datetime,
|
|
||||||
|
|
||||||
passcode: obj.passcode,
|
|
||||||
|
|
||||||
hide_event_launcher: obj.hide_event_launcher,
|
|
||||||
|
|
||||||
alert: obj.alert,
|
|
||||||
alert_msg: obj.alert_msg,
|
|
||||||
|
|
||||||
data_json: obj.data_json,
|
|
||||||
|
|
||||||
ux_mode: obj.ux_mode,
|
|
||||||
|
|
||||||
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,
|
|
||||||
|
|
||||||
// From SQL view
|
|
||||||
file_count: obj.file_count,
|
|
||||||
file_count_all: obj.file_count_all,
|
|
||||||
internal_use_count: obj.internal_use_count,
|
|
||||||
event_file_id_li_json: obj.event_file_id_li_json,
|
|
||||||
|
|
||||||
poc_person_given_name: obj.poc_person_given_name,
|
|
||||||
poc_person_family_name: obj.poc_person_family_name,
|
|
||||||
poc_person_full_name: obj.poc_person_full_name,
|
|
||||||
poc_person_primary_email: obj.poc_person_primary_email,
|
|
||||||
poc_person_passcode: obj.poc_person_passcode,
|
|
||||||
|
|
||||||
event_name: obj.event_name,
|
|
||||||
|
|
||||||
event_location_code: obj.event_location_code,
|
|
||||||
event_location_name: obj.event_location_name,
|
|
||||||
|
|
||||||
// A key value list of the presentations
|
|
||||||
event_presentation_kv: obj.event_presentation_kv,
|
|
||||||
event_presentation_li: obj.event_presentation_li,
|
|
||||||
});
|
|
||||||
// console.log(`Put obj with ID: ${obj.event_session_id_random} or ${id_random}`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let status = `Failed to put ${obj.event_session_id_random}: ${error}`;
|
console.error(`Error: Failed to update ${obj_record.id}: ${error}`);
|
||||||
console.log(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// const id_random = await db_events.sessions.put(obj);
|
if (!id_random) {
|
||||||
// console.log(`Put obj with ID: ${obj.event_session_id_random}`);
|
if (log_lvl) {
|
||||||
});
|
console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
id_random = await db_events.event_sessions.put(obj_record);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error: Failed to put ${obj.event_session_id_random}: ${error}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log(`Updated record with ID: ${obj_record.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
if (!id_random) {
|
||||||
|
console.error(`Failed to save record with ID: ${obj_record.id}`);
|
||||||
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log(`Saved record with ID: ${obj_record.id}`);
|
||||||
|
}
|
||||||
|
obj_li_id.push(obj_record.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj_li_id;
|
||||||
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log('No objects to save.');
|
||||||
|
}
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -544,10 +544,11 @@ export async function db_save_ae_obj_li__journal(
|
|||||||
|
|
||||||
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(`ae_obj ${obj_type}:`, obj);
|
console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
let description = obj.description ?? '';
|
let description = obj.description ?? '';
|
||||||
@@ -662,5 +663,10 @@ export async function db_save_ae_obj_li__journal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return obj_li_id;
|
return obj_li_id;
|
||||||
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log('No objects to save.');
|
||||||
|
}
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -397,10 +397,11 @@ export async function db_save_ae_obj_li__journal_entry(
|
|||||||
if (obj_li && obj_li.length) {
|
if (obj_li && obj_li.length) {
|
||||||
// let obj_li_id = obj_li.map((obj: any) => obj.journal_entry_id_random);
|
// let obj_li_id = obj_li.map((obj: any) => obj.journal_entry_id_random);
|
||||||
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(`ae_obj ${obj_type}:`, obj);
|
console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = obj.content ?? '';
|
let content = obj.content ?? '';
|
||||||
@@ -577,5 +578,10 @@ export async function db_save_ae_obj_li__journal_entry(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return obj_li_id;
|
return obj_li_id;
|
||||||
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log('No objects to save.');
|
||||||
|
}
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user