Should have saved my work earlier... General clean up of initial API calls and saving to IDB. Other fixes and updates.

This commit is contained in:
Scott Idem
2024-08-07 15:26:58 -04:00
parent 0d34f81fa7
commit 7aebf24996
40 changed files with 1218 additions and 3259 deletions

View File

@@ -180,13 +180,14 @@ export let get_ae_obj_id_crud = async function get_ae_obj_id_crud(
}
// The lookup "obj_type" should broken out into a separate function. - 2024-08-07
// Updated 2023-11-15
export let get_ae_obj_li_for_obj_id_crud = async function get_ae_obj_li_for_obj_id_crud(
{
api_cfg,
obj_type,
for_obj_type,
for_obj_id=null, // NOTE: Changed 2023-12-06 to no longer required
for_obj_id, // NOTE: Changed 2023-12-06 to no longer required
use_alt_table=false,
use_alt_base=false,
inc={},
@@ -304,15 +305,15 @@ export let get_ae_obj_li_for_obj_id_crud = async function get_ae_obj_li_for_obj_
endpoint = `/crud/sponsorship/list`;
// } else if (obj_type == 'user') {
// endpoint = `/crud/user/list`;
} else if (obj_type == 'lu' && for_obj_type == 'country_subdivision') {
endpoint = `/crud/lu/country_subdivision/list`;
for_obj_type = null;
} else if (obj_type == 'lu' && for_obj_type == 'country') {
endpoint = `/crud/lu/country/list`;
for_obj_type = null;
} else if (obj_type == 'lu' && for_obj_type == 'time_zone') {
endpoint = `/crud/lu/time_zone/list`;
for_obj_type = null;
// } else if (obj_type == 'lu' && for_obj_type == 'country_subdivision') {
// endpoint = `/crud/lu/country_subdivision/list`;
// for_obj_type = null;
// } else if (obj_type == 'lu' && for_obj_type == 'country') {
// endpoint = `/crud/lu/country/list`;
// for_obj_type = null;
// } else if (obj_type == 'lu' && for_obj_type == 'time_zone') {
// endpoint = `/crud/lu/time_zone/list`;
// for_obj_type = null;
} else {
console.log(`Unknown object type: ${obj_type}`);
return false;
@@ -402,10 +403,147 @@ export let get_ae_obj_li_for_obj_id_crud = async function get_ae_obj_li_for_obj_
}
// Updated 2023-07-24
export let create_ae_obj_crud = async function create_ae_obj_crud({api_cfg, obj_type, field_name=null, field_value=null, fields={}, key, jwt=null, headers={}, params={}, data={}, return_obj=false, obj_v_name='', return_meta=false, log_lvl=0}) {
// This new function has not been tested yet!!!
// Updated 2024-08-07
export let get_ae_obj_li_for_lu = async function get_ae_obj_li_for_lu(
{
api_cfg,
// obj_type,
for_lu_type,
// for_obj_id=null,
// use_alt_table=false,
// use_alt_base=false,
// inc={},
enabled='enabled',
hidden='not_hidden',
order_by_li=null,
limit=999999,
offset=0,
// key,
// jwt=null,
headers={},
params_json=null,
// json_obj=null,
params={},
return_meta=false,
log_lvl=1
}: {
api_cfg: any,
// obj_type: string,
for_lu_type: string,
// for_lu_id?: string,
// use_alt_table?: boolean,
// use_alt_base?: boolean,
// inc?: key_val
enabled?: string,
hidden?: string,
order_by_li?: any,
limit?: number,
offset?: number,
// key: string,
// jwt?: string,
headers?: any,
params_json?: any,
// json_obj?: any,
params?: key_val,
return_meta?: boolean,
log_lvl?: number
}
) {
if (log_lvl) {
console.log('*** create_ae_obj_crud() ***');
console.log(`*** get_ae_obj_li_for_lu() *** for_lu_type=${for_lu_type}`);
}
let endpoint = '';
if (for_lu_type == 'country_subdivision') {
endpoint = `/crud/lu/country_subdivision/list`;
} else if (for_lu_type == 'country') {
endpoint = `/crud/lu/country/list`;
} else if (for_lu_type == 'time_zone') {
endpoint = `/crud/lu/time_zone/list`;
} else {
console.log(`Unknown object type: ${for_lu_type}`);
return false;
}
if (log_lvl) {
console.log('Endpoint:', endpoint);
}
if (order_by_li) {
headers['order_by_li'] = order_by_li;
}
let allowed_enabled_list = ['all', 'enabled', 'not_enabled']
if (allowed_enabled_list.includes(enabled) ) {
params['enabled'] = enabled;
}
let allowed_hidden_list = ['all', 'hidden', 'not_hidden'];
if (allowed_hidden_list.includes(hidden) ) {
params['hidden'] = hidden;
}
if (limit >= 0) {
params['limit'] = limit;
}
if (offset >= 0) {
params['offset'] = offset;
}
let object_li_get_promise = await api.get_object({
api_cfg: api_cfg,
endpoint: endpoint,
headers: headers,
params: params,
return_meta: return_meta,
log_lvl: log_lvl
});
if (log_lvl > 1) {
console.log(object_li_get_promise);
}
return object_li_get_promise;
}
// Updated 2023-07-24
export let create_ae_obj_crud = async function create_ae_obj_crud(
{
api_cfg,
obj_type,
field_name = null,
field_value = null,
fields = {},
key,
jwt = null,
headers = {},
params = {},
data = {},
return_obj = false,
obj_v_name = '',
return_meta = false,
log_lvl = 0
} : {
api_cfg: any,
obj_type: string,
field_name?: null|string,
field_value?: any,
fields?: key_val,
key: string,
jwt?: null|string,
headers?: key_val,
params?: key_val,
data?: key_val,
return_obj?: boolean,
obj_v_name?: string,
return_meta?: boolean,
log_lvl?: number
}
) {
if (log_lvl) {
console.log(`*** create_ae_obj_crud() *** obj_type=${obj_type}`);
}
data['super_key'] = key;
@@ -759,7 +897,33 @@ export let update_ae_obj_id_crud = async function update_ae_obj_id_crud(
// Updated 2023-11-14
export let delete_ae_obj_id_crud = async function delete_ae_obj_id_crud({api_cfg, obj_type, obj_id, key, jwt=null, headers={}, params={}, data={}, method='delete', return_meta=false, log_lvl=0}) {
export let delete_ae_obj_id_crud = async function delete_ae_obj_id_crud(
{
api_cfg,
obj_type,
obj_id,
key,
jwt=null,
headers={},
params={},
data={},
method='delete', // 'delete', 'disable', 'hide'
return_meta=false,
log_lvl=0
} : {
api_cfg: any,
obj_type: string,
obj_id: string,
key: string,
jwt?: string,
headers?: any,
params?: any,
data?: any,
method?: string,
return_meta?: boolean,
log_lvl?: number
}
) {
if (log_lvl) {
console.log(`*** delete_ae_obj_id_crud() *** obj_type: ${obj_type} obj_id: ${obj_id}`);
}
@@ -864,15 +1028,25 @@ export let delete_ae_obj_id_crud = async function delete_ae_obj_id_crud({api_cfg
/* BEGIN: Hosted File Related */
// Updated 2023-08-17
export let download_hosted_file = async function download_hosted_file({
api_cfg,
hosted_file_id,
return_file=true,
filename=null,
auto_download=false,
params={},
log_lvl=0
}) {
export let download_hosted_file = async function download_hosted_file(
{
api_cfg,
hosted_file_id,
return_file=true,
filename,
auto_download=false,
params={},
log_lvl=0
} : {
api_cfg: any,
hosted_file_id: string,
return_file?: boolean,
filename?: string,
auto_download?: boolean,
params?: key_val,
log_lvl?: number
}
) {
console.log('*** stores_hosted_api.js: download_hosted_file() ***');
let task_id = hosted_file_id;
@@ -897,8 +1071,29 @@ export let download_hosted_file = async function download_hosted_file({
return hosted_file_download_get_promise;
}
// Updated 2023-12-15
export let delete_hosted_file = async function delete_hosted_file({api_cfg, hosted_file_id, link_to_type=null, link_to_id=null, rm_orphan=false, params={}, data={}, log_lvl=1}) {
export let delete_hosted_file = async function delete_hosted_file(
{
api_cfg,
hosted_file_id,
link_to_type,
link_to_id,
rm_orphan=false,
params={},
data={},
log_lvl=1
} : {
api_cfg: any,
hosted_file_id: string,
link_to_type?: string,
link_to_id?: string,
rm_orphan?: boolean,
params?: key_val,
data?: key_val,
log_lvl?: number
}
) {
console.log('*** stores_hosted_api.js: delete_hosted_file() ***');
const endpoint = `/hosted_file/${hosted_file_id}`;
@@ -923,14 +1118,23 @@ export let delete_hosted_file = async function delete_hosted_file({api_cfg, host
// Updated 2023-06-29
export let get_data_store_obj_w_code = async function get_data_store_obj_w_code({
api_cfg,
data_store_code,
data_type='text',
headers={},
params={},
timeout=25000,
log_lvl=0
}) {
api_cfg,
data_store_code,
data_type='text',
headers={},
params={},
timeout=25000,
log_lvl=0
} : {
api_cfg: any,
data_store_code: string,
data_type?: string,
headers?: key_val,
params?: key_val,
timeout?: number,
log_lvl?: number
}
) {
if (log_lvl) {
console.log('*** get_data_store_obj_w_code() ***');
}
@@ -974,7 +1178,47 @@ export let get_data_store_obj_w_code = async function get_data_store_obj_w_code(
/* BEGIN: Utility: Email Related */
// Updated 2023-06-29
export let send_email = async function send_email({api_cfg, from_email, from_name='', to_email, to_name='', cc_email=null, cc_name=null, bcc_email=null, bcc_name=null, subject, body_html, body_text=null, headers={}, params={}, data={}, return_obj=false, return_meta=false, log_lvl=0}) {
export let send_email = async function send_email(
{
api_cfg,
from_email,
from_name='',
to_email,
to_name='',
cc_email=null,
cc_name=null,
bcc_email=null,
bcc_name=null,
subject,
body_html,
body_text=null,
headers={},
params={},
data={},
return_obj=false,
return_meta=false,
log_lvl=0
} : {
api_cfg: any,
from_email: string,
from_name?: string,
to_email: string,
to_name?: string,
cc_email?: string,
cc_name?: string,
bcc_email?: string,
bcc_name?: string,
subject: string,
body_html: string,
body_text?: string,
headers?: key_val,
params?: key_val,
data?: key_val,
return_obj?: boolean,
return_meta?: boolean,
log_lvl?: number
}
) {
console.log('*** send_email() ***');
let endpoint = `/util/email/send`;
@@ -1004,7 +1248,14 @@ export let send_email = async function send_email({api_cfg, from_email, from_nam
params['return_obj'] = true;
}
let send_email_post_promise = await api.post_object({api_cfg: api_cfg, endpoint: endpoint, headers: headers, params: params, data: data, return_meta: return_meta, log_lvl: log_lvl});
let send_email_post_promise = await api.post_object({
api_cfg: api_cfg,
endpoint: endpoint,
params: params,
data: data,
return_meta: return_meta,
log_lvl: log_lvl
});
if (log_lvl > 1) {
console.log('Response Data:', send_email_post_promise);