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

@@ -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;
}