Updates related to IDAA API functions and related. Some style updates.

This commit is contained in:
Scott Idem
2025-06-23 15:49:53 -04:00
parent 1ad1251931
commit 0b345e325e
8 changed files with 542 additions and 253 deletions

View File

@@ -15,12 +15,14 @@ export async function load_ae_obj_id__archive(
api_cfg,
archive_id,
inc_content_li = false,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
archive_id: string,
inc_content_li?: boolean,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
@@ -29,14 +31,12 @@ export async function load_ae_obj_id__archive(
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.
obj_id: archive_id,
use_alt_table: true,
use_alt_base: false,
params: params,
log_lvl: log_lvl
})
@@ -284,7 +284,7 @@ export async function load_ae_obj_li__archive(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function create_ae_obj__archive(
{
api_cfg,
@@ -306,6 +306,11 @@ export async function create_ae_obj__archive(
console.log(`*** create_ae_obj__archive() *** account_id=${account_id}`);
}
if (!account_id) {
console.log(`ERROR: Archives - Archive - account_id required to create`);
return false;
}
ae_promises.create__archive = await api.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'archive',
@@ -318,14 +323,37 @@ export async function create_ae_obj__archive(
return_obj: true,
log_lvl: log_lvl
})
.then(function (archive_obj_create_result) {
.then(async function (archive_obj_create_result) {
if (archive_obj_create_result) {
if (try_cache) {
db_save_ae_obj_li__archive(
{
obj_type: 'archive',
obj_li: [archive_obj_create_result]
// Process the results first
let processed_obj_li = await process_ae_obj__archive_props({
obj_li: [archive_obj_create_result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'archive',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__archive(
// {
// obj_type: 'archive',
// obj_li: [archive_obj_create_result]
// });
}
return archive_obj_create_result;
} else {
@@ -394,7 +422,7 @@ export async function delete_ae_obj_id__archive(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function update_ae_obj__archive(
{
api_cfg,
@@ -415,7 +443,9 @@ export async function update_ae_obj__archive(
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({
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'archive',
obj_id: archive_id,
@@ -424,29 +454,45 @@ export async function update_ae_obj__archive(
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);
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
let processed_obj_li = await process_ae_obj__archive_props({
obj_li: [result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'archive',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__archive({
// obj_type: 'archive',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update archive.');
return null;
}
return ae_promises.update__archive_obj;
}

View File

@@ -191,7 +191,7 @@ export async function load_ae_obj_li__archive_content(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function create_ae_obj__archive_content(
{
api_cfg,
@@ -213,6 +213,11 @@ export async function create_ae_obj__archive_content(
console.log(`*** create_ae_obj__archive_content() *** archive_id=${archive_id}`);
}
if (!archive_id) {
console.log(`ERROR: Archives - Content - archive_id required to create`);
return false;
}
ae_promises.create__archive_content = await api.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'archive_content',
@@ -228,11 +233,34 @@ export async function create_ae_obj__archive_content(
.then(async function (archive_content_obj_create_result) {
if (archive_content_obj_create_result) {
if (try_cache) {
await db_save_ae_obj_li__archive_content(
{
obj_type: 'archive_content',
obj_li: [archive_content_obj_create_result]
// Process the results first
let processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: [archive_content_obj_create_result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'archive_content',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// await 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 {
@@ -301,7 +329,7 @@ export async function delete_ae_obj_id__archive_content(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function update_ae_obj__archive_content(
{
api_cfg,
@@ -322,7 +350,9 @@ export async function update_ae_obj__archive_content(
if (log_lvl) {
console.log(`*** update_ae_obj__archive_content() *** archive_content_id=${archive_content_id}`, data_kv);
}
ae_promises.update__archive_content_obj = await api.update_ae_obj_id_crud({
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'archive_content',
obj_id: archive_content_id,
@@ -330,30 +360,46 @@ export async function update_ae_obj__archive_content(
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (archive_content_obj_update_result) {
if (archive_content_obj_update_result) {
if (try_cache) {
await db_save_ae_obj_li__archive_content({
obj_type: 'archive_content', obj_li: [archive_content_obj_update_result]
});
}
return archive_content_obj_update_result;
} else {
return null;
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('ae_promises.update__archive_content_obj:', ae_promises.update__archive_content_obj);
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
let processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: [result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'archive_content',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__archive_content({
// obj_type: 'archive_content',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update archive content.');
return null;
}
return ae_promises.update__archive_content_obj;
}

View File

@@ -611,6 +611,7 @@ export async function create_ae_obj__event(
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event(
// {
// obj_type: 'event',

View File

@@ -584,15 +584,15 @@ export async function update_ae_obj__journal_entry(
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__journal_entry({
// obj_type: 'journal_entry',
// obj_li: [result],
// log_lvl: log_lvl,
// });
if (log_lvl) {
console.log('DB save completed.');
}
}
return result;
} else {

View File

@@ -10,7 +10,7 @@ import { load_ae_obj_li__post_comment } from "$lib/ae_posts/ae_posts__post_comme
let ae_promises: key_val = {};
// Updated 2024-09-25
// Updated 2025-06-23
export async function load_ae_obj_id__post(
{
api_cfg,
@@ -20,6 +20,7 @@ export async function load_ae_obj_id__post(
limit = 99,
offset = 0,
inc_comment_li = false,
params = {},
try_cache = true,
log_lvl = 0
}: {
@@ -30,6 +31,7 @@ export async function load_ae_obj_id__post(
limit?: number,
offset?: number,
inc_comment_li?: boolean,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
@@ -38,8 +40,6 @@ export async function load_ae_obj_id__post(
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',
@@ -49,15 +49,38 @@ export async function load_ae_obj_id__post(
params: params,
log_lvl: log_lvl
})
.then(function (post_obj_get_result) {
.then(async 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',
// Process the results first
let processed_obj_li = await process_ae_obj__post_props({
obj_li: [post_obj_get_result],
log_lvl: log_lvl
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// db_save_ae_obj_li__post({
// obj_type: 'post',
// obj_li: [post_obj_get_result],
// log_lvl: log_lvl
// });
}
return post_obj_get_result;
} else {
@@ -73,7 +96,7 @@ export async function load_ae_obj_id__post(
console.log('ae_promises.load__post_obj:', ae_promises.load__post_obj);
}
if (inc_comment_li && 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`);
@@ -82,9 +105,9 @@ export async function load_ae_obj_id__post(
api_cfg: api_cfg,
for_obj_type: 'post',
for_obj_id: post_id,
enabled: enabled,
hidden: hidden,
limit: limit,
enabled: enabled, // all, disabled, enabled
hidden: hidden, // all, hidden, not_hidden
limit: limit, // Limit for the comments
offset: offset,
params: {qry__enabled: 'all', qry__limit: 25},
try_cache: try_cache,
@@ -107,7 +130,7 @@ export async function load_ae_obj_id__post(
}
// Updated 2024-11-20
// Updated 2025-06-23
export async function load_ae_obj_li__post(
{
api_cfg,
@@ -143,7 +166,9 @@ export async function load_ae_obj_li__post(
let params_json: key_val = {};
// console.log('params_json:', params_json);
if (log_lvl) {
console.log('params_json:', params_json);
}
ae_promises.load__post_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
@@ -162,14 +187,37 @@ export async function load_ae_obj_li__post(
params: params,
log_lvl: log_lvl
})
.then(function (post_obj_li_get_result) {
.then(async function (post_obj_li_get_result) {
if (post_obj_li_get_result) {
if (try_cache) {
db_save_ae_obj_li__post({
obj_type: 'post',
// Process the results first
let processed_obj_li = await process_ae_obj__post_props({
obj_li: post_obj_li_get_result,
log_lvl: log_lvl
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post({
// obj_type: 'post',
// obj_li: post_obj_li_get_result,
// log_lvl: log_lvl
// });
}
return post_obj_li_get_result;
} else {
@@ -223,7 +271,7 @@ export async function load_ae_obj_li__post(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function create_ae_obj__post(
{
api_cfg,
@@ -245,6 +293,11 @@ export async function create_ae_obj__post(
console.log(`*** create_ae_obj__post() *** account_id=${account_id}`);
}
if (!account_id) {
console.log(`ERROR: Posts - Post - account_id required to create`);
return false;
}
ae_promises.create__post = await api.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'post',
@@ -257,15 +310,38 @@ export async function create_ae_obj__post(
return_obj: true,
log_lvl: log_lvl
})
.then(function (post_obj_create_result) {
.then(async function (post_obj_create_result) {
if (post_obj_create_result) {
if (try_cache) {
db_save_ae_obj_li__post(
{
obj_type: 'post',
obj_li: [post_obj_create_result],
log_lvl: log_lvl
// Process the results first
let processed_obj_li = await process_ae_obj__post_props({
obj_li: [post_obj_create_result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post(
// {
// obj_type: 'post',
// obj_li: [post_obj_create_result],
// log_lvl: log_lvl
// });
}
return post_obj_create_result;
} else {
@@ -336,7 +412,7 @@ export async function delete_ae_obj_id__post(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function update_ae_obj__post(
{
api_cfg,
@@ -357,7 +433,9 @@ export async function update_ae_obj__post(
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({
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'post',
obj_id: post_id,
@@ -365,32 +443,46 @@ export async function update_ae_obj__post(
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],
log_lvl: log_lvl
});
}
return post_obj_update_result;
} else {
return null;
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('ae_promises.update__post_obj:', ae_promises.update__post_obj);
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
let processed_obj_li = await process_ae_obj__post_props({
obj_li: [result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__post({
// obj_type: 'post',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update post.');
return null;
}
return ae_promises.update__post_obj;
}

View File

@@ -8,7 +8,7 @@ import { db_posts } from "$lib/ae_posts/db_posts";
let ae_promises: key_val = {};
// Updated 2024-09-25
// Updated 2025-06-23
export async function load_ae_obj_id__post_comment(
{
api_cfg,
@@ -17,6 +17,7 @@ export async function load_ae_obj_id__post_comment(
hidden = 'not_hidden',
limit = 99,
offset = 0,
params = {},
try_cache = true,
log_lvl = 0
}: {
@@ -26,6 +27,7 @@ export async function load_ae_obj_id__post_comment(
hidden?: string,
limit?: number,
offset?: number,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
@@ -34,8 +36,6 @@ export async function load_ae_obj_id__post_comment(
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',
@@ -45,16 +45,39 @@ export async function load_ae_obj_id__post_comment(
params: params,
log_lvl: log_lvl
})
.then(function (post_comment_obj_get_result) {
.then(async 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',
// Process the results first
let processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: [post_comment_obj_get_result],
log_lvl: log_lvl
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post_comment',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// db_save_ae_obj_li__post_comment({
// obj_type: 'post_comment',
// obj_li: [post_comment_obj_get_result],
// log_lvl: log_lvl
// });
}
return post_comment_obj_get_result;
} else {
@@ -70,7 +93,7 @@ export async function load_ae_obj_id__post_comment(
}
// Updated 2024-11-20
// Updated 2025-06-23
export async function load_ae_obj_li__post_comment(
{
api_cfg,
@@ -102,14 +125,11 @@ export async function load_ae_obj_li__post_comment(
console.log(`*** load_ae_obj_li__post_comment() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
}
// if (params.qry__enabled) { enabled = params.qry__enabled; }
// if (params.qry__hidden) { hidden = params.qry__hidden; }
// if (params.qry__limit) { limit = params.qry__limit; }
// if (params.qry__offset) { offset = params.qry__offset; }
let params_json: key_val = {};
// console('params_json:', params_json);
if (log_lvl) {
console.log('params_json:', params_json);
}
ae_promises.load__post_comment_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
@@ -128,14 +148,37 @@ export async function load_ae_obj_li__post_comment(
params: params,
log_lvl: log_lvl
})
.then(function (post_comment_obj_li_get_result) {
.then(async 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',
// Process the results first
let processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: post_comment_obj_li_get_result,
log_lvl: log_lvl
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post_comment',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post_comment({
// obj_type: 'post_comment',
// obj_li: post_comment_obj_li_get_result,
// log_lvl: log_lvl
// });
}
return post_comment_obj_li_get_result;
} else {
@@ -154,7 +197,7 @@ export async function load_ae_obj_li__post_comment(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function create_ae_obj__post_comment(
{
api_cfg,
@@ -176,6 +219,11 @@ export async function create_ae_obj__post_comment(
console.log(`*** create_ae_obj__post_comment() *** post_id=${post_id}`);
}
if (!post_id) {
console.log(`ERROR: Posts - Comment - post_id required to create`);
return false;
}
ae_promises.create__post_comment = await api.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'post_comment',
@@ -188,15 +236,38 @@ export async function create_ae_obj__post_comment(
return_obj: true,
log_lvl: log_lvl
})
.then(function (post_comment_obj_create_result) {
.then(async function (post_comment_obj_create_result) {
if (post_comment_obj_create_result) {
if (try_cache) {
db_save_ae_obj_li__post_comment(
{
obj_type: 'post_comment',
obj_li: [post_comment_obj_create_result],
log_lvl: log_lvl
// Process the results first
let processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: [post_comment_obj_create_result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post_comment',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post_comment(
// {
// obj_type: 'post_comment',
// obj_li: [post_comment_obj_create_result],
// log_lvl: log_lvl
// });
}
return post_comment_obj_create_result;
} else {
@@ -267,7 +338,7 @@ export async function delete_ae_obj_id__post_comment(
}
// Updated 2024-09-25
// Updated 2025-06-23
export async function update_ae_obj__post_comment(
{
api_cfg,
@@ -288,7 +359,9 @@ export async function update_ae_obj__post_comment(
if (log_lvl) {
console.log(`*** update_ae_obj__post_comment() *** post_comment_id=${post_comment_id}`, data_kv);
}
ae_promises.update__post_comment_obj = await api.update_ae_obj_id_crud({
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'post_comment',
obj_id: post_comment_id,
@@ -296,32 +369,46 @@ export async function update_ae_obj__post_comment(
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(function (post_comment_obj_update_result) {
if (post_comment_obj_update_result) {
if (try_cache) {
db_save_ae_obj_li__post_comment({
obj_type: 'post_comment',
obj_li: [post_comment_obj_update_result],
log_lvl: log_lvl
});
}
return post_comment_obj_update_result;
} else {
return null;
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('ae_promises.update__post_comment_obj:', ae_promises.update__post_comment_obj);
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
let processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: [result],
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post_comment',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl,
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__post_comment({
// obj_type: 'post_comment',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update post comment.');
return null;
}
return ae_promises.update__post_comment_obj;
}