Creating standardized functions. Mainly for create and delete.

This commit is contained in:
Scott Idem
2024-11-08 12:47:24 -05:00
parent 4fe04d9c3f
commit 13d906428b
17 changed files with 855 additions and 276 deletions

View File

@@ -134,17 +134,21 @@ export async function create_ae_obj__post_comment(
api_cfg,
post_id,
data_kv,
params={},
log_lvl=0
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
}
) {
console.log(`*** create_ae_obj__post_comment() *** post_id=${post_id}`);
if (log_lvl) {
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,
@@ -160,11 +164,13 @@ export async function create_ae_obj__post_comment(
})
.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]
});
if (try_cache) {
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;
@@ -183,6 +189,57 @@ export async function create_ae_obj__post_comment(
}
// Updated 2024-11-08
export async function delete_ae_obj_id__post_comment(
{
api_cfg,
post_comment_id,
method = 'delete', // 'delete', 'disable', 'hide'
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
post_comment_id: string,
method?: string,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
if (log_lvl) {
console.log(`*** delete_ae_obj_id__post_comment() *** post_comment_id=${post_comment_id}`);
}
ae_promises.delete__post_comment_obj = await api.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'post_comment',
obj_id: post_comment_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
log_lvl: log_lvl
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
if (try_cache) {
if (log_lvl) {
console.log(`Attempting to remove IDB entry for post_comment_id=${post_comment_id}`);
}
db_posts.comment.delete(post_comment_id); // Delete from the DB no matter what.
}
});
if (log_lvl) {
console.log('ae_promises.delete__post_comment_obj:', ae_promises.delete__post_comment_obj);
}
return ae_promises.delete__post_comment_obj;
}
// Updated 2024-09-25
export async function update_ae_obj__post_comment(
{