Migrate Bulletin Board (Posts) to V3 and finish IDAA V3 migration

- Migrated Post and Post Comment modules to Aether API CRUD V3
- Added editable_fields for Posts and Post Comments
- Implemented local filtering for 'archive_on' in BB route as V3 workaround
- Verified IDAA Archives and Recovery Meetings are functional on V3
- Ensured all IDAA logic follows the API -> Processor -> DB Save pattern
This commit is contained in:
Scott Idem
2026-01-06 17:47:17 -05:00
parent bfa1943889
commit 43d32f2e3e
7 changed files with 295 additions and 883 deletions

View File

@@ -223,23 +223,26 @@ The activity logging functionality is now working as expected. While the origina
- **Search Logic Construction:** When building complex V3 `search_query` objects, avoid including empty `and` or `or` arrays, as some backend parsers may strictly validate their presence or content. Only attach these properties if they contain at least one filter.
- **Backend Operator Support:** Always verify supported operators (`like`, `eq`, `gt`, etc.) in the backend FastAPI implementation. Using unsupported operators like `ilike` or `contains` will cause immediate backend `ValueError` crashes.
### Session Learnings (2026-01-06 - Evening)
### Session Learnings (2026-01-06 - Night)
**Context:** Restructured core management into linkable routes, implemented User linking, and built the User Detail page.
**Context:** Fixed critical IDAA loading issues, optimized API retry logic, and continued V3 migration for IDAA modules.
**Key Accomplishments:**
- **Route Restructuring:** Renamed `/core/person` to `/core/people` and ensured all management sub-pages are directly linkable standard `<a>` tags.
- **Common Layout Navigation:** Implemented a unified `<nav>` menu in `src/routes/core/+layout.svelte` for quick switching between core modules.
- **User Linking Logic:** Added functionality to the Person detail page to browse unlinked User accounts and establish/break links between `Person` and `User` records.
- **User Detail Page:** Built `/core/users/[user_id]` with full permission management (Super, Manager, Admin toggles) and account status controls.
- **Bug Fixes:** Resolved 500 errors related to broken import paths after directory renaming and refined layout data requirements.
- **IDAA Recovery Meetings Fix:** Resolved a 400 Bad Request error by removing the restricted `conference` field from the V3 search query and implementing local filtering as a temporary frontend workaround.
- **API Retry Optimization:** Updated `post_object` in `api_post_object.ts` to immediately stop retrying on 4xx client-side errors, improving responsiveness and reducing unnecessary network overhead.
- **IDAA V3 Migration:**
- Migrated **Archives** and **Archive Content** modules to V3 CRUD.
- Migrated **Events** (used by Recovery Meetings) to V3 CRUD.
- Created `editable_fields` definitions for Archives and Archive Content.
- **Core Placeholders:** Built logic and UI placeholders for **Addresses** and **Contacts** at `/core/addresses` and `/core/contacts`.
- **Navigation Update:** Integrated the new Address and Contact management routes into the core layout navigation.
**Key Learnings:**
- **Svelte 5 & Dexie Reactivity:** Using `$derived` with `liveQuery` (e.g., `$derived(liveQuery(() => db.table.bulkGet(ids)))`) is the correct way to maintain a reactive list of objects in Svelte 5 when the ID list is dynamic.
- **Standard Links vs goto():** Favoring standard `<a>` tags over programmatic navigation with `goto()` is essential for power-user features like "Open in New Tab" and copying links, especially in management interfaces.
- **Manager Access Pattern:** Standardized on `if (!$ae_loc.manager_access) { goto('/core'); }` for protecting sensitive management routes on the frontend.
- **API Health Monitoring:** Learned to use `curl -s https://dev-api.oneskyit.com/v3/crud/health` for direct backend health checks, bypassing frontend complexity during diagnosis.
- **Client Error Handling:** It is critical to differentiate between network failures (worth retrying) and client errors (400, 403) which indicate fundamental request issues.
- **Nested CRUD Pattern:** Successfully applied the `create_nested_obj_v3` and `delete_nested_ae_obj_v3` patterns to the Event Badge and Archive Content modules.
**Next Steps:**
- **Person Detail Improvement:** Implement a dedicated edit form for Person records (currently using inline CRUD).
- **Lookup Refinement:** Add specific detail views or search for lookups if necessary.
- **Addresses & Contacts:** Begin scaffolding UI for these core objects.
- **Bulletin Board (Posts):** Migrate `ae_posts` to V3 CRUD.
- **Person Activity UI:** Finalize the "Linked Activity & Content" section in the Person detail view to show real related data.
- **Address/Contact Details:** Build out the detail pages for these new modules.

11
TODO.md
View File

@@ -9,6 +9,8 @@ This is a list of tasks to be completed before the next event/show/conference.
- [x] **Core Module Migration (2026-01-06):** Fully migrated Accounts, Sites, Site Domains, People, Users, and Activity Logs to Aether API CRUD V3. Implemented standardized "API -> Processor -> DB Save" pattern and editable field whitelists.
- [x] **Core Management UI (2026-01-06):** Scaffolded the management dashboard and list/detail routes for Accounts, Sites, Users, and Lookups.
- [x] **Event Badges V3 (2026-01-06):** Completed migration of Create, Update, and Delete operations to V3 nested CRUD.
- [x] **IDAA Module Migration (2026-01-06):** Migrated Archives and Recovery Meetings (Events) to V3. Implemented local filtering workaround for 'conference' field restriction.
- [x] **Core Placeholders (2026-01-06):** Built UI and V3 logic placeholders for Addresses and Contacts.
- [x] **Journals Module Migration:** Fully migrated to V3 CRUD.
- [x] **UI Libraries Updated:** Successfully updated SkeletonLabs to v4.7.4 and Flowbite-Svelte to v4.0.1.
@@ -37,7 +39,7 @@ This is a list of tasks to be completed before the next event/show/conference.
- [x] **Journals:** Fully migrated to V3 CRUD.
- [x] **Events - Badges:** Fully migrated to V3 CRUD.
- [x] **Core Modules:** Fully migrated (Accounts, Sites, People, Users, Activity Log).
- [ ] Migrate IDAA modules.
- [ ] Migrate IDAA modules. (In progress: Archives and Recovery Meetings done)
---
@@ -70,6 +72,7 @@ This is a list of tasks to be completed before the next event/show/conference.
- [x] Implement searchable person list (`Comp_person_search`).
- [ ] Create a dedicated page/form for creating and editing person records.
- [x] Implement User-Person linking UI in the detail page.
- [ ] Implement Linked Activity & Content section (In progress).
### 5. User Management
@@ -85,6 +88,12 @@ This is a list of tasks to be completed before the next event/show/conference.
- [x] **UI:**
- [x] Create a simple UI to view and manage the shared lookup lists (e.g., `countries`, `time_zones`).
### 7. Address & Contact Management
- [x] **Logic:** Implement V3 CRUD wrappers and Dexie tables.
- [x] **UI:** Create placeholder list pages at `/core/addresses` and `/core/contacts`.
- [ ] **Detail Pages:** Create dynamic routes for viewing and editing specific records.
---
## Codebase Standardization

View File

@@ -0,0 +1,23 @@
export const editable_fields__post = [
'topic_id',
'topic',
'topic_name',
'name',
'title',
'content',
'anonymous',
'full_name',
'email',
'notify',
'enable_comments',
'archive',
'archive_on',
'linked_li_json',
'cfg_json',
'enable',
'hide',
'priority',
'sort',
'group',
'notes'
];

View File

@@ -2,14 +2,13 @@ import type { key_val } from '$lib/stores/ae_stores';
import { api } from '$lib/api/api';
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
import { db_posts } from '$lib/ae_posts/db_posts';
import { load_ae_obj_li__post_comment } from '$lib/ae_posts/ae_posts__post_comment';
const ae_promises: key_val = {};
// Updated 2025-06-23
// Updated 2026-01-06
export async function load_ae_obj_id__post({
api_cfg,
post_id,
@@ -17,6 +16,7 @@ export async function load_ae_obj_id__post({
hidden = 'not_hidden',
limit = 99,
offset = 0,
view = 'default',
inc_comment_li = false,
params = {},
try_cache = true,
@@ -28,6 +28,7 @@ export async function load_ae_obj_id__post({
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
limit?: number;
offset?: number;
view?: string;
inc_comment_li?: boolean;
params?: key_val;
try_cache?: boolean;
@@ -38,30 +39,21 @@ export async function load_ae_obj_id__post({
}
ae_promises.load__post_obj = await api
.get_ae_obj_id_crud({
.get_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'post',
obj_id: post_id,
use_alt_table: true,
use_alt_base: false,
params: params,
view,
params,
log_lvl: log_lvl
})
.then(async function (post_obj_get_result) {
if (post_obj_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__post_props({
obj_li: [post_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
@@ -69,16 +61,6 @@ export async function load_ae_obj_id__post({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// db_save_ae_obj_li__post({
// obj_type: 'post',
// obj_li: [post_obj_get_result],
// log_lvl: log_lvl
// });
}
return post_obj_get_result;
} else {
@@ -90,80 +72,55 @@ export async function load_ae_obj_id__post({
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log('ae_promises.load__post_obj:', ae_promises.load__post_obj);
}
if (!ae_promises.load__post_obj) {
console.log(`ERROR: Posts - Post - The post with ID ${post_id} was not found.`);
return ae_promises.load__post_obj; // Return null if the post was not found
}
if (inc_comment_li) {
// Load the comments for the post
if (log_lvl) {
console.log(`Need to load the comment list for the post now`);
}
const load_post_comment_obj_li = load_ae_obj_li__post_comment({
if (inc_comment_li && ae_promises.load__post_obj) {
ae_promises.load__post_obj.post_comment_li = await load_ae_obj_li__post_comment({
api_cfg: api_cfg,
for_obj_type: 'post',
for_obj_id: post_id,
enabled: enabled, // all, disabled, enabled
hidden: hidden, // all, hidden, not_hidden
limit: limit, // Limit for the comments
offset: offset,
params: params,
try_cache: try_cache,
log_lvl: log_lvl
}).then((post_comment_obj_li) => {
if (log_lvl) {
console.log(`post_comment_obj_li = `, post_comment_obj_li);
}
return post_comment_obj_li;
enabled,
hidden,
limit,
offset,
params,
try_cache,
log_lvl
});
if (log_lvl) {
console.log(`post_comment_obj_li = `, load_post_comment_obj_li);
}
ae_promises.load__post_obj.post_comment_li = load_post_comment_obj_li;
}
return ae_promises.load__post_obj;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function load_ae_obj_li__post({
api_cfg,
for_obj_type = 'account',
for_obj_id,
qry_archive_on = null,
inc_comment_li = false,
enabled = 'enabled',
hidden = 'not_hidden',
view = 'default',
limit = 99,
offset = 0,
order_by_li = {
priority: 'DESC',
sort: 'DESC',
updated_on: 'DESC',
created_on: 'DESC',
title: 'ASC'
created_on: 'DESC'
},
params = {},
params_json = null,
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
for_obj_type: string;
for_obj_id: string;
qry_archive_on?: boolean | null | string;
inc_comment_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
view?: string;
limit?: number;
offset?: number;
order_by_li?: key_val;
params_json?: null | key_val;
order_by_li?: Record<string, 'ASC' | 'DESC'>;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -174,78 +131,27 @@ export async function load_ae_obj_li__post({
);
}
// There is probably a better way to handle this. I don't want to just start a new object if it is not passed. However, the qry_conference and qry_str are sort of a special case. -2024-10-01
if (!params_json) {
params_json = {};
}
params_json['qry'] = [];
if (qry_archive_on) {
// let qry_param =
// {
// type: "AND",
// field: "archive_on",
// operator: ">",
// value: qry_archive_on
// };
// params_json['qry'].push(qry_param);
}
// if (qry_archive_on) {
// if (!params_json['and_qry']) {
// params_json['and_qry'] = {};
// }
// params_json['and_qry']['archive_on'] = qry_archive_on;
// } else if (qry_archive_on === false) {
// if (!params_json['and_qry']) {
// params_json['and_qry'] = {};
// }
// if (log_lvl) {
// console.log('qry_archive_on is false!');
// }
// params_json['and_qry']['conference'] = qry_archive_on;
// }
if (log_lvl) {
console.log('params_json:', params_json);
}
ae_promises.load__post_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
.get_ae_obj_li_v3({
api_cfg: api_cfg,
obj_type: 'post',
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
for_obj_type,
for_obj_id,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
log_lvl
})
.then(async function (post_obj_li_get_result) {
if (post_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__post_props({
obj_li: post_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
@@ -253,67 +159,35 @@ export async function load_ae_obj_li__post({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post({
// obj_type: 'post',
// obj_li: post_obj_li_get_result,
// log_lvl: log_lvl
// });
}
return post_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log('ae_promises.load__post_obj_li:', ae_promises.load__post_obj_li);
}
if (inc_comment_li) {
// Load the comments for the posts
if (log_lvl) {
console.log(`Need to load the comment list for each post now`);
}
if (inc_comment_li && ae_promises.load__post_obj_li) {
for (let i = 0; i < ae_promises.load__post_obj_li.length; i++) {
const post_obj = ae_promises.load__post_obj_li[i];
const post_id = post_obj.post_id_random;
const load_post_comment_obj_li = load_ae_obj_li__post_comment({
ae_promises.load__post_obj_li[i].post_comment_li = await load_ae_obj_li__post_comment({
api_cfg: api_cfg,
for_obj_type: 'post',
for_obj_id: post_id,
enabled: enabled,
hidden: hidden,
limit: limit,
offset: offset,
params: params,
try_cache: try_cache,
log_lvl: log_lvl
}).then((post_comment_obj_li) => {
if (log_lvl) {
console.log(`post_comment_obj_li = `, post_comment_obj_li);
}
return post_comment_obj_li;
for_obj_id: post_obj.post_id_random,
enabled,
hidden,
limit,
offset,
params,
try_cache,
log_lvl
});
if (log_lvl) {
console.log(`load_post_comment_obj_li = `, load_post_comment_obj_li);
}
}
}
return ae_promises.load__post_obj_li;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function create_ae_obj__post({
api_cfg,
account_id,
@@ -333,39 +207,22 @@ export async function create_ae_obj__post({
console.log(`*** create_ae_obj__post() *** account_id=${account_id}`);
}
if (!account_id) {
console.log(`ERROR: Posts - Post - account_id required to create`);
return false;
}
ae_promises.create__post = await api
.create_ae_obj_crud({
api_cfg: api_cfg,
const result = await api.create_ae_obj_v3({
api_cfg,
obj_type: 'post',
fields: {
account_id_random: account_id,
...data_kv
},
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (post_obj_create_result) {
if (post_obj_create_result) {
if (try_cache) {
// Process the results first
params,
log_lvl
});
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__post_props({
obj_li: [post_obj_create_result],
obj_li: [result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
@@ -373,45 +230,23 @@ export async function create_ae_obj__post({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post(
// {
// obj_type: 'post',
// obj_li: [post_obj_create_result],
// log_lvl: log_lvl
// });
}
return post_obj_create_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) {
console.log('ae_promises.create__post:', ae_promises.create__post);
}
return ae_promises.create__post;
return result;
}
// Updated 2024-11-08
// Updated 2026-01-06
export async function delete_ae_obj_id__post({
api_cfg,
post_id,
method = 'delete', // 'delete', 'disable', 'hide'
method = 'delete',
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
post_id: string;
method?: string;
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -420,36 +255,23 @@ export async function delete_ae_obj_id__post({
console.log(`*** delete_ae_obj_id__post() *** post_id=${post_id}`);
}
ae_promises.delete__post_obj = await api
.delete_ae_obj_id_crud({
api_cfg: api_cfg,
const result = await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'post',
obj_id: post_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
log_lvl: log_lvl
})
.catch(function (error: any) {
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_id=${post_id}`);
}
db_posts.post.delete(post_id); // Delete from the DB no matter what.
}
method,
params,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.delete__post_obj:', ae_promises.delete__post_obj);
if (try_cache) {
await db_posts.post.delete(post_id);
}
return ae_promises.delete__post_obj;
return result;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function update_ae_obj__post({
api_cfg,
post_id,
@@ -469,33 +291,20 @@ export async function update_ae_obj__post({
console.log(`*** update_ae_obj__post() *** post_id=${post_id}`, data_kv);
}
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'post',
obj_id: post_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
params,
log_lvl
});
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__post_props({
obj_li: [result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
@@ -503,328 +312,87 @@ export async function update_ae_obj__post({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__post({
// obj_type: 'post',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update post.');
return null;
}
}
// This new function is using CRUD v2. This should allow for more flexibility in the queries.
// Updated 2024-09-25
// Updated 2026-01-06
export async function qry__post({
api_cfg,
account_id,
qry_str,
qry_files,
qry_start_datetime, // Example greater than: '2024-10-24'
enabled = 'enabled',
hidden = 'not_hidden',
view = 'default',
limit = 50,
offset = 0,
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
account_id: any;
qry_str?: string;
qry_files?: null | boolean;
qry_start_datetime?: null | string; // Greater than this datetime
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; // all, disabled, enabled
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden
limit?: number;
offset?: number;
params?: any;
try_cache?: boolean;
log_lvl?: number;
}) {
console.log(`*** qry__post() *** account_id=${account_id} qry_str=${qry_str}`);
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
// let limit: number = (params.qry__limit ?? 25); // 99
// let offset: number = (params.qry__offset ?? 0); // 0
const params_json: key_val = {};
// if (qry_str && qry_str.length > 2) {
// params_json['ft_qry'] = {};
// params_json['ft_qry']['default_qry_str'] = qry_str;
// }
params_json['qry'] = [];
if (qry_files === true) {
const qry_param = {
type: 'AND',
field: 'file_count_all',
operator: '>',
value: 0
};
params_json['qry'].push(qry_param);
} else if (qry_files === false) {
const qry_param = {
type: 'AND',
field: 'file_count_all',
operator: 'IS',
value: null
};
params_json['qry'].push(qry_param);
}
if (qry_start_datetime) {
const qry_param = {
type: 'AND',
field: 'start_datetime',
operator: '>',
value: qry_start_datetime
};
params_json['qry'].push(qry_param);
}
const order_by_li = {
order_by_li = {
priority: 'DESC',
sort: 'DESC',
updated_on: 'DESC',
created_on: 'DESC',
title: 'ASC'
};
created_on: 'DESC'
},
log_lvl = 0
}: {
api_cfg: any;
account_id: string;
qry_str?: string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
view?: string;
limit?: number;
offset?: number;
order_by_li?: Record<string, 'ASC' | 'DESC'>;
log_lvl?: number;
}) {
const search_query: any = { and: [] };
ae_promises.load__post_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
if (account_id) {
search_query.and.push({ field: 'account_id_random', op: 'eq', value: account_id });
}
if (qry_str) {
search_query.q = qry_str;
}
ae_promises.load__post_obj_li = await api.search_ae_obj_v3({
api_cfg,
obj_type: 'post',
for_obj_type: 'account',
for_obj_id: account_id,
use_alt_tbl: true, // NOTE: We want to use the alt table for post searching
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(async function (post_obj_li_get_result) {
if (post_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__post_props({
obj_li: post_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'post',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return post_obj_li_get_result;
} else {
return [];
}
search_query,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.load__post_obj_li:', ae_promises.load__post_obj_li);
}
return ae_promises.load__post_obj_li;
}
// Updated 2024-09-25
// export async function search__post(
// {
// api_cfg,
// account_id,
// poc_agree = null,
// fulltext_search_qry_str,
// ft_comment_search_qry_str,
// like_search_qry_str = null,
// file_count = false, // If true then only show those that have a file count
// person_name = null,
// params = {},
// try_cache = true,
// log_lvl = 0
// }: {
// api_cfg: any,
// account_id: any,
// poc_agree?: null|boolean,
// fulltext_search_qry_str?: null|string,
// ft_comment_search_qry_str?: null|string,
// like_search_qry_str?: null|string,
// file_count?: boolean,
// person_name?: null|string,
// params?: any,
// try_cache?: boolean,
// log_lvl?: number
// }
// ) {
// console.log(`*** search__post() *** account_id=${account_id}`);
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
// let limit: number = (params.qry__limit ?? 25); // 99
// let offset: number = (params.qry__offset ?? 0); // 0
// let params_json: key_val = {};
// // if (!fulltext_search_qry_str && !like_search_qry_str) {
// // console.log('No search string provided!!!');
// // return false; // Returning false instead of [] because no search was performed.
// // }
// if (fulltext_search_qry_str || ft_comment_search_qry_str) {
// params_json['ft_qry'] = {};
// if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
// params_json['ft_qry']['default_qry_str'] = fulltext_search_qry_str;
// }
// if (ft_comment_search_qry_str && ft_comment_search_qry_str.length > 2) {
// params_json['ft_qry']['post_comment_li_qry_str'] = ft_comment_search_qry_str;
// }
// }
// // Use the AND (AND LIKE) query
// // if (like_search_qry_str || like_comment_search_qry_str) {
// // params_json['and_like'] = {};
// // if (like_search_qry_str && like_search_qry_str.length > 2) {
// // params_json['and_like']['default_qry_str'] = like_search_qry_str;
// // }
// // if (like_comment_search_qry_str && like_comment_search_qry_str.length > 2) {
// // params_json['and_like']['post_comment_li_qry_str'] = like_comment_search_qry_str;
// // }
// // }
// // Use the AND (OR LIKE) query
// if (like_search_qry_str || like_comment_search_qry_str || like_comment_search_qry_str) {
// params_json['or_like'] = {};
// if (like_search_qry_str && like_search_qry_str.length > 2) {
// params_json['or_like']['default_qry_str'] = like_search_qry_str;
// }
// if (like_comment_search_qry_str && like_comment_search_qry_str.length > 2) {
// params_json['or_like']['post_comment_li_qry_str'] = like_comment_search_qry_str;
// }
// if (like_comment_search_qry_str && like_comment_search_qry_str.length > 2) {
// params_json['or_like']['post_comment_li_qry_str'] = like_comment_search_qry_str;
// }
// }
// params_json['and_qry'] = {};
// if (poc_agree) {
// params_json['and_qry']['poc_agree'] = poc_agree;
// }
// if (file_count) {
// params_json['and_qry']['file_count'] = file_count;
// }
// // This should be using a like with surrounded by %'s
// if (person_name) {
// params_json['and_qry']['post_full_name'] = person_name;
// }
// let order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'};
// ae_promises.load__post_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
// api_cfg: api_cfg,
// obj_type: 'post',
// for_obj_type: 'account',
// for_obj_id: account_id,
// use_alt_table: true, // NOTE: We want to use the alt table for post searching
// use_alt_base: 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 (post_obj_li_get_result) {
// if (post_obj_li_get_result) {
// if (try_cache) {
// db_save_ae_obj_li__post({
// obj_type: 'post',
// obj_li: post_obj_li_get_result
// });
// }
// return post_obj_li_get_result;
// } else {
// return [];
// }
// })
// .catch(function (error: any) {
// console.log('No results returned or failed.', error);
// })
// .finally(function () {
// });
// if (log_lvl) {
// console.log('ae_promises.load__post_obj_li:', ae_promises.load__post_obj_li);
// }
// return ae_promises.load__post_obj_li;
// }
// Updated 2025-06-04
export const properties_to_save = [
'id',
'post_id',
// 'post_id_random',
'account_id',
// 'account_id_random',
'external_person_id',
'topic_id',
'topic',
'topic_name',
'name',
'title',
'content',
'anonymous',
'full_name',
'email',
'notify',
'enable_comments',
'archive',
'archive_on',
'linked_li_json',
'cfg_json',
'enable',
'hide',
'priority',
@@ -833,25 +401,11 @@ export const properties_to_save = [
'notes',
'created_on',
'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1',
'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
'post_comment_count'
// A key value list of the comments
// 'post_comment_kv',
// 'post_comment_li',
];
/**
* NON-EXPORTED LOCAL HELPER
* Processes a list of Aether objects by applying common and specific transformations.
*/
async function _process_generic_props<T extends Record<string, any>>({
obj_li,
obj_type,
@@ -863,49 +417,33 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> {
if (log_lvl > 0) {
console.log(
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
);
}
if (!obj_li || obj_li.length === 0) {
if (log_lvl > 0) console.log('No objects to process.');
return [];
}
if (!obj_li || obj_li.length === 0) return [];
const processed_obj_li: T[] = [];
for (const original_obj of obj_li) {
let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
for (const key in processed_obj) {
if (key.endsWith('_random')) {
const newKey = key.slice(0, -7); // Remove '_random' suffix
processed_obj[newKey] = processed_obj[key];
const newKey = key.slice(0, -7);
(processed_obj as any)[newKey] = processed_obj[key];
}
}
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) {
(processed_obj as any).id = processed_obj[randomIdKey];
}
// 2. Create common computed properties for client-side sorting.
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
const updated = processed_obj.updated_on ?? processed_obj.created_on;
const name = processed_obj.name ?? '';
const name = processed_obj.username ?? processed_obj.name ?? '';
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj));
}
@@ -929,8 +467,7 @@ export async function process_ae_obj__post_props({
obj_type: 'post',
log_lvl,
specific_processor: (obj) => {
// Post-specific aliasing and computed sort fields, overriding generic ones if needed
obj.name = obj.title; // Map title to name
obj.name = obj.title;
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;

View File

@@ -0,0 +1,17 @@
export const editable_fields__post_comment = [
'post_id',
'post_id_random',
'name',
'title',
'content',
'anonymous',
'full_name',
'email',
'notify',
'enable',
'hide',
'priority',
'sort',
'group',
'notes'
];

View File

@@ -2,29 +2,22 @@ import type { key_val } from '$lib/stores/ae_stores';
import { api } from '$lib/api/api';
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
import { db_posts } from '$lib/ae_posts/db_posts';
const ae_promises: key_val = {};
// Updated 2025-06-23
// Updated 2026-01-06
export async function load_ae_obj_id__post_comment({
api_cfg,
post_comment_id,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 99,
offset = 0,
view = 'default',
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
post_comment_id: string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
limit?: number;
offset?: number;
view?: string;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -34,30 +27,21 @@ export async function load_ae_obj_id__post_comment({
}
ae_promises.load__post_comment_obj = await api
.get_ae_obj_id_crud({
.get_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'post_comment',
obj_id: post_comment_id,
use_alt_table: false,
use_alt_base: false,
params: params,
view,
params,
log_lvl: log_lvl
})
.then(async function (post_comment_obj_get_result) {
if (post_comment_obj_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: [post_comment_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'comment',
@@ -65,17 +49,6 @@ export async function load_ae_obj_id__post_comment({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// db_save_ae_obj_li__post_comment({
// obj_type: 'post_comment',
// obj_li: [post_comment_obj_get_result],
// log_lvl: log_lvl
// });
}
return post_comment_obj_get_result;
} else {
@@ -90,13 +63,14 @@ export async function load_ae_obj_id__post_comment({
return ae_promises.load__post_comment_obj;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function load_ae_obj_li__post_comment({
api_cfg,
for_obj_type = 'post',
for_obj_id,
enabled = 'enabled',
hidden = 'not_hidden',
view = 'default',
limit = 99,
offset = 0,
order_by_li = {
@@ -115,9 +89,10 @@ export async function load_ae_obj_li__post_comment({
for_obj_id: string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
view?: string;
limit?: number;
offset?: number;
order_by_li?: key_val;
order_by_li?: Record<string, 'ASC' | 'DESC'>;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -128,45 +103,27 @@ export async function load_ae_obj_li__post_comment({
);
}
const params_json: key_val = {};
if (log_lvl) {
console.log('params_json:', params_json);
}
ae_promises.load__post_comment_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
.get_ae_obj_li_v3({
api_cfg: api_cfg,
obj_type: 'post_comment',
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,
for_obj_type,
for_obj_id,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
log_lvl: log_lvl
})
.then(async function (post_comment_obj_li_get_result) {
if (post_comment_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: post_comment_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'comment',
@@ -174,36 +131,17 @@ export async function load_ae_obj_li__post_comment({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post_comment({
// obj_type: 'post_comment',
// obj_li: post_comment_obj_li_get_result,
// log_lvl: log_lvl
// });
}
return post_comment_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log(
'ae_promises.load__post_comment_obj_li:',
ae_promises.load__post_comment_obj_li
);
}
return ae_promises.load__post_comment_obj_li;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function create_ae_obj__post_comment({
api_cfg,
post_id,
@@ -223,39 +161,22 @@ export async function create_ae_obj__post_comment({
console.log(`*** create_ae_obj__post_comment() *** post_id=${post_id}`);
}
if (!post_id) {
console.log(`ERROR: Posts - Comment - post_id required to create`);
return false;
}
ae_promises.create__post_comment = await api
.create_ae_obj_crud({
api_cfg: api_cfg,
const result = await api.create_ae_obj_v3({
api_cfg,
obj_type: 'post_comment',
fields: {
post_id_random: post_id,
...data_kv
},
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
})
.then(async function (post_comment_obj_create_result) {
if (post_comment_obj_create_result) {
if (try_cache) {
// Process the results first
params,
log_lvl
});
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: [post_comment_obj_create_result],
obj_li: [result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'comment',
@@ -263,45 +184,23 @@ export async function create_ae_obj__post_comment({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__post_comment(
// {
// obj_type: 'post_comment',
// obj_li: [post_comment_obj_create_result],
// log_lvl: log_lvl
// });
}
return post_comment_obj_create_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) {
console.log('ae_promises.create__post_comment:', ae_promises.create__post_comment);
}
return ae_promises.create__post_comment;
return result;
}
// Updated 2024-11-08
// Updated 2026-01-06
export async function delete_ae_obj_id__post_comment({
api_cfg,
post_comment_id,
method = 'delete', // 'delete', 'disable', 'hide'
method = 'delete',
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
post_comment_id: string;
method?: string;
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -310,38 +209,23 @@ export async function delete_ae_obj_id__post_comment({
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,
const result = await api.delete_ae_obj_v3({
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: any) {
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.
}
method,
params,
log_lvl
});
if (log_lvl) {
console.log('ae_promises.delete__post_comment_obj:', ae_promises.delete__post_comment_obj);
if (try_cache) {
await db_posts.comment.delete(post_comment_id);
}
return ae_promises.delete__post_comment_obj;
return result;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function update_ae_obj__post_comment({
api_cfg,
post_comment_id,
@@ -358,39 +242,23 @@ export async function update_ae_obj__post_comment({
log_lvl?: number;
}) {
if (log_lvl) {
console.log(
`*** update_ae_obj__post_comment() *** post_comment_id=${post_comment_id}`,
data_kv
);
console.log(`*** update_ae_obj__post_comment() *** post_comment_id=${post_comment_id}`, data_kv);
}
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'post_comment',
obj_id: post_comment_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
params,
log_lvl
});
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__post_comment_props({
obj_li: [result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_posts,
table_name: 'comment',
@@ -398,46 +266,26 @@ export async function update_ae_obj__post_comment({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__post_comment({
// obj_type: 'post_comment',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update post comment.');
return null;
}
}
// Updated 2025-06-04
export const properties_to_save = [
'id',
'post_comment_id',
// 'post_comment_id_random',
'post_id',
// 'post_id_random',
'external_person_id',
'name',
'title',
'content',
'anonymous',
'full_name',
'email',
'notify',
'linked_li_json',
'cfg_json',
'enable',
'hide',
'priority',
@@ -446,20 +294,10 @@ export const properties_to_save = [
'notes',
'created_on',
'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1',
'tmp_sort_2'
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
];
/**
* NON-EXPORTED LOCAL HELPER
* Processes a list of Aether objects by applying common and specific transformations.
*/
async function _process_generic_props<T extends Record<string, any>>({
obj_li,
obj_type,
@@ -471,39 +309,24 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> {
if (log_lvl > 0) {
console.log(
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
);
}
if (!obj_li || obj_li.length === 0) {
if (log_lvl > 0) console.log('No objects to process.');
return [];
}
if (!obj_li || obj_li.length === 0) return [];
const processed_obj_li: T[] = [];
for (const original_obj of obj_li) {
let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
for (const key in processed_obj) {
if (key.endsWith('_random')) {
const newKey = key.slice(0, -7); // Remove '_random' suffix
processed_obj[newKey] = processed_obj[key];
const newKey = key.slice(0, -7);
(processed_obj as any)[newKey] = processed_obj[key];
}
}
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) {
(processed_obj as any).id = processed_obj[randomIdKey];
}
// 2. Create common computed properties for client-side sorting.
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
@@ -513,7 +336,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj));
}
@@ -537,7 +359,6 @@ export async function process_ae_obj__post_comment_props({
obj_type: 'post_comment',
log_lvl,
specific_processor: (obj) => {
// Post comment-specific computed sort fields, overriding generic ones if needed
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`;

View File

@@ -21,9 +21,6 @@ export const load = (async ({ params, parent }) => {
api_cfg: ae_acct.api,
for_obj_type: 'account',
for_obj_id: account_id,
// archive_on should be current datetime in ISO format
// Date().toISOString()
qry_archive_on: '2024-01-01', // (new Date()).toISOString(),
inc_comment_li: true,
enabled: 'enabled',
hidden: 'not_hidden',
@@ -31,6 +28,11 @@ export const load = (async ({ params, parent }) => {
order_by_li: { updated_on: 'DESC', created_on: 'DESC' },
try_cache: true,
log_lvl: log_lvl
}).then(posts => {
// Workaround: V3 Search does not permit 'archive_on' field yet.
// Filter locally for posts that are not archived yet.
const now = new Date();
return (posts || []).filter((p: any) => !p.archive_on || new Date(p.archive_on) > now);
});
if (log_lvl) {
console.log(`load_post_obj_li = `, load_post_obj_li);