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

@@ -201,17 +201,21 @@ export async function create_ae_obj__archive(
api_cfg,
account_id,
data_kv,
params={},
log_lvl=0
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
account_id: string,
data_kv: key_val,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
console.log(`*** create_ae_obj__archive() *** account_id=${account_id}`);
if (log_lvl) {
console.log(`*** create_ae_obj__archive() *** account_id=${account_id}`);
}
ae_promises.create__archive = await api.create_ae_obj_crud({
api_cfg: api_cfg,
@@ -227,11 +231,13 @@ export async function create_ae_obj__archive(
})
.then(function (archive_obj_create_result) {
if (archive_obj_create_result) {
db_save_ae_obj_li__archive(
{
obj_type: 'archive',
obj_li: [archive_obj_create_result]
});
if (try_cache) {
db_save_ae_obj_li__archive(
{
obj_type: 'archive',
obj_li: [archive_obj_create_result]
});
}
return archive_obj_create_result;
} else {
return null;
@@ -239,8 +245,6 @@ export async function create_ae_obj__archive(
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
});
if (log_lvl) {
@@ -250,6 +254,57 @@ export async function create_ae_obj__archive(
}
// Updated 2024-11-08
export async function delete_ae_obj_id__archive(
{
api_cfg,
archive_id,
method = 'delete', // 'delete', 'disable', 'hide'
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
archive_id: string,
method?: string,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
if (log_lvl) {
console.log(`*** delete_ae_obj_id__archive() *** archive_id=${archive_id}`);
}
ae_promises.delete__archive_obj = await api.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'archive',
obj_id: archive_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 archive_id=${archive_id}`);
}
db_archives.content.delete(archive_id); // Delete from the DB no matter what.
}
});
if (log_lvl) {
console.log('ae_promises.delete__archive_obj:', ae_promises.delete__archive_obj);
}
return ae_promises.delete__archive_obj;
}
// Updated 2024-09-25
export async function update_ae_obj__archive(
{

View File

@@ -139,7 +139,7 @@ export async function create_ae_obj__archive_content(
data_kv,
params={},
try_cache = true,
log_lvl=0
log_lvl = 0
}: {
api_cfg: any,
archive_id: string,
@@ -149,7 +149,9 @@ export async function create_ae_obj__archive_content(
log_lvl?: number
}
) {
console.log(`*** create_ae_obj__archive_content() *** archive_id=${archive_id}`);
if (log_lvl) {
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,
@@ -179,8 +181,6 @@ export async function create_ae_obj__archive_content(
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
});
if (log_lvl) {
@@ -221,18 +221,16 @@ export async function delete_ae_obj_id__archive_content(
method: method,
log_lvl: log_lvl
})
.then(function (archive_content_obj_delete_result) {
// if (archive_content_obj_delete_result) {
// return archive_content_obj_delete_result;
// } else {
// return null;
// }
})
.catch(function (error) {
console.log('No results returned or failed.', error);
})
.finally(function () {
db_archives.content.delete(archive_content_id); // Delete from the DB no matter what.
if (try_cache) {
if (log_lvl) {
console.log(`Attempting to remove IDB entry for archive_content_id=${archive_content_id}`);
}
db_archives.content.delete(archive_content_id); // Delete from the DB no matter what.
}
});
if (log_lvl) {

View File

@@ -4,6 +4,7 @@ import {
load_ae_obj_id__archive,
load_ae_obj_li__archive,
create_ae_obj__archive,
delete_ae_obj_id__archive,
update_ae_obj__archive,
// qry__archive,
db_save_ae_obj_li__archive,
@@ -25,6 +26,7 @@ let export_obj = {
load_ae_obj_id__archive: load_ae_obj_id__archive,
load_ae_obj_li__archive: load_ae_obj_li__archive,
create_ae_obj__archive: create_ae_obj__archive,
delete_ae_obj_id__archive: delete_ae_obj_id__archive,
update_ae_obj__archive: update_ae_obj__archive,
db_save_ae_obj_li__archive: db_save_ae_obj_li__archive,