diff --git a/src/lib/ae_archives__archive.ts b/src/lib/ae_archives__archive.ts new file mode 100644 index 00000000..6d845133 --- /dev/null +++ b/src/lib/ae_archives__archive.ts @@ -0,0 +1,583 @@ +import type { key_val } from '$lib/ae_stores'; +import { api } from '$lib/api'; + +import { db_archives } from "$lib/db_archives"; + +import { load_ae_obj_li__archive_content } from "$lib/ae_archives__archive_content"; + +let ae_promises: key_val = {}; + + +// Updated 2024-09-25 +export async function load_ae_obj_id__archive( + { + api_cfg, + archive_id, + inc_content_li = false, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + archive_id: string, + inc_content_li?: boolean, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_id__archive() *** archive_id=${archive_id}`); + + let params = {}; + + ae_promises.load__archive_obj = await api.get_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'archive', + obj_id: archive_id, // NOTE: This is the FQDN, not normally the ID. + use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. + params: params, + log_lvl: log_lvl + }) + .then(function (archive_obj_get_result) { + if (archive_obj_get_result) { + if (try_cache) { + // This is expecting a list + db_save_ae_obj_li__archive({ + obj_type: 'archive', + obj_li: [archive_obj_get_result] + }); + } + return archive_obj_get_result; + } else { + console.log('No results returned.'); + return null; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + if (log_lvl) { + console.log('ae_promises.load__archive_obj:', ae_promises.load__archive_obj); + } + + if (inc_content_li) { + // Load the contents for the archive + if (log_lvl) { + console.log(`Need to load the content list for the archive now`); + } + let load_archive_content_obj_li = load_ae_obj_li__archive_content({ + api_cfg: api_cfg, + for_obj_type: 'archive', + for_obj_id: archive_id, + inc_content_li: inc_content_li, + params: {qry__enabled: 'all', qry__limit: 25}, + try_cache: try_cache, + log_lvl: log_lvl + }) + .then((archive_content_obj_li) => { + if (log_lvl) { + console.log(`archive_content_obj_li = `, archive_content_obj_li); + } + return archive_content_obj_li; + }); + + if (log_lvl) { + console.log(`archive_content_obj_li = `, load_archive_content_obj_li); + } + ae_promises.load__archive_obj.archive_content_li = load_archive_content_obj_li; + } + + return ae_promises.load__archive_obj; +} + + +// Updated 2024-09-25 +export async function load_ae_obj_li__archive( + { + api_cfg, + for_obj_type = 'account', + for_obj_id, + inc_content_li = false, + order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + for_obj_type: string, + for_obj_id: string, + inc_content_li?: boolean, + order_by_li?: key_val, + params?: key_val, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_li__archive() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`); + + let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled + let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden + let limit: number = (params.qry__limit ?? 99); // 99 + let offset: number = (params.qry__offset ?? 0); // 0 + + let params_json: key_val = {}; + + // console.log('params_json:', params_json); + + ae_promises.load__archive_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'archive', + for_obj_type: for_obj_type, + for_obj_id: for_obj_id, + use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + enabled: enabled, + hidden: hidden, + order_by_li: order_by_li, + limit: limit, + offset: offset, + params_json: params_json, + params: params, + log_lvl: log_lvl + }) + .then(function (archive_obj_li_get_result) { + if (archive_obj_li_get_result) { + if (try_cache) { + db_save_ae_obj_li__archive({ + obj_type: 'archive', + obj_li: archive_obj_li_get_result + }); + } + return archive_obj_li_get_result; + } else { + return []; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + if (log_lvl) { + console.log('ae_promises.load__archive_obj_li:', ae_promises.load__archive_obj_li); + } + + if (inc_content_li) { + // Load the contents for the archives + if (log_lvl) { + console.log(`Need to load the content list for each archive now`); + } + for (let i = 0; i < ae_promises.load__archive_obj_li.length; i++) { + let archive_obj = ae_promises.load__archive_obj_li[i]; + let archive_id = archive_obj.archive_id_random; + + let load_archive_content_obj_li = load_ae_obj_li__archive_content({ + api_cfg: api_cfg, + for_obj_type: 'archive', + for_obj_id: archive_id, + params: {qry__enabled: enabled, qry__limit: limit}, + try_cache: try_cache, + log_lvl: log_lvl + }) + .then((archive_content_obj_li) => { + if (log_lvl) { + console.log(`archive_content_obj_li = `, archive_content_obj_li); + } + + return archive_content_obj_li; + }); + + if (log_lvl) { + console.log(`load_archive_content_obj_li = `, load_archive_content_obj_li); + } + } + } + + return ae_promises.load__archive_obj_li; +} + + +// Updated 2024-09-25 +export async function update_ae_obj__archive( + { + api_cfg, + archive_id, + data_kv, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + archive_id: string, + data_kv: key_val, + params?: key_val, + try_cache?: boolean, + log_lvl?: number + } + ) { + if (log_lvl) { + console.log(`*** update_ae_obj__archive() *** archive_id=${archive_id}`, data_kv); + } + ae_promises.update__archive_obj = await api.update_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'archive', + obj_id: archive_id, // NOTE: This is the FQDN, not normally the ID. + fields: data_kv, + key: api_cfg.api_crud_super_key, + params: params, + return_obj: true, + log_lvl: log_lvl + }) + .then(function (archive_obj_update_result) { + if (archive_obj_update_result) { + if (try_cache) { + db_save_ae_obj_li__archive({ + obj_type: 'archive', obj_li: [archive_obj_update_result] + }); + } + return archive_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__archive_obj:', ae_promises.update__archive_obj); + } + return ae_promises.update__archive_obj; +} + + +// This new function is using CRUD v2. This should allow for more flexibility in the queries. +// Updated 2024-09-25 +export async function qry__archive( + { + api_cfg, + archive_id, + qry_str, + qry_files, + qry_start_datetime, // Example greater than: '2024-10-24' + enabled = 'enabled', + hidden = 'not_hidden', + limit = 50, + offset = 0, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + archive_id: any, + qry_str?: string, + qry_files?: null|boolean, + qry_start_datetime?: null|string, // Greater than this datetime + enabled?: string, // all, disabled, enabled + hidden?: string, // all, hidden, not_hidden + limit?: number, + offset?: number, + params?: any, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** qry__archive() *** archive_id=${archive_id} qry_str=${qry_str}`); + + // let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled + // let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden + // let limit: number = (params.qry__limit ?? 25); // 99 + // let offset: number = (params.qry__offset ?? 0); // 0 + + let params_json: key_val = {}; + + // if (qry_str && qry_str.length > 2) { + // params_json['ft_qry'] = {}; + // params_json['ft_qry']['default_qry_str'] = qry_str; + // } + + params_json['qry'] = []; + + if (qry_files === true) { + let qry_param = + { + type: "AND", + field: "file_count_all", + operator: ">", + value: 0 + }; + params_json['qry'].push(qry_param); + } else if (qry_files === false) { + let qry_param = + { + type: "AND", + field: "file_count_all", + operator: "IS", + value: null + }; + params_json['qry'].push(qry_param); + } + + if (qry_start_datetime) { + let qry_param = + { + type: "AND", + field: "start_datetime", + operator: ">", + value: qry_start_datetime + }; + params_json['qry'].push(qry_param); + } + + let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}; + + ae_promises.load__archive_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({ + api_cfg: api_cfg, + obj_type: 'archive', + for_obj_type: 'event', + for_obj_id: archive_id, + use_alt_tbl: true, // NOTE: We want to use the alt table for archive searching + use_alt_mdl: false, + use_alt_exp: false, + enabled: enabled, + hidden: hidden, + order_by_li: order_by_li, + limit: limit, + offset: offset, + params_json: params_json, + params: params, + log_lvl: log_lvl + }) + .then(function (archive_obj_li_get_result) { + if (archive_obj_li_get_result) { + db_save_ae_obj_li__archive({ + obj_type: 'archive', + obj_li: archive_obj_li_get_result + }); + return archive_obj_li_get_result; + } else { + return []; + } + }); + + if (log_lvl) { + console.log('ae_promises.load__archive_obj_li:', ae_promises.load__archive_obj_li); + } + return ae_promises.load__archive_obj_li; +} + + +// Updated 2024-09-25 +export async function search__archive( + { + api_cfg, + account_id, + poc_agree = null, + fulltext_search_qry_str, + ft_content_search_qry_str, + like_search_qry_str = null, + file_count = false, // If true then only show those that have a file count + person_name = null, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + account_id: any, + poc_agree?: null|boolean, + fulltext_search_qry_str?: null|string, + ft_content_search_qry_str?: null|string, + like_search_qry_str?: null|string, + file_count?: boolean, + person_name?: null|string, + params?: any, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** search__archive() *** account_id=${account_id}`); + + let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled + let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden + let limit: number = (params.qry__limit ?? 25); // 99 + let offset: number = (params.qry__offset ?? 0); // 0 + + let params_json: key_val = {}; + + // if (!fulltext_search_qry_str && !like_search_qry_str) { + // console.log('No search string provided!!!'); + // return false; // Returning false instead of [] because no search was performed. + // } + + if (fulltext_search_qry_str || ft_content_search_qry_str) { + params_json['ft_qry'] = {}; + if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { + params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str; + } + + if (ft_content_search_qry_str && ft_content_search_qry_str.length > 2) { + params_json['ft_qry']['archive_content_li_qry_str'] = ft_content_search_qry_str; + } + } + + // Use the AND (AND LIKE) query + // if (like_search_qry_str || like_content_search_qry_str) { + // params_json['and_like'] = {}; + // if (like_search_qry_str && like_search_qry_str.length > 2) { + // params_json['and_like']['default_qry_str'] = like_search_qry_str; + // } + // if (like_content_search_qry_str && like_content_search_qry_str.length > 2) { + // params_json['and_like']['archive_content_li_qry_str'] = like_content_search_qry_str; + // } + // } + + // Use the AND (OR LIKE) query + if (like_search_qry_str || like_content_search_qry_str || like_content_search_qry_str) { + params_json['or_like'] = {}; + if (like_search_qry_str && like_search_qry_str.length > 2) { + params_json['or_like']['default_qry_str'] = like_search_qry_str; + } + if (like_content_search_qry_str && like_content_search_qry_str.length > 2) { + params_json['or_like']['archive_content_li_qry_str'] = like_content_search_qry_str; + } + if (like_content_search_qry_str && like_content_search_qry_str.length > 2) { + params_json['or_like']['archive_content_li_qry_str'] = like_content_search_qry_str; + } + } + + params_json['and_qry'] = {}; + + if (poc_agree) { + params_json['and_qry']['poc_agree'] = poc_agree; + } + + if (file_count) { + params_json['and_qry']['file_count'] = file_count; + } + + // This should be using a like with surrounded by %'s + if (person_name) { + params_json['and_qry']['archive_full_name'] = person_name; + } + + let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}; + + ae_promises.load__archive_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'archive', + for_obj_type: 'account', + for_obj_id: account_id, + use_alt_table: true, // NOTE: We want to use the alt table for archive searching + use_alt_base: false, + enabled: enabled, + hidden: hidden, + order_by_li: order_by_li, + limit: limit, + offset: offset, + params_json: params_json, + params: params, + log_lvl: log_lvl + }) + .then(function (archive_obj_li_get_result) { + if (archive_obj_li_get_result) { + if (try_cache) { + db_save_ae_obj_li__archive({ + obj_type: 'archive', + obj_li: archive_obj_li_get_result + }); + } + return archive_obj_li_get_result; + } else { + return []; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }) + .finally(function () { + }); + + if (log_lvl) { + console.log('ae_promises.load__archive_obj_li:', ae_promises.load__archive_obj_li); + } + return ae_promises.load__archive_obj_li; +} + + +// This function will loop through the archive_obj_li and save each one to the DB. +// Updated 2024-09-25 +export function db_save_ae_obj_li__archive( + { + 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__archive() ***`); + } + + if (obj_li && obj_li.length) { + obj_li.forEach(async function (obj: any) { + if (log_lvl) { + console.log(`ae_obj ${obj_type}:`, obj); + } + + try { + const id_random = await db_archives.archive.put({ + id: obj.archive_id_random, + archive_id: obj.archive_id_random, + + code: obj.code, + + account_id: obj.account_id_random, + + name: obj.name, + description: obj.description, + + original_datetime: obj.original_datetime, + original_timezone: obj.original_timezone, + original_location: obj.original_location, + + original_url: obj.original_url, + original_url_text: obj.original_url_text, + + sort_by: obj.sort_by, + sort_by_desc: obj.sort_by_desc, + + 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, + + // From SQL view + // archive_content_count: obj.archive_content_count, + + // A key value list of the contents + // archive_content_kv: obj.archive_content_kv, + // archive_content_li: obj.archive_content_li, + }); + // console.log(`Put obj with ID: ${obj.archive_id_random} or ${id_random}`); + } catch (error) { + let status = `Failed to put ${obj.archive_id_random}: ${error}`; + console.log(status); + } + + // const id_random = await db_archives.archive.put(obj); + // console.log(`Put obj with ID: ${obj.archive_id_random}`); + }); + + return true; + } +} diff --git a/src/lib/ae_archives__archive_content.ts b/src/lib/ae_archives__archive_content.ts new file mode 100644 index 00000000..95ec8eb8 --- /dev/null +++ b/src/lib/ae_archives__archive_content.ts @@ -0,0 +1,269 @@ +import type { key_val } from '$lib/ae_stores'; +import { api } from '$lib/api'; + +import { db_archives } from "$lib/db_archives"; + +let ae_promises: key_val = {}; + + +// Updated 2024-09-25 +export async function load_ae_obj_id__archive_content( + { + api_cfg, + archive_content_id, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + archive_content_id: string, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_id__archive_content() *** archive_content_id=${archive_content_id}`); + + let params = {}; + + ae_promises.load__archive_content_obj = await api.get_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'archive_content', + obj_id: archive_content_id, // NOTE: This is the FQDN, not normally the ID. + use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + params: params, + log_lvl: log_lvl + }) + .then(function (archive_content_obj_get_result) { + if (archive_content_obj_get_result) { + if (try_cache) { + // This is expecting a list + db_save_ae_obj_li__archive_content({ + obj_type: 'archive_content', + obj_li: [archive_content_obj_get_result] + + }); + } + return archive_content_obj_get_result; + } else { + console.log('No results returned.'); + return null; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + return ae_promises.load__archive_content_obj; +} + + +// Updated 2024-09-25 +export async function load_ae_obj_li__archive_content( + { + api_cfg, + for_obj_type = 'archive', + for_obj_id, + order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + for_obj_type: string, + for_obj_id: string, + order_by_li?: key_val, + params?: key_val, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_li__archive_content() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`); + + let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled + let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden + let limit: number = (params.qry__limit ?? 99); // 99 + let offset: number = (params.qry__offset ?? 0); // 0 + + let params_json: key_val = {}; + + // console('params_json:', params_json); + + ae_promises.load__archive_content_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'archive_content', + for_obj_type: for_obj_type, + for_obj_id: for_obj_id, + use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + enabled: enabled, + hidden: hidden, + order_by_li: order_by_li, + limit: limit, + offset: offset, + params_json: params_json, + params: params, + log_lvl: log_lvl + }) + .then(function (archive_content_obj_li_get_result) { + if (archive_content_obj_li_get_result) { + if (try_cache) { + db_save_ae_obj_li__archive_content({ + obj_type: 'archive_content', obj_li: archive_content_obj_li_get_result + }); + } + return archive_content_obj_li_get_result; + } else { + return []; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + if (log_lvl) { + console.log('ae_promises.load__archive_content_obj_li:', ae_promises.load__archive_content_obj_li); + } + + return ae_promises.load__archive_content_obj_li; +} + + +// Updated 2024-09-25 +export async function create_ae_obj__archive_content( + { + api_cfg, + archive_id, + data_kv, + params={}, + log_lvl=0 + }: { + api_cfg: any, + archive_id: string, + data_kv: key_val, + params?: key_val, + log_lvl?: number + } + ) { + console.log(`*** create_ae_obj__archive_content() *** archive_id=${archive_id}`); + + ae_promises.create__archive_content = await api.create_ae_obj_crud({ + api_cfg: api_cfg, + obj_type: 'archive_content', + fields: { + archive_id_random: archive_id, + ...data_kv + }, + key: api_cfg.api_crud_super_key, + params: params, + return_obj: true, + log_lvl: log_lvl + }) + .then(function (archive_content_obj_create_result) { + if (archive_content_obj_create_result) { + db_save_ae_obj_li__archive_content( + { + obj_type: 'archive_content', + obj_li: [archive_content_obj_create_result] + }); + return archive_content_obj_create_result; + } else { + return null; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }) + .finally(function () { + }); + + if (log_lvl) { + console.log('ae_promises.create__archive_content:', ae_promises.create__archive_content); + } + return ae_promises.create__archive_content; +} + + +// This function will loop through the archive_content_obj_li and save each one to the DB. +// Updated 2024-09-25 +export function db_save_ae_obj_li__archive_content( + { + 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__archive_content() ***`); + } + + if (obj_li && obj_li.length) { + obj_li.forEach(async function (obj: any) { + if (log_lvl) { + console.log(`ae_obj ${obj_type}:`, obj); + } + + try { + const id_random = await db_archives.content.put({ + id: obj.archive_content_id_random, + archive_content_id: obj.archive_content_id_random, + + archive_id: obj.archive_id_random, + + archive_content_type: obj.archive_content_type, + + name: obj.name, + description: obj.description, + + content_html: obj.content_html, + content_json: obj.content_json, + + url: obj.url, + url_text: obj.url_text, + + hosted_file_id: obj.hosted_file_id, + + file_path: obj.file_path, + + filename: obj.filename, + file_extension: obj.file_extension, + + original_datetime: obj.original_datetime, + original_timezone: obj.original_timezone, + original_location: obj.original_location, + original_url: obj.original_url, + original_url_text: obj.original_url_text, + + enable_for_public: obj.enable_for_public, + + 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, + + // From SQL view + archive_code: obj.archive_code, + archive_name: obj.archive_name, + }); + // console.log(`Put obj with ID: ${obj.archive_content_id_random} or ${id_random}`); + } catch (error) { + let status = `Failed to put ${obj.archive_content_id_random}: ${error}`; + console.log(status); + } + + // const id_random = await db_archives.content.put(obj); + // console.log(`Put obj with ID: ${obj.archive_content_id_random}`); + }); + + return true; + } +} diff --git a/src/lib/ae_events__event_presentation.ts b/src/lib/ae_events__event_presentation.ts index ec727a88..d3ef9a2c 100644 --- a/src/lib/ae_events__event_presentation.ts +++ b/src/lib/ae_events__event_presentation.ts @@ -19,7 +19,7 @@ export async function load_ae_obj_id__event_presentation( api_cfg: any, event_presentation_id: string, inc_file_li?: boolean, - inc_presenter_li?: boolean + inc_presenter_li?: boolean, try_cache?: boolean, log_lvl?: number } @@ -79,10 +79,11 @@ export async function load_ae_obj_id__event_presentation( export async function load_ae_obj_li__event_presentation( { api_cfg, - for_obj_type, + for_obj_type = 'event_session', for_obj_id, inc_file_li = false, inc_presenter_li = false, + order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, params = {}, try_cache = true, log_lvl = 0 @@ -91,7 +92,8 @@ export async function load_ae_obj_li__event_presentation( for_obj_type: string, for_obj_id: string, inc_file_li?: boolean, - inc_presenter_li?: boolean + inc_presenter_li?: boolean, + order_by_li?: key_val, params?: key_val, try_cache?: boolean, log_lvl?: number @@ -117,7 +119,7 @@ export async function load_ae_obj_li__event_presentation( use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value enabled: enabled, hidden: hidden, - order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, + order_by_li: order_by_li, limit: limit, offset: offset, params_json: params_json, diff --git a/src/lib/ae_events__event_presenter.ts b/src/lib/ae_events__event_presenter.ts index 2bef91f5..19b1f2fd 100644 --- a/src/lib/ae_events__event_presenter.ts +++ b/src/lib/ae_events__event_presenter.ts @@ -62,6 +62,7 @@ export async function load_ae_obj_li__event_presenter( api_cfg, for_obj_type, for_obj_id, + order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'given_name': 'ASC', 'family_name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, params={}, try_cache=true, log_lvl=0 @@ -69,6 +70,7 @@ export async function load_ae_obj_li__event_presenter( api_cfg: any, for_obj_type: string, for_obj_id: string, + order_by_li?: key_val, params?: key_val, try_cache?: boolean, log_lvl?: number @@ -96,7 +98,7 @@ export async function load_ae_obj_li__event_presenter( use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value enabled: enabled, hidden: hidden, - order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'given_name': 'ASC', 'family_name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, + order_by_li: order_by_li, limit: limit, offset: offset, params_json: params_json, diff --git a/src/lib/ae_events__event_session.ts b/src/lib/ae_events__event_session.ts index 1e49cb28..82d80bb7 100644 --- a/src/lib/ae_events__event_session.ts +++ b/src/lib/ae_events__event_session.ts @@ -220,7 +220,7 @@ export async function load_ae_obj_li__event_session( api_cfg: api_cfg, for_obj_type: 'event_session', for_obj_id: event_session_id, - params: {qry__enabled: 'all', qry__limit: 15}, + params: {qry__enabled: enabled, qry__limit: limit}, try_cache: try_cache, log_lvl: log_lvl }) @@ -252,7 +252,7 @@ export async function load_ae_obj_li__event_session( for_obj_id: event_session_id, inc_file_li: inc_file_li, inc_presenter_li: inc_presenter_li, - params: {qry__enabled: 'all', qry__limit: 25}, + params: {qry__enabled: enabled, qry__limit: limit}, try_cache: try_cache, log_lvl: log_lvl }) diff --git a/src/lib/ae_posts__post.ts b/src/lib/ae_posts__post.ts new file mode 100644 index 00000000..7164e920 --- /dev/null +++ b/src/lib/ae_posts__post.ts @@ -0,0 +1,583 @@ +import type { key_val } from '$lib/ae_stores'; +import { api } from '$lib/api'; + +import { db_posts } from "$lib/db_posts"; + +import { load_ae_obj_li__post_comment } from "$lib/ae_posts__post_comment"; + +let ae_promises: key_val = {}; + + +// Updated 2024-09-25 +export async function load_ae_obj_id__post( + { + api_cfg, + post_id, + inc_comment_li = false, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + post_id: string, + inc_comment_li?: boolean, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_id__post() *** post_id=${post_id}`); + + let params = {}; + + ae_promises.load__post_obj = await api.get_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'post', + obj_id: post_id, // NOTE: This is the FQDN, not normally the ID. + use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. + params: params, + log_lvl: log_lvl + }) + .then(function (post_obj_get_result) { + if (post_obj_get_result) { + if (try_cache) { + // This is expecting a list + db_save_ae_obj_li__post({ + obj_type: 'post', + obj_li: [post_obj_get_result] + }); + } + return post_obj_get_result; + } else { + console.log('No results returned.'); + return null; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + if (log_lvl) { + console.log('ae_promises.load__post_obj:', ae_promises.load__post_obj); + } + + if (inc_comment_li) { + // Load the comments for the post + if (log_lvl) { + console.log(`Need to load the comment list for the post now`); + } + let load_post_comment_obj_li = load_ae_obj_li__post_comment({ + api_cfg: api_cfg, + for_obj_type: 'post', + for_obj_id: post_id, + inc_comment_li: inc_comment_li, + params: {qry__enabled: 'all', qry__limit: 25}, + try_cache: try_cache, + log_lvl: log_lvl + }) + .then((post_comment_obj_li) => { + if (log_lvl) { + console.log(`post_comment_obj_li = `, post_comment_obj_li); + } + return post_comment_obj_li; + }); + + if (log_lvl) { + console.log(`post_comment_obj_li = `, load_post_comment_obj_li); + } + ae_promises.load__post_obj.post_comment_li = load_post_comment_obj_li; + } + + return ae_promises.load__post_obj; +} + + +// Updated 2024-09-25 +export async function load_ae_obj_li__post( + { + api_cfg, + for_obj_type = 'account', + for_obj_id, + inc_comment_li = false, + order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + for_obj_type: string, + for_obj_id: string, + inc_comment_li?: boolean, + order_by_li?: key_val, + params?: key_val, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_li__post() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`); + + let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled + let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden + let limit: number = (params.qry__limit ?? 99); // 99 + let offset: number = (params.qry__offset ?? 0); // 0 + + let params_json: key_val = {}; + + // console.log('params_json:', params_json); + + ae_promises.load__post_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'post', + for_obj_type: for_obj_type, + for_obj_id: for_obj_id, + use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + enabled: enabled, + hidden: hidden, + order_by_li: order_by_li, + limit: limit, + offset: offset, + params_json: params_json, + params: params, + log_lvl: log_lvl + }) + .then(function (post_obj_li_get_result) { + if (post_obj_li_get_result) { + if (try_cache) { + db_save_ae_obj_li__post({ + obj_type: 'post', + obj_li: post_obj_li_get_result + }); + } + return post_obj_li_get_result; + } else { + return []; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + if (log_lvl) { + console.log('ae_promises.load__post_obj_li:', ae_promises.load__post_obj_li); + } + + if (inc_comment_li) { + // Load the comments for the posts + if (log_lvl) { + console.log(`Need to load the comment list for each post now`); + } + for (let i = 0; i < ae_promises.load__post_obj_li.length; i++) { + let post_obj = ae_promises.load__post_obj_li[i]; + let post_id = post_obj.post_id_random; + + let load_post_comment_obj_li = load_ae_obj_li__post_comment({ + api_cfg: api_cfg, + for_obj_type: 'post', + for_obj_id: post_id, + params: {qry__enabled: enabled, qry__limit: limit}, + try_cache: try_cache, + log_lvl: log_lvl + }) + .then((post_comment_obj_li) => { + if (log_lvl) { + console.log(`post_comment_obj_li = `, post_comment_obj_li); + } + + return post_comment_obj_li; + }); + + if (log_lvl) { + console.log(`load_post_comment_obj_li = `, load_post_comment_obj_li); + } + } + } + + return ae_promises.load__post_obj_li; +} + + +// Updated 2024-09-25 +export async function update_ae_obj__post( + { + api_cfg, + post_id, + data_kv, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + post_id: string, + data_kv: key_val, + params?: key_val, + try_cache?: boolean, + log_lvl?: number + } + ) { + if (log_lvl) { + console.log(`*** update_ae_obj__post() *** post_id=${post_id}`, data_kv); + } + ae_promises.update__post_obj = await api.update_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'post', + obj_id: post_id, // NOTE: This is the FQDN, not normally the ID. + fields: data_kv, + key: api_cfg.api_crud_super_key, + params: params, + return_obj: true, + log_lvl: log_lvl + }) + .then(function (post_obj_update_result) { + if (post_obj_update_result) { + if (try_cache) { + db_save_ae_obj_li__post({ + obj_type: 'post', obj_li: [post_obj_update_result] + }); + } + return post_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__post_obj:', ae_promises.update__post_obj); + } + return ae_promises.update__post_obj; +} + + +// This new function is using CRUD v2. This should allow for more flexibility in the queries. +// Updated 2024-09-25 +export async function qry__post( + { + api_cfg, + post_id, + qry_str, + qry_files, + qry_start_datetime, // Example greater than: '2024-10-24' + enabled = 'enabled', + hidden = 'not_hidden', + limit = 50, + offset = 0, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + post_id: any, + qry_str?: string, + qry_files?: null|boolean, + qry_start_datetime?: null|string, // Greater than this datetime + enabled?: string, // all, disabled, enabled + hidden?: string, // all, hidden, not_hidden + limit?: number, + offset?: number, + params?: any, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** qry__post() *** post_id=${post_id} qry_str=${qry_str}`); + + // let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled + // let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden + // let limit: number = (params.qry__limit ?? 25); // 99 + // let offset: number = (params.qry__offset ?? 0); // 0 + + let params_json: key_val = {}; + + // if (qry_str && qry_str.length > 2) { + // params_json['ft_qry'] = {}; + // params_json['ft_qry']['default_qry_str'] = qry_str; + // } + + params_json['qry'] = []; + + if (qry_files === true) { + let qry_param = + { + type: "AND", + field: "file_count_all", + operator: ">", + value: 0 + }; + params_json['qry'].push(qry_param); + } else if (qry_files === false) { + let qry_param = + { + type: "AND", + field: "file_count_all", + operator: "IS", + value: null + }; + params_json['qry'].push(qry_param); + } + + if (qry_start_datetime) { + let qry_param = + { + type: "AND", + field: "start_datetime", + operator: ">", + value: qry_start_datetime + }; + params_json['qry'].push(qry_param); + } + + let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}; + + ae_promises.load__post_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({ + api_cfg: api_cfg, + obj_type: 'post', + for_obj_type: 'event', + for_obj_id: post_id, + use_alt_tbl: true, // NOTE: We want to use the alt table for post searching + use_alt_mdl: false, + use_alt_exp: false, + enabled: enabled, + hidden: hidden, + order_by_li: order_by_li, + limit: limit, + offset: offset, + params_json: params_json, + params: params, + log_lvl: log_lvl + }) + .then(function (post_obj_li_get_result) { + if (post_obj_li_get_result) { + db_save_ae_obj_li__post({ + obj_type: 'post', + obj_li: post_obj_li_get_result + }); + return post_obj_li_get_result; + } else { + return []; + } + }); + + if (log_lvl) { + console.log('ae_promises.load__post_obj_li:', ae_promises.load__post_obj_li); + } + return ae_promises.load__post_obj_li; +} + + +// Updated 2024-09-25 +// export async function search__post( +// { +// api_cfg, +// account_id, +// poc_agree = null, +// fulltext_search_qry_str, +// ft_comment_search_qry_str, +// like_search_qry_str = null, +// file_count = false, // If true then only show those that have a file count +// person_name = null, +// params = {}, +// try_cache = true, +// log_lvl = 0 +// }: { +// api_cfg: any, +// account_id: any, +// poc_agree?: null|boolean, +// fulltext_search_qry_str?: null|string, +// ft_comment_search_qry_str?: null|string, +// like_search_qry_str?: null|string, +// file_count?: boolean, +// person_name?: null|string, +// params?: any, +// try_cache?: boolean, +// log_lvl?: number +// } +// ) { +// console.log(`*** search__post() *** account_id=${account_id}`); + +// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled +// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden +// let limit: number = (params.qry__limit ?? 25); // 99 +// let offset: number = (params.qry__offset ?? 0); // 0 + +// let params_json: key_val = {}; + +// // if (!fulltext_search_qry_str && !like_search_qry_str) { +// // console.log('No search string provided!!!'); +// // return false; // Returning false instead of [] because no search was performed. +// // } + +// if (fulltext_search_qry_str || ft_comment_search_qry_str) { +// params_json['ft_qry'] = {}; +// if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { +// params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str; +// } + +// if (ft_comment_search_qry_str && ft_comment_search_qry_str.length > 2) { +// params_json['ft_qry']['post_comment_li_qry_str'] = ft_comment_search_qry_str; +// } +// } + +// // Use the AND (AND LIKE) query +// // if (like_search_qry_str || like_comment_search_qry_str) { +// // params_json['and_like'] = {}; +// // if (like_search_qry_str && like_search_qry_str.length > 2) { +// // params_json['and_like']['default_qry_str'] = like_search_qry_str; +// // } +// // if (like_comment_search_qry_str && like_comment_search_qry_str.length > 2) { +// // params_json['and_like']['post_comment_li_qry_str'] = like_comment_search_qry_str; +// // } +// // } + +// // Use the AND (OR LIKE) query +// if (like_search_qry_str || like_comment_search_qry_str || like_comment_search_qry_str) { +// params_json['or_like'] = {}; +// if (like_search_qry_str && like_search_qry_str.length > 2) { +// params_json['or_like']['default_qry_str'] = like_search_qry_str; +// } +// if (like_comment_search_qry_str && like_comment_search_qry_str.length > 2) { +// params_json['or_like']['post_comment_li_qry_str'] = like_comment_search_qry_str; +// } +// if (like_comment_search_qry_str && like_comment_search_qry_str.length > 2) { +// params_json['or_like']['post_comment_li_qry_str'] = like_comment_search_qry_str; +// } +// } + +// params_json['and_qry'] = {}; + +// if (poc_agree) { +// params_json['and_qry']['poc_agree'] = poc_agree; +// } + +// if (file_count) { +// params_json['and_qry']['file_count'] = file_count; +// } + +// // This should be using a like with surrounded by %'s +// if (person_name) { +// params_json['and_qry']['post_full_name'] = person_name; +// } + +// let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}; + +// ae_promises.load__post_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ +// api_cfg: api_cfg, +// obj_type: 'post', +// for_obj_type: 'account', +// for_obj_id: account_id, +// use_alt_table: true, // NOTE: We want to use the alt table for post searching +// use_alt_base: false, +// enabled: enabled, +// hidden: hidden, +// order_by_li: order_by_li, +// limit: limit, +// offset: offset, +// params_json: params_json, +// params: params, +// log_lvl: log_lvl +// }) +// .then(function (post_obj_li_get_result) { +// if (post_obj_li_get_result) { +// if (try_cache) { +// db_save_ae_obj_li__post({ +// obj_type: 'post', +// obj_li: post_obj_li_get_result +// }); +// } +// return post_obj_li_get_result; +// } else { +// return []; +// } +// }) +// .catch(function (error) { +// console.log('No results returned or failed.', error); +// }) +// .finally(function () { +// }); + +// if (log_lvl) { +// console.log('ae_promises.load__post_obj_li:', ae_promises.load__post_obj_li); +// } +// return ae_promises.load__post_obj_li; +// } + + +// This function will loop through the post_obj_li and save each one to the DB. +// Updated 2024-09-25 +export function db_save_ae_obj_li__post( + { + 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__post() ***`); + } + + if (obj_li && obj_li.length) { + obj_li.forEach(async function (obj: any) { + if (log_lvl) { + console.log(`ae_obj ${obj_type}:`, obj); + } + + try { + const id_random = await db_posts.post.put({ + id: obj.post_id_random, + post_id: obj.post_id_random, + + code: obj.code, + + account_id: obj.account_id_random, + + name: obj.name, + description: obj.description, + + original_datetime: obj.original_datetime, + original_timezone: obj.original_timezone, + original_location: obj.original_location, + + original_url: obj.original_url, + original_url_text: obj.original_url_text, + + sort_by: obj.sort_by, + sort_by_desc: obj.sort_by_desc, + + 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, + + // From SQL view + // post_comment_count: obj.post_comment_count, + + // A key value list of the comments + // post_comment_kv: obj.post_comment_kv, + // post_comment_li: obj.post_comment_li, + }); + // console.log(`Put obj with ID: ${obj.post_id_random} or ${id_random}`); + } catch (error) { + let status = `Failed to put ${obj.post_id_random}: ${error}`; + console.log(status); + } + + // const id_random = await db_posts.post.put(obj); + // console.log(`Put obj with ID: ${obj.post_id_random}`); + }); + + return true; + } +} diff --git a/src/lib/ae_posts__post_comment.ts b/src/lib/ae_posts__post_comment.ts new file mode 100644 index 00000000..c9f5dde8 --- /dev/null +++ b/src/lib/ae_posts__post_comment.ts @@ -0,0 +1,250 @@ +import type { key_val } from '$lib/ae_stores'; +import { api } from '$lib/api'; + +import { db_posts } from "$lib/db_posts"; + +let ae_promises: key_val = {}; + + +// Updated 2024-09-25 +export async function load_ae_obj_id__post_comment( + { + api_cfg, + post_comment_id, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + post_comment_id: string, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_id__post_comment() *** post_comment_id=${post_comment_id}`); + + let params = {}; + + ae_promises.load__post_comment_obj = await api.get_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'post_comment', + obj_id: post_comment_id, // NOTE: This is the FQDN, not normally the ID. + use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + params: params, + log_lvl: log_lvl + }) + .then(function (post_comment_obj_get_result) { + if (post_comment_obj_get_result) { + if (try_cache) { + // This is expecting a list + db_save_ae_obj_li__post_comment({ + obj_type: 'post_comment', + obj_li: [post_comment_obj_get_result] + + }); + } + return post_comment_obj_get_result; + } else { + console.log('No results returned.'); + return null; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + return ae_promises.load__post_comment_obj; +} + + +// Updated 2024-09-25 +export async function load_ae_obj_li__post_comment( + { + api_cfg, + for_obj_type = 'post', + for_obj_id, + order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'start_datetime': 'ASC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}, + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + for_obj_type: string, + for_obj_id: string, + order_by_li?: key_val, + params?: key_val, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** load_ae_obj_li__post_comment() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`); + + let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled + let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden + let limit: number = (params.qry__limit ?? 99); // 99 + let offset: number = (params.qry__offset ?? 0); // 0 + + let params_json: key_val = {}; + + // console('params_json:', params_json); + + ae_promises.load__post_comment_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'post_comment', + for_obj_type: for_obj_type, + for_obj_id: for_obj_id, + use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + enabled: enabled, + hidden: hidden, + order_by_li: order_by_li, + limit: limit, + offset: offset, + params_json: params_json, + params: params, + log_lvl: log_lvl + }) + .then(function (post_comment_obj_li_get_result) { + if (post_comment_obj_li_get_result) { + if (try_cache) { + db_save_ae_obj_li__post_comment({ + obj_type: 'post_comment', obj_li: post_comment_obj_li_get_result + }); + } + return post_comment_obj_li_get_result; + } else { + return []; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + if (log_lvl) { + console.log('ae_promises.load__post_comment_obj_li:', ae_promises.load__post_comment_obj_li); + } + + return ae_promises.load__post_comment_obj_li; +} + + +// Updated 2024-09-25 +export async function create_ae_obj__post_comment( + { + api_cfg, + post_id, + data_kv, + params={}, + log_lvl=0 + }: { + api_cfg: any, + post_id: string, + data_kv: key_val, + params?: key_val, + log_lvl?: number + } + ) { + console.log(`*** create_ae_obj__post_comment() *** post_id=${post_id}`); + + ae_promises.create__post_comment = await api.create_ae_obj_crud({ + api_cfg: api_cfg, + obj_type: 'post_comment', + fields: { + post_id_random: post_id, + ...data_kv + }, + key: api_cfg.api_crud_super_key, + params: params, + return_obj: true, + log_lvl: log_lvl + }) + .then(function (post_comment_obj_create_result) { + if (post_comment_obj_create_result) { + db_save_ae_obj_li__post_comment( + { + obj_type: 'post_comment', + obj_li: [post_comment_obj_create_result] + }); + return post_comment_obj_create_result; + } else { + return null; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }) + .finally(function () { + }); + + if (log_lvl) { + console.log('ae_promises.create__post_comment:', ae_promises.create__post_comment); + } + return ae_promises.create__post_comment; +} + + +// This function will loop through the post_comment_obj_li and save each one to the DB. +// Updated 2024-09-25 +export function db_save_ae_obj_li__post_comment( + { + 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__post_comment() ***`); + } + + if (obj_li && obj_li.length) { + obj_li.forEach(async function (obj: any) { + if (log_lvl) { + console.log(`ae_obj ${obj_type}:`, obj); + } + + try { + const id_random = await db_posts.comment.put({ + id: obj.post_comment_id_random, + post_comment_id: obj.post_comment_id_random, + + post_id: obj.post_id_random, + + // name: obj.name, + // summary: obj.summary, + title: obj.title, + content: obj.content, + + anonymous: obj.anonymous, + full_name: obj.full_name, + email: obj.email, + + 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, + + // From SQL view + }); + // console.log(`Put obj with ID: ${obj.post_comment_id_random} or ${id_random}`); + } catch (error) { + let status = `Failed to put ${obj.post_comment_id_random}: ${error}`; + console.log(status); + } + + // const id_random = await db_posts.comment.put(obj); + // console.log(`Put obj with ID: ${obj.post_comment_id_random}`); + }); + + return true; + } +} diff --git a/src/lib/db_archives.ts b/src/lib/db_archives.ts index 8b9cf547..e09cd6bd 100644 --- a/src/lib/db_archives.ts +++ b/src/lib/db_archives.ts @@ -5,6 +5,7 @@ import type { key_val } from './ae_stores'; // li = list // kv = key value list +// Updated 2024-09-25 export interface Archive { id: string; // id_random: string; @@ -41,11 +42,6 @@ export interface Archive { sort_by?: null|string; sort_by_desc?: null|string; - start_datetime?: Date; - end_datetime?: Date; - timezone?: null|string; - location_address_json?: null|string; - cfg_json?: null|key_val; enable: null|boolean; @@ -58,12 +54,12 @@ export interface Archive { updated_on?: null|Date; // Additional fields for convenience (database views) - archive_content_count: number; - // file_count?: null|number; - // file_count_all?: null|number; - // archive_file_id_li_json?: null|string; + // archive_content_count?: number; + // archive_content_kv?: null|key_val; + // archive_content_li?: null|[]; } +// Updated 2024-09-25 export interface Archive_Content { id: string; // id_random: string; @@ -112,4 +108,40 @@ export interface Archive_Content { notes?: null|string; created_on: Date; updated_on?: null|Date; -} \ No newline at end of file + + // Additional fields for convenience (database views) +} + + +// Updated 2024-09-25 +export class MySubClassedDexie extends Dexie { + // We just tell the typing system this is the case + archive!: Table; + archive_content!: Table; + + constructor() { + super('ae_archives_db'); + this.version(1).stores({ + archive: ` + id, archive_id, + code, + account_id, + name, + original_datetime, original_timezone, original_location, + enable, hide, priority, sort, group, notes, created_on, updated_on`, + archive_content: ` + id, archive_content_id, + archive_id, + archive_content_type, + name, + hosted_file_id, + file_path, + filename, file_extension, + original_datetime, original_timezone, original_location, original_url, original_url_text, + enable_for_public, + enable, hide, priority, sort, group, notes, created_on, updated_on`, + }); + } +} + +export const db_archives = new MySubClassedDexie(); \ No newline at end of file diff --git a/src/lib/db_notes.ts b/src/lib/db_notes.ts index a40f22b5..48836c3b 100644 --- a/src/lib/db_notes.ts +++ b/src/lib/db_notes.ts @@ -127,12 +127,12 @@ export interface Note { // Updated 2024-06-10 export class MySubClassedDexie extends Dexie { // We just tell the typing system this is the case - notes!: Table; + note!: Table; constructor() { super('ae_notes_db'); this.version(1).stores({ - notes: ` + note: ` id, note_id, note_id_random, code, account_id, account_id_random, @@ -146,4 +146,4 @@ export class MySubClassedDexie extends Dexie { } } -export const db_notes = new MySubClassedDexie(); \ No newline at end of file +export const db_notes = new MySubClassedDexie(); diff --git a/src/lib/db_posts.ts b/src/lib/db_posts.ts new file mode 100644 index 00000000..f428dcc7 --- /dev/null +++ b/src/lib/db_posts.ts @@ -0,0 +1,115 @@ +import Dexie, { type Table } from 'dexie'; + +import type { key_val } from './ae_stores'; + +// li = list +// kv = key value list + +// Updated 2024-09-25 +export interface Post { + id: string; + // id_random: string; + post_id: string; + // post_id_random: string; + + account_id: string; + // account_id_random: string; + + person_id?: null|string; + external_person_id?: null|string; // For IDAA this is the Novi UUID + user_id?: null|string; + + topic_id: string; + topic: string; // or topic_name? + + // name: null|string; + // summary?: null|string; + title: null|string; + content?: null|string; + + anonymous?: null|boolean; + full_name?: null|string; + email?: null|string; + + enable_comments?: null|boolean; + + archive?: null|boolean; + archive_on?: Date; + + cfg_json?: null|key_val; + + enable: null|boolean; + hide?: null|boolean; + priority?: null|boolean + sort?: null|number; + group?: null|string; + notes?: null|string; + created_on: Date; + updated_on?: null|Date; + + // Additional fields for convenience (database views) + post_comment_count?: number; +} + +// Updated 2024-09-25 +export interface Post_Comment { + id: string; + // id_random: string; + post_comment_id: string; + // post_comment_id_random: string; + + post_id: string; + // post_id_random: string; + + // name: null|string; + // summary?: null|string; + title: null|string; + content?: null|string; + + anonymous?: null|boolean; + full_name?: null|string; + email?: null|string; + + cfg_json?: null|key_val; + + enable: null|boolean; + hide?: null|boolean; + priority?: null|boolean + sort?: null|number; + group?: null|string; + notes?: null|string; + created_on: Date; + updated_on?: null|Date; + + // Additional fields for convenience (database views) +} + + +// Updated 2024-09-25 +export class MySubClassedDexie extends Dexie { + // We just tell the typing system this is the case + post!: Table; + post_comment!: Table; + + constructor() { + super('ae_posts_db'); + this.version(1).stores({ + post: ` + id, post_id, + account_id, + topic_id, topic, + title, + full_name, email, + archive, archive_on, + enable, hide, priority, sort, group, notes, created_on, updated_on`, + post_comment: ` + id, post_comment_id, + post_id, + title, + full_name, email, + enable, hide, priority, sort, group, notes, created_on, updated_on`, + }); + } +} + +export const db_posts = new MySubClassedDexie();