121 lines
3.5 KiB
TypeScript
121 lines
3.5 KiB
TypeScript
import type { key_val } from '$lib/ae_stores';
|
|
import { api } from '$lib/api';
|
|
import type { log } from 'console';
|
|
|
|
// import { liveQuery } from "dexie";
|
|
// import { db_core } from "$lib/db_core";
|
|
|
|
// let example_li = liveQuery(
|
|
// () => db_core.sponsorships.toArray()
|
|
// );
|
|
|
|
let ae_promises: key_val = {}; // Promise<any>;
|
|
|
|
|
|
// Updated 2024-03-29
|
|
async function handle_load_ae_obj_id__sponsorship_cfg(
|
|
{
|
|
api_cfg,
|
|
sponsorship_cfg_id,
|
|
try_cache=false,
|
|
log_lvl=0
|
|
}: {
|
|
api_cfg: any,
|
|
sponsorship_cfg_id: string,
|
|
try_cache: boolean,
|
|
log_lvl: number
|
|
}
|
|
) {
|
|
console.log(`*** handle_load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}`);
|
|
|
|
if (!api_cfg.account_id) {
|
|
console.log(`*ae_func* No account_id found in API config!'`);
|
|
return false;
|
|
}
|
|
|
|
let params = {};
|
|
|
|
// ae_loc.hub.sponsorships.qry_status = 'loading';
|
|
ae_promises.load__sponsorship_cfg_obj = api.get_ae_obj_id_crud({
|
|
api_cfg: api_cfg,
|
|
obj_type: 'sponsorship_cfg',
|
|
obj_id: sponsorship_cfg_id,
|
|
use_alt_table: false, // 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.
|
|
params: params,
|
|
log_lvl: log_lvl
|
|
})
|
|
.then(function (sponsorship_cfg_obj_get_result) {
|
|
if (sponsorship_cfg_obj_get_result) {
|
|
if (log_lvl) {
|
|
console.log(`*ae_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}`);
|
|
} else if (log_lvl > 1) {
|
|
console.log(`*ae_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}:`, sponsorship_cfg_obj_get_result);
|
|
}
|
|
return sponsorship_cfg_obj_get_result;
|
|
} else {
|
|
console.log('No results returned.');
|
|
return null;
|
|
}
|
|
})
|
|
.catch(function (error) {
|
|
console.log('No results returned or failed.', error);
|
|
});
|
|
|
|
return ae_promises.load__sponsorship_cfg_obj;
|
|
}
|
|
|
|
|
|
async function handle_download_export__sponsorship(
|
|
{
|
|
api_cfg,
|
|
account_id,
|
|
file_type='CSV', // 'CSV' or 'Excel'
|
|
return_file=true,
|
|
filename='no_filename.csv',
|
|
auto_download=false,
|
|
params={}, // key value object is expected
|
|
log_lvl=0
|
|
}: {
|
|
api_cfg: any,
|
|
account_id: string,
|
|
file_type?: string,
|
|
return_file?: boolean,
|
|
filename?: string,
|
|
auto_download?: boolean,
|
|
params?: key_val,
|
|
log_lvl?: number
|
|
}
|
|
) {
|
|
console.log('*** stores_event_api.js: get_sponsorship_export() ***');
|
|
|
|
const endpoint = `/v2/crud/sponsorship/list`;
|
|
params['for_obj_type'] = 'account';
|
|
params['for_obj_id'] = account_id;
|
|
|
|
if (file_type == 'CSV' || file_type == 'Excel') {
|
|
params['file_type'] = file_type;
|
|
}
|
|
params['return_file'] = true;
|
|
|
|
ae_promises.download__sponsorship_export_file = await api.get_object({
|
|
api_cfg: api_cfg,
|
|
endpoint: endpoint,
|
|
params: params,
|
|
return_blob: return_file,
|
|
filename: filename,
|
|
auto_download: auto_download,
|
|
log_lvl: log_lvl
|
|
});
|
|
|
|
console.log('ae_promises.download__sponsorship_export_file:', ae_promises.download__sponsorship_export_file);
|
|
return ae_promises.download__sponsorship_export_file;
|
|
}
|
|
|
|
|
|
let export_obj = {
|
|
handle_load_ae_obj_id__sponsorship_cfg: handle_load_ae_obj_id__sponsorship_cfg,
|
|
handle_download_export__sponsorship: handle_download_export__sponsorship,
|
|
};
|
|
export let spons_func = export_obj;
|