Saving first versions to use the new CRUD V3 endpoints.

This commit is contained in:
Scott Idem
2026-01-02 18:27:12 -05:00
parent 2c7ed476af
commit 33d42ed85b
3 changed files with 212 additions and 203 deletions

View File

@@ -82,7 +82,7 @@ export async function load_ae_obj_id__journal_entry({
return ae_promises.load__journal_entry_obj;
}
// Updated 2025-03-15
// Updated 2026-01-02
export async function load_ae_obj_li__journal_entry({
api_cfg,
for_obj_type = 'journal',
@@ -120,33 +120,37 @@ export async function load_ae_obj_li__journal_entry({
);
}
// 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 ?? 99); // 99
// let offset: number = (params.qry__offset ?? 0); // 0
let promise;
const params_json: key_val = {};
// console('params_json:', params_json);
ae_promises.load__journal_entry_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
if (for_obj_type === 'journal' && for_obj_id) {
promise = api.get_nested_obj_li_v3({
api_cfg,
parent_type: 'journal',
parent_id: for_obj_id,
child_type: 'journal_entry',
limit,
offset,
enabled,
hidden,
order_by_li,
log_lvl
});
} else {
promise = api.get_ae_obj_li_v3({
api_cfg,
obj_type: 'journal_entry',
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,
limit,
offset,
order_by_li,
log_lvl
});
}
ae_promises.load__journal_entry_obj_li = await promise
.then(async function (journal_entry_obj_li_get_result) {
if (journal_entry_obj_li_get_result) {
if (try_cache) {
@@ -172,12 +176,6 @@ export async function load_ae_obj_li__journal_entry({
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__journal_entry({
// obj_type: 'journal_entry',
// obj_li: journal_entry_obj_li_get_result,
// log_lvl: log_lvl
// });
}
return journal_entry_obj_li_get_result;
} else {
@@ -340,8 +338,8 @@ export async function delete_ae_obj_id__journal_entry({
return ae_promises.delete__journal_entry_obj;
}
// This new function is using CRUD v2. This should allow for more flexibility in the queries.
// Updated 2025-06-04
// This new function is using CRUD V3 Search.
// Updated 2026-01-02
export async function qry__journal_entry({
api_cfg,
journal_id,
@@ -381,71 +379,55 @@ export async function qry__journal_entry({
try_cache?: boolean;
log_lvl?: number;
}) {
log_lvl = 1;
// log_lvl = 1;
if (log_lvl) {
console.log(`*** qry__journal_entry() *** journal_id=${journal_id}`);
}
const params_json: key_val = {};
params_json['qry'] = [];
const search_query: any = { and: [] };
if (qry_str) {
console.log('qry_str:', qry_str);
// let qry_param =
// {
// type: "AND",
// field: "qry_str",
// operator: "LIKE",
// value: qry_str
// };
const qry_param = {
type: '',
field: 'default_qry_str', // default is really just the standard FT string in the DB
operator: 'MATCH',
value: qry_str
};
params_json['qry'].push(qry_param);
// Using 'match' as per previous code's intent
search_query.and.push({ field: 'default_qry_str', op: 'match', value: qry_str });
}
if (qry_created_on) {
const qry_param = {
type: 'AND',
field: 'created_on',
operator: '>',
value: qry_created_on
};
params_json['qry'].push(qry_param);
search_query.and.push({ field: 'created_on', op: 'gt', value: qry_created_on });
}
if (qry_priority) {
console.log('qry_priority:', qry_priority);
const qry_param = {
type: 'AND',
field: 'priority',
operator: '=',
value: qry_priority
};
params_json['qry'].push(qry_param);
search_query.and.push({ field: 'priority', op: 'eq', value: qry_priority });
}
// Add context
if (journal_id) {
search_query.and.push({ field: 'journal_id_random', op: 'eq', value: journal_id });
}
// Add enabled/hidden filters
if (enabled === 'enabled') {
search_query.and.push({ field: 'enabled', op: 'eq', value: true });
} else if (enabled === 'not_enabled') {
search_query.and.push({ field: 'enabled', op: 'eq', value: false });
}
if (hidden === 'hidden') {
search_query.and.push({ field: 'hidden', op: 'eq', value: true });
} else if (hidden === 'not_hidden') {
search_query.and.push({ field: 'hidden', op: 'eq', value: false });
}
ae_promises.load__journal_entry_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
.search_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'journal_entry',
for_obj_type: 'journal',
for_obj_id: journal_id,
use_alt_tbl: true, // NOTE: We want to use the alt table for journal entry 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
search_query,
order_by_li,
limit,
offset,
log_lvl
})
.then(function (journal_entry_obj_li_get_result) {
if (journal_entry_obj_li_get_result) {
@@ -935,7 +917,7 @@ async function _process_generic_props<T extends Record<string, any>>({
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];
(processed_obj as any)[newKey] = processed_obj[key];
}
}
// Ensure 'id' is set from '[obj_type]_id_random'