Getting some basic things ready for CHOW 2025
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
import type { log } from 'console';
|
||||
|
||||
import { db_sponsorships } from "$lib/ae_sponsorships/db_sponsorships";
|
||||
|
||||
// import { liveQuery } from "dexie";
|
||||
// import { db_core } from "$lib/db_core";
|
||||
@@ -15,27 +16,23 @@ 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,
|
||||
sponsorship_cfg_id,
|
||||
try_cache = false,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
sponsorship_cfg_id: string,
|
||||
try_cache: boolean,
|
||||
log_lvl: number
|
||||
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;
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** handle_load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}`);
|
||||
}
|
||||
|
||||
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',
|
||||
@@ -48,9 +45,16 @@ async function handle_load_ae_obj_id__sponsorship_cfg(
|
||||
.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}`);
|
||||
console.log(`*spons_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);
|
||||
console.log(`*spons_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}:`, sponsorship_cfg_obj_get_result);
|
||||
}
|
||||
if (try_cache) {
|
||||
// This is expecting a list
|
||||
db_save_ae_obj_li__sponsorship({
|
||||
obj_type: 'sponsorship',
|
||||
obj_li: [sponsorship_obj_get_result]
|
||||
});
|
||||
}
|
||||
return sponsorship_cfg_obj_get_result;
|
||||
} else {
|
||||
@@ -62,10 +66,89 @@ async function handle_load_ae_obj_id__sponsorship_cfg(
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__sponsorship_cfg_obj:', ae_promises.load__sponsorship_cfg_obj);
|
||||
}
|
||||
|
||||
return ae_promises.load__sponsorship_cfg_obj;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-01-15
|
||||
async function load_ae_obj_li__sponsorship(
|
||||
{
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
inc_content_li?: boolean,
|
||||
enabled?: string,
|
||||
hidden?: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
order_by_li?: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__sponsorship() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
ae_promises.load__sponsorship_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'sponsorship',
|
||||
for_obj_type: for_obj_type,
|
||||
for_obj_id: for_obj_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
use_alt_exp: false,
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (sponsorship_obj_li_get_result) {
|
||||
if (sponsorship_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__sponsorship({
|
||||
obj_type: 'sponsorship',
|
||||
obj_li: sponsorship_obj_li_get_result
|
||||
});
|
||||
}
|
||||
return sponsorship_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__sponsorship_obj_li:', ae_promises.load__sponsorship_obj_li);
|
||||
}
|
||||
|
||||
return ae_promises.load__sponsorship_obj_li;
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function handle_download_export__sponsorship(
|
||||
{
|
||||
api_cfg,
|
||||
@@ -113,8 +196,98 @@ return ae_promises.download__sponsorship_export_file;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-01-15
|
||||
export function db_save_ae_obj_li__sponsorship(
|
||||
{
|
||||
obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_type: string,
|
||||
obj_li: any,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__sponsorship() ***`);
|
||||
}
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
obj_li.forEach(async function (obj: any) {
|
||||
if (log_lvl) {
|
||||
console.log(`ae_obj ${obj_type}:`, obj);
|
||||
}
|
||||
|
||||
try {
|
||||
const id_random = await db_sponsorships.sponsorship.put({
|
||||
id: obj.sponsorship_id_random,
|
||||
sponsorship_id: obj.sponsorship_id_random,
|
||||
|
||||
account_id: obj.account_id_random,
|
||||
|
||||
external_person_id: obj.external_person_id,
|
||||
|
||||
topic_id: obj.topic_id,
|
||||
topic: obj.topic,
|
||||
topic_name: obj.topic_name,
|
||||
|
||||
name: obj.title,
|
||||
title: obj.title, // Switching to name instead of title
|
||||
// summary: obj.summary,
|
||||
content: obj.content,
|
||||
|
||||
anonymous: obj.anonymous,
|
||||
full_name: obj.full_name,
|
||||
email: obj.email,
|
||||
notify: obj.notify,
|
||||
|
||||
enable_comments: obj.enable_comments,
|
||||
|
||||
archive: obj.archive,
|
||||
archive_on: obj.archive_on,
|
||||
|
||||
linked_li_json: obj.linked_li_json,
|
||||
cfg_json: obj.cfg_json,
|
||||
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
group: obj.group,
|
||||
notes: obj.notes,
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
|
||||
tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
|
||||
tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
|
||||
|
||||
// From SQL view
|
||||
sponsorship_comment_count: obj.sponsorship_comment_count,
|
||||
|
||||
// A key value list of the comments
|
||||
// sponsorship_comment_kv: obj.sponsorship_comment_kv,
|
||||
// sponsorship_comment_li: obj.sponsorship_comment_li,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log(`Put obj with ID: ${obj.sponsorship_id_random} or ${id_random}`);
|
||||
}
|
||||
} catch (error) {
|
||||
let status = `Failed to put ${obj.sponsorship_id_random}: ${error}`;
|
||||
console.log(status);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let export_obj = {
|
||||
handle_load_ae_obj_id__sponsorship_cfg: handle_load_ae_obj_id__sponsorship_cfg,
|
||||
load_ae_obj_li__sponsorship: load_ae_obj_li__sponsorship,
|
||||
handle_download_export__sponsorship: handle_download_export__sponsorship,
|
||||
db_save_ae_obj_li__sponsorship: db_save_ae_obj_li__sponsorship
|
||||
};
|
||||
export let spons_func = export_obj;
|
||||
|
||||
Reference in New Issue
Block a user