Migrate Core modules (Account, Site, Person, Activity Log) to Aether API CRUD V3 pattern
- Created V3 logic files: ae_core__account.ts, ae_core__site.ts, ae_core__person.ts - Standardized on API -> Processor -> DB Save pattern - Added editable_fields definitions for Account, Site, Person, and Activity Log - Updated Activity Log module to use V3 wrappers - Updated Dexie schema with account, site, and site_domain tables - Added V3 tests to testing page
This commit is contained in:
14
src/lib/ae_core/ae_core__account.editable_fields.ts
Normal file
14
src/lib/ae_core/ae_core__account.editable_fields.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const editable_fields__account = [
|
||||
'code',
|
||||
'name',
|
||||
'short_name',
|
||||
'description',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes'
|
||||
];
|
||||
391
src/lib/ae_core/ae_core__account.ts
Normal file
391
src/lib/ae_core/ae_core__account.ts
Normal file
@@ -0,0 +1,391 @@
|
||||
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_core } from '$lib/ae_core/db_core';
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
export interface Account {
|
||||
id: string;
|
||||
account_id: string;
|
||||
account_id_random: string;
|
||||
|
||||
code?: string;
|
||||
name: string;
|
||||
short_name?: null | string;
|
||||
description?: null | string;
|
||||
|
||||
enable: null | boolean;
|
||||
enable_from?: null | Date;
|
||||
enable_to?: null | Date;
|
||||
|
||||
hide?: null | boolean;
|
||||
priority?: null | boolean;
|
||||
sort?: null | number;
|
||||
group?: null | string;
|
||||
notes?: null | string;
|
||||
created_on: Date;
|
||||
updated_on?: null | Date;
|
||||
|
||||
// Computed or extra fields from views
|
||||
tmp_sort_1?: string;
|
||||
tmp_sort_2?: string;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_id__account({
|
||||
api_cfg,
|
||||
account_id,
|
||||
view = 'default',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id: string;
|
||||
view?: string;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__account() *** account_id=${account_id}`);
|
||||
}
|
||||
|
||||
ae_promises.load__account_obj = await api
|
||||
.get_ae_obj_v3({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'account',
|
||||
obj_id: account_id,
|
||||
view,
|
||||
params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (account_obj_get_result) {
|
||||
if (account_obj_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__account_props({
|
||||
obj_li: [account_obj_get_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'account',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return account_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
return null;
|
||||
});
|
||||
|
||||
return ae_promises.load__account_obj;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_li__account({
|
||||
api_cfg,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
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;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__account() ***`);
|
||||
}
|
||||
|
||||
ae_promises.load__account_obj_li = await api
|
||||
.get_ae_obj_li_v3({
|
||||
api_cfg,
|
||||
obj_type: 'account',
|
||||
enabled,
|
||||
hidden,
|
||||
view,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (account_obj_li_get_result) {
|
||||
if (account_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__account_props({
|
||||
obj_li: account_obj_li_get_result,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'account',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return account_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
return ae_promises.load__account_obj_li;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function create_ae_obj__account({
|
||||
api_cfg,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__account() ***`);
|
||||
}
|
||||
|
||||
ae_promises.create__account = await api
|
||||
.create_ae_obj_v3({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'account',
|
||||
fields: data_kv,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (account_obj_create_result) {
|
||||
if (account_obj_create_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__account_props({
|
||||
obj_li: [account_obj_create_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'account',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return account_obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
return null;
|
||||
});
|
||||
|
||||
return ae_promises.create__account;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function update_ae_obj__account({
|
||||
api_cfg,
|
||||
account_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__account() *** account_id=${account_id}`, data_kv);
|
||||
}
|
||||
|
||||
const result = await api.update_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'account',
|
||||
obj_id: account_id,
|
||||
fields: data_kv,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__account_props({
|
||||
obj_li: [result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'account',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
console.error('Failed to update account.');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function delete_ae_obj_id__account({
|
||||
api_cfg,
|
||||
account_id,
|
||||
method = 'delete',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id: string;
|
||||
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id__account() *** account_id=${account_id}`);
|
||||
}
|
||||
|
||||
ae_promises.delete__account_obj = await api
|
||||
.delete_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'account',
|
||||
obj_id: account_id,
|
||||
params,
|
||||
method,
|
||||
log_lvl
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(async function () {
|
||||
if (try_cache) {
|
||||
await db_core.account.delete(account_id);
|
||||
}
|
||||
});
|
||||
|
||||
return ae_promises.delete__account_obj;
|
||||
}
|
||||
|
||||
const properties_to_save = [
|
||||
'id',
|
||||
'account_id',
|
||||
'account_id_random',
|
||||
'code',
|
||||
'name',
|
||||
'short_name',
|
||||
'description',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2'
|
||||
];
|
||||
|
||||
async function _process_generic_props<T extends Record<string, any>>({
|
||||
obj_li,
|
||||
obj_type,
|
||||
log_lvl = 0,
|
||||
specific_processor
|
||||
}: {
|
||||
obj_li: T[];
|
||||
obj_type: string;
|
||||
log_lvl?: number;
|
||||
specific_processor?: (obj: T) => Promise<T> | T;
|
||||
}): Promise<T[]> {
|
||||
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 };
|
||||
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7);
|
||||
(processed_obj as any)[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
const randomIdKey = `${obj_type}_id_random`;
|
||||
if (processed_obj[randomIdKey]) {
|
||||
(processed_obj as any).id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
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 ?? '';
|
||||
|
||||
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
}
|
||||
|
||||
processed_obj_li.push(processed_obj as T);
|
||||
}
|
||||
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
export async function process_ae_obj__account_props({
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return _process_generic_props({
|
||||
obj_li,
|
||||
obj_type: 'account',
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
22
src/lib/ae_core/ae_core__activity_log.editable_fields.ts
Normal file
22
src/lib/ae_core/ae_core__activity_log.editable_fields.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export const editable_fields__activity_log = [
|
||||
'for_type',
|
||||
'for_id',
|
||||
'for_id_random',
|
||||
'person_id',
|
||||
'person_id_random',
|
||||
'event_id',
|
||||
'event_id_random',
|
||||
'action',
|
||||
'action_with',
|
||||
'summary',
|
||||
'description',
|
||||
'data_json',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes'
|
||||
];
|
||||
30
src/lib/ae_core/ae_core__person.editable_fields.ts
Normal file
30
src/lib/ae_core/ae_core__person.editable_fields.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export const editable_fields__person = [
|
||||
'external_id',
|
||||
'external_sys_id',
|
||||
'code',
|
||||
'pronouns',
|
||||
'informal_name',
|
||||
'title_names',
|
||||
'given_name',
|
||||
'middle_name',
|
||||
'family_name',
|
||||
'designations',
|
||||
'professional_title',
|
||||
'full_name_override',
|
||||
'affiliations',
|
||||
'primary_email',
|
||||
'biography',
|
||||
'agree',
|
||||
'comments',
|
||||
'allow_auth_key',
|
||||
'passcode',
|
||||
'data_json',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes'
|
||||
];
|
||||
502
src/lib/ae_core/ae_core__person.ts
Normal file
502
src/lib/ae_core/ae_core__person.ts
Normal file
@@ -0,0 +1,502 @@
|
||||
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_core } from '$lib/ae_core/db_core';
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
export interface Person {
|
||||
id: string;
|
||||
person_id: string;
|
||||
person_id_random: string;
|
||||
|
||||
external_id?: string;
|
||||
external_sys_id?: string;
|
||||
code?: string;
|
||||
|
||||
account_id?: string;
|
||||
account_id_random?: string;
|
||||
|
||||
person_profile_id?: null | string;
|
||||
person_profile_id_random?: null | string;
|
||||
|
||||
user_id?: string;
|
||||
user_id_random?: string;
|
||||
|
||||
pronouns?: null | string;
|
||||
informal_name?: null | string;
|
||||
title_names?: null | string;
|
||||
given_name: string;
|
||||
middle_name?: null | string;
|
||||
family_name: null | string;
|
||||
designations?: null | string;
|
||||
|
||||
professional_title?: null | string;
|
||||
|
||||
full_name?: string;
|
||||
full_name_override?: null | string;
|
||||
|
||||
affiliations?: null | string;
|
||||
|
||||
primary_email?: string;
|
||||
|
||||
biography?: null | string;
|
||||
|
||||
agree?: null | boolean;
|
||||
comments?: null | string;
|
||||
|
||||
allow_auth_key?: null | boolean;
|
||||
auth_key?: null | string;
|
||||
passcode?: null | string;
|
||||
|
||||
data_json?: null | string;
|
||||
|
||||
enable: null | boolean;
|
||||
hide?: null | boolean;
|
||||
priority?: null | boolean;
|
||||
sort?: null | number;
|
||||
group?: null | string;
|
||||
notes?: null | string;
|
||||
created_on: Date;
|
||||
updated_on?: null | Date;
|
||||
|
||||
tmp_sort_1?: string;
|
||||
tmp_sort_2?: string;
|
||||
tmp_sort_3?: string;
|
||||
|
||||
// View fields
|
||||
username?: string;
|
||||
user_name?: null | string;
|
||||
user_email?: null | string;
|
||||
user_allow_auth_key?: null | boolean;
|
||||
user_super?: boolean;
|
||||
user_manager?: boolean;
|
||||
user_administrator?: boolean;
|
||||
user_public?: boolean;
|
||||
|
||||
organization_id?: null | string;
|
||||
organization_id_random?: null | string;
|
||||
organization_name?: null | string;
|
||||
|
||||
contact_id?: null | string;
|
||||
contact_id_random?: null | string;
|
||||
contact_name?: null | string;
|
||||
contact_email?: null | string;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_id__person({
|
||||
api_cfg,
|
||||
person_id,
|
||||
view = 'default',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
person_id: string;
|
||||
view?: string;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__person() *** person_id=${person_id}`);
|
||||
}
|
||||
|
||||
ae_promises.load__person_obj = await api
|
||||
.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'person',
|
||||
obj_id: person_id,
|
||||
view,
|
||||
params,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (result) {
|
||||
if (result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__person_props({
|
||||
obj_li: [result],
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'person',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
return ae_promises.load__person_obj;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_li__person({
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
qry_user_id = null,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = {
|
||||
family_name: 'ASC',
|
||||
given_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;
|
||||
qry_user_id?: string | null;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__person() *** for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
let promise;
|
||||
|
||||
if (qry_user_id) {
|
||||
const search_query: any = {
|
||||
and: [{ field: 'user_id_random', op: 'eq', value: qry_user_id }]
|
||||
};
|
||||
|
||||
if (for_obj_id) {
|
||||
search_query.and.push({
|
||||
field: `${for_obj_type}_id_random`,
|
||||
op: 'eq',
|
||||
value: for_obj_id
|
||||
});
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
promise = api.search_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'person',
|
||||
search_query,
|
||||
order_by_li,
|
||||
limit,
|
||||
offset,
|
||||
log_lvl
|
||||
});
|
||||
} else {
|
||||
promise = api.get_ae_obj_li_v3({
|
||||
api_cfg,
|
||||
obj_type: 'person',
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
enabled,
|
||||
hidden,
|
||||
view,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
ae_promises.load__person_obj_li = await promise.then(async function (result_li) {
|
||||
if (result_li) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__person_props({
|
||||
obj_li: result_li,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'person',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return result_li;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
return ae_promises.load__person_obj_li;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function create_ae_obj__person({
|
||||
api_cfg,
|
||||
account_id,
|
||||
user_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id?: string;
|
||||
user_id?: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const fields: key_val = { ...data_kv };
|
||||
if (account_id) fields.account_id_random = account_id;
|
||||
if (user_id) fields.user_id_random = user_id;
|
||||
|
||||
const result = await api.create_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'person',
|
||||
fields,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (result && try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__person_props({
|
||||
obj_li: [result],
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'person',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function update_ae_obj__person({
|
||||
api_cfg,
|
||||
person_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
person_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.update_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'person',
|
||||
obj_id: person_id,
|
||||
fields: data_kv,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (result && try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__person_props({
|
||||
obj_li: [result],
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'person',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function delete_ae_obj_id__person({
|
||||
api_cfg,
|
||||
person_id,
|
||||
method = 'delete',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
person_id: string;
|
||||
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.delete_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'person',
|
||||
obj_id: person_id,
|
||||
method,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (try_cache) {
|
||||
await db_core.person.delete(person_id);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const properties_to_save = [
|
||||
'id',
|
||||
'person_id',
|
||||
'person_id_random',
|
||||
'external_id',
|
||||
'external_sys_id',
|
||||
'code',
|
||||
'account_id',
|
||||
'account_id_random',
|
||||
'person_profile_id',
|
||||
'person_profile_id_random',
|
||||
'user_id',
|
||||
'user_id_random',
|
||||
'pronouns',
|
||||
'informal_name',
|
||||
'title_names',
|
||||
'given_name',
|
||||
'middle_name',
|
||||
'family_name',
|
||||
'designations',
|
||||
'professional_title',
|
||||
'full_name',
|
||||
'full_name_override',
|
||||
'affiliations',
|
||||
'primary_email',
|
||||
'biography',
|
||||
'agree',
|
||||
'comments',
|
||||
'allow_auth_key',
|
||||
'passcode',
|
||||
'data_json',
|
||||
'enable',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2',
|
||||
'tmp_sort_3',
|
||||
'username',
|
||||
'user_name',
|
||||
'user_email',
|
||||
'user_allow_auth_key',
|
||||
'user_super',
|
||||
'user_manager',
|
||||
'user_administrator',
|
||||
'user_public',
|
||||
'organization_id',
|
||||
'organization_id_random',
|
||||
'organization_name',
|
||||
'contact_id',
|
||||
'contact_id_random',
|
||||
'contact_name',
|
||||
'contact_email'
|
||||
];
|
||||
|
||||
async function _process_generic_props<T extends Record<string, any>>({
|
||||
obj_li,
|
||||
obj_type,
|
||||
log_lvl = 0,
|
||||
specific_processor
|
||||
}: {
|
||||
obj_li: T[];
|
||||
obj_type: string;
|
||||
log_lvl?: number;
|
||||
specific_processor?: (obj: T) => Promise<T> | T;
|
||||
}): Promise<T[]> {
|
||||
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 };
|
||||
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7);
|
||||
(processed_obj as any)[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
const randomIdKey = `${obj_type}_id_random`;
|
||||
if (processed_obj[randomIdKey]) {
|
||||
(processed_obj as any).id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
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.full_name ?? 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}`;
|
||||
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
}
|
||||
|
||||
processed_obj_li.push(processed_obj as T);
|
||||
}
|
||||
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
export async function process_ae_obj__person_props({
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return _process_generic_props({
|
||||
obj_li,
|
||||
obj_type: 'person',
|
||||
log_lvl,
|
||||
specific_processor: (obj) => {
|
||||
obj.tmp_sort_3 = `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${
|
||||
obj.family_name ?? ''
|
||||
}_${obj.given_name ?? ''}_${obj.updated_on ?? obj.created_on}`;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
23
src/lib/ae_core/ae_core__site.editable_fields.ts
Normal file
23
src/lib/ae_core/ae_core__site.editable_fields.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export const editable_fields__site = [
|
||||
'code',
|
||||
'name',
|
||||
'description',
|
||||
'restrict_access',
|
||||
'access_key',
|
||||
'access_code_kv_json',
|
||||
'logo_path',
|
||||
'logo_bg_color',
|
||||
'title',
|
||||
'tagline',
|
||||
'style_href',
|
||||
'google_tracking_id',
|
||||
'cfg_json',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes'
|
||||
];
|
||||
657
src/lib/ae_core/ae_core__site.ts
Normal file
657
src/lib/ae_core/ae_core__site.ts
Normal file
@@ -0,0 +1,657 @@
|
||||
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_core } from '$lib/ae_core/db_core';
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
export interface Site {
|
||||
id: string;
|
||||
site_id: string;
|
||||
site_id_random: string;
|
||||
account_id: string;
|
||||
account_id_random: string;
|
||||
|
||||
code?: string;
|
||||
name: string;
|
||||
description?: null | string;
|
||||
|
||||
restrict_access?: null | boolean;
|
||||
access_key?: null | string;
|
||||
access_code_kv_json?: null | string;
|
||||
|
||||
logo_path?: null | string;
|
||||
logo_bg_color?: null | string;
|
||||
title?: null | string;
|
||||
tagline?: null | string;
|
||||
style_href?: null | string;
|
||||
google_tracking_id?: null | string;
|
||||
|
||||
cfg_json?: null | string;
|
||||
|
||||
enable: null | boolean;
|
||||
enable_from?: null | Date;
|
||||
enable_to?: null | Date;
|
||||
|
||||
hide?: null | boolean;
|
||||
priority?: null | boolean;
|
||||
sort?: null | number;
|
||||
group?: null | string;
|
||||
notes?: null | string;
|
||||
created_on: Date;
|
||||
updated_on?: null | Date;
|
||||
|
||||
tmp_sort_1?: string;
|
||||
tmp_sort_2?: string;
|
||||
}
|
||||
|
||||
export interface Site_Domain {
|
||||
id: string;
|
||||
site_domain_id: string;
|
||||
site_domain_id_random: string;
|
||||
site_id: string;
|
||||
site_id_random: string;
|
||||
|
||||
domain: string;
|
||||
|
||||
enable: null | boolean;
|
||||
enable_from?: null | Date;
|
||||
enable_to?: null | Date;
|
||||
|
||||
hide?: null | boolean;
|
||||
priority?: null | boolean;
|
||||
sort?: null | number;
|
||||
group?: null | string;
|
||||
notes?: null | string;
|
||||
created_on: Date;
|
||||
updated_on?: null | Date;
|
||||
|
||||
tmp_sort_1?: string;
|
||||
tmp_sort_2?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* --- SITE CRUD ---
|
||||
*/
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_id__site({
|
||||
api_cfg,
|
||||
site_id,
|
||||
view = 'default',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
site_id: string;
|
||||
view?: string;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__site() *** site_id=${site_id}`);
|
||||
}
|
||||
|
||||
ae_promises.load__site_obj = await api
|
||||
.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'site',
|
||||
obj_id: site_id,
|
||||
view,
|
||||
params,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (site_obj_get_result) {
|
||||
if (site_obj_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__site_props({
|
||||
obj_li: [site_obj_get_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'site',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save__site,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return site_obj_get_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
return ae_promises.load__site_obj;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_li__site({
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
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;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__site() *** for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
ae_promises.load__site_obj_li = await api
|
||||
.get_ae_obj_li_v3({
|
||||
api_cfg,
|
||||
obj_type: 'site',
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
enabled,
|
||||
hidden,
|
||||
view,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (site_obj_li_get_result) {
|
||||
if (site_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__site_props({
|
||||
obj_li: site_obj_li_get_result,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'site',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save__site,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return site_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
return ae_promises.load__site_obj_li;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function create_ae_obj__site({
|
||||
api_cfg,
|
||||
account_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.create_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'site',
|
||||
fields: {
|
||||
account_id_random: account_id,
|
||||
...data_kv
|
||||
},
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (result && try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__site_props({
|
||||
obj_li: [result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'site',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save__site,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function update_ae_obj__site({
|
||||
api_cfg,
|
||||
site_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
site_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.update_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'site',
|
||||
obj_id: site_id,
|
||||
fields: data_kv,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (result && try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__site_props({
|
||||
obj_li: [result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'site',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save__site,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function delete_ae_obj_id__site({
|
||||
api_cfg,
|
||||
site_id,
|
||||
method = 'delete',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
site_id: string;
|
||||
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.delete_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'site',
|
||||
obj_id: site_id,
|
||||
method,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (try_cache) {
|
||||
await db_core.site.delete(site_id);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* --- SITE DOMAIN CRUD ---
|
||||
*/
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_li__site_domain({
|
||||
api_cfg,
|
||||
site_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = { domain: 'ASC' },
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
site_id: string;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
ae_promises.load__site_domain_li = await api
|
||||
.get_nested_obj_li_v3({
|
||||
api_cfg,
|
||||
parent_type: 'site',
|
||||
parent_id: site_id,
|
||||
child_type: 'site_domain',
|
||||
enabled,
|
||||
hidden,
|
||||
view,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (domain_li) {
|
||||
if (domain_li) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__site_domain_props({
|
||||
obj_li: domain_li,
|
||||
site_id,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'site_domain',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save__site_domain,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return domain_li;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
return ae_promises.load__site_domain_li;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function create_ae_obj__site_domain({
|
||||
api_cfg,
|
||||
site_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
site_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.create_nested_obj_v3({
|
||||
api_cfg,
|
||||
parent_type: 'site',
|
||||
parent_id: site_id,
|
||||
child_type: 'site_domain',
|
||||
fields: data_kv,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (result && try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__site_domain_props({
|
||||
obj_li: [result],
|
||||
site_id,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'site_domain',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save__site_domain,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function update_ae_obj__site_domain({
|
||||
api_cfg,
|
||||
site_id,
|
||||
site_domain_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
site_id: string;
|
||||
site_domain_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.update_nested_obj_v3({
|
||||
api_cfg,
|
||||
parent_type: 'site',
|
||||
parent_id: site_id,
|
||||
child_type: 'site_domain',
|
||||
child_id: site_domain_id,
|
||||
fields: data_kv,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (result && try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__site_domain_props({
|
||||
obj_li: [result],
|
||||
site_id,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'site_domain',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save__site_domain,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function delete_ae_obj_id__site_domain({
|
||||
api_cfg,
|
||||
site_id,
|
||||
site_domain_id,
|
||||
method = 'delete',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
site_id: string;
|
||||
site_domain_id: string;
|
||||
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const result = await api.delete_nested_ae_obj_v3({
|
||||
api_cfg,
|
||||
parent_type: 'site',
|
||||
parent_id: site_id,
|
||||
child_type: 'site_domain',
|
||||
child_id: site_domain_id,
|
||||
method,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (try_cache) {
|
||||
await db_core.site_domain.delete(site_domain_id);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const properties_to_save__site = [
|
||||
'id',
|
||||
'site_id',
|
||||
'site_id_random',
|
||||
'account_id',
|
||||
'account_id_random',
|
||||
'code',
|
||||
'name',
|
||||
'description',
|
||||
'restrict_access',
|
||||
'access_key',
|
||||
'access_code_kv_json',
|
||||
'logo_path',
|
||||
'logo_bg_color',
|
||||
'title',
|
||||
'tagline',
|
||||
'style_href',
|
||||
'google_tracking_id',
|
||||
'cfg_json',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2'
|
||||
];
|
||||
|
||||
const properties_to_save__site_domain = [
|
||||
'id',
|
||||
'site_domain_id',
|
||||
'site_domain_id_random',
|
||||
'site_id',
|
||||
'site_id_random',
|
||||
'domain',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2'
|
||||
];
|
||||
|
||||
async function _process_generic_props<T extends Record<string, any>>({
|
||||
obj_li,
|
||||
obj_type,
|
||||
log_lvl = 0,
|
||||
specific_processor
|
||||
}: {
|
||||
obj_li: T[];
|
||||
obj_type: string;
|
||||
log_lvl?: number;
|
||||
specific_processor?: (obj: T) => Promise<T> | T;
|
||||
}): Promise<T[]> {
|
||||
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 };
|
||||
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7);
|
||||
(processed_obj as any)[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
const randomIdKey = `${obj_type}_id_random`;
|
||||
if (processed_obj[randomIdKey]) {
|
||||
(processed_obj as any).id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
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 ?? processed_obj.domain ?? '';
|
||||
|
||||
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
}
|
||||
|
||||
processed_obj_li.push(processed_obj as T);
|
||||
}
|
||||
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
export async function process_ae_obj__site_props({
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return _process_generic_props({
|
||||
obj_li,
|
||||
obj_type: 'site',
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
export async function process_ae_obj__site_domain_props({
|
||||
obj_li,
|
||||
site_id,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[];
|
||||
site_id?: string;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return _process_generic_props({
|
||||
obj_li,
|
||||
obj_type: 'site_domain',
|
||||
log_lvl,
|
||||
specific_processor: (obj) => {
|
||||
if (site_id && !obj.site_id) {
|
||||
obj.site_id = site_id;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
11
src/lib/ae_core/ae_core__site_domain.editable_fields.ts
Normal file
11
src/lib/ae_core/ae_core__site_domain.editable_fields.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const editable_fields__site_domain = [
|
||||
'domain',
|
||||
'enable',
|
||||
'enable_from',
|
||||
'enable_to',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes'
|
||||
];
|
||||
@@ -3,144 +3,118 @@ import { api } from '$lib/api/api';
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
// Updated 2024-10-23
|
||||
export interface Activity_Log {
|
||||
id: string;
|
||||
activity_log_id: string;
|
||||
activity_log_id_random: string;
|
||||
account_id: string;
|
||||
account_id_random: string;
|
||||
|
||||
for_type?: string;
|
||||
for_id?: string;
|
||||
for_id_random?: string;
|
||||
|
||||
person_id?: string;
|
||||
person_id_random?: string;
|
||||
|
||||
event_id?: string;
|
||||
event_id_random?: string;
|
||||
|
||||
action: string;
|
||||
action_with?: string;
|
||||
|
||||
summary?: string;
|
||||
description?: string;
|
||||
data_json?: any;
|
||||
|
||||
enable: null | boolean;
|
||||
hide?: null | boolean;
|
||||
priority?: null | boolean;
|
||||
sort?: null | number;
|
||||
group?: null | string;
|
||||
notes?: null | string;
|
||||
created_on: Date;
|
||||
updated_on?: null | Date;
|
||||
}
|
||||
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_id__activity_log({
|
||||
api_cfg,
|
||||
activity_log_id,
|
||||
// inc_other_li = false,
|
||||
try_cache = false,
|
||||
view = 'default',
|
||||
params = {},
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
activity_log_id: string;
|
||||
// inc_other_li?: boolean,
|
||||
try_cache?: boolean;
|
||||
view?: string;
|
||||
params?: key_val;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
console.log(`*** load_ae_obj_id__activity_log() *** activity_log_id=${activity_log_id}`);
|
||||
|
||||
const params = {};
|
||||
|
||||
ae_promises.load__activity_log_obj = await api
|
||||
.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
obj_id: activity_log_id, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // 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 (activity_log_obj_get_result) {
|
||||
if (activity_log_obj_get_result) {
|
||||
// if (try_cache) {
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__activity_log({
|
||||
// obj_type: 'activity_log',
|
||||
// obj_li: [activity_log_obj_get_result]
|
||||
// });
|
||||
// }
|
||||
return activity_log_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__activity_log_obj:', ae_promises.load__activity_log_obj);
|
||||
console.log(`*** load_ae_obj_id__activity_log() *** activity_log_id=${activity_log_id}`);
|
||||
}
|
||||
|
||||
ae_promises.load__activity_log_obj = await api.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
obj_id: activity_log_id,
|
||||
view,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
return ae_promises.load__activity_log_obj;
|
||||
}
|
||||
|
||||
// Updated 2024-10-23
|
||||
// Updated 2026-01-06
|
||||
export async function load_ae_obj_li__activity_log({
|
||||
api_cfg,
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
// inc_other_li = false,
|
||||
order_by_li = {
|
||||
priority: 'DESC',
|
||||
sort: 'DESC',
|
||||
name: 'ASC',
|
||||
updated_on: 'DESC',
|
||||
created_on: 'DESC'
|
||||
},
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = { created_on: 'DESC' },
|
||||
params = {},
|
||||
try_cache = false,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
for_obj_type: string;
|
||||
for_obj_type?: string;
|
||||
for_obj_id: string;
|
||||
// inc_other_li?: boolean,
|
||||
order_by_li?: key_val;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
console.log(
|
||||
`*** load_ae_obj_li__activity_log() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`
|
||||
);
|
||||
|
||||
const enabled: string = params.qry__enabled ?? 'enabled'; // all, disabled, enabled
|
||||
const hidden: string = params.qry__hidden ?? 'not_hidden'; // all, hidden, not_hidden
|
||||
const limit: number = params.qry__limit ?? 99; // 99
|
||||
const offset: number = params.qry__offset ?? 0; // 0
|
||||
|
||||
const params_json: key_val = {};
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__activity_log_obj_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
for_obj_type: for_obj_type,
|
||||
for_obj_id: for_obj_id,
|
||||
use_alt_table: true, // 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
|
||||
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 (activity_log_obj_li_get_result) {
|
||||
if (activity_log_obj_li_get_result) {
|
||||
// if (try_cache) {
|
||||
// db_save_ae_obj_li__activity_log({
|
||||
// obj_type: 'activity_log',
|
||||
// obj_li: activity_log_obj_li_get_result
|
||||
// });
|
||||
// }
|
||||
return activity_log_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__activity_log_obj_li:',
|
||||
ae_promises.load__activity_log_obj_li
|
||||
);
|
||||
console.log(`*** load_ae_obj_li__activity_log() *** for_obj_id=${for_obj_id}`);
|
||||
}
|
||||
|
||||
ae_promises.load__activity_log_obj_li = await api.get_ae_obj_li_v3({
|
||||
api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
enabled,
|
||||
hidden,
|
||||
view,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
return ae_promises.load__activity_log_obj_li;
|
||||
}
|
||||
|
||||
// Updated 2024-10-23
|
||||
// Updated 2026-01-06
|
||||
export async function create_ae_obj__activity_log({
|
||||
api_cfg,
|
||||
account_id,
|
||||
@@ -154,224 +128,105 @@ export async function create_ae_obj__activity_log({
|
||||
params?: key_val;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
console.log(`*** create_ae_obj__activity_log() *** account_id=${account_id}`);
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__activity_log() *** account_id=${account_id}`);
|
||||
}
|
||||
|
||||
if (!account_id) {
|
||||
console.log(`ERROR: Journals - Journal - account_id required to create`);
|
||||
console.log(`ERROR: Core - Activity Log - account_id required to create`);
|
||||
return false;
|
||||
}
|
||||
|
||||
ae_promises.create__activity_log = await api
|
||||
.create_ae_obj_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
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(function (activity_log_obj_create_result) {
|
||||
if (activity_log_obj_create_result) {
|
||||
// db_save_ae_obj_li__activity_log(
|
||||
// {
|
||||
// obj_type: 'activity_log',
|
||||
// obj_li: [activity_log_obj_create_result]
|
||||
// });
|
||||
return activity_log_obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {});
|
||||
ae_promises.create__activity_log = await api.create_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
fields: {
|
||||
account_id_random: account_id,
|
||||
...data_kv
|
||||
},
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.create__activity_log:', ae_promises.create__activity_log);
|
||||
}
|
||||
return ae_promises.create__activity_log;
|
||||
}
|
||||
|
||||
// Updated 2024-10-23
|
||||
// Updated 2026-01-06
|
||||
export async function update_ae_obj__activity_log({
|
||||
api_cfg,
|
||||
activity_log_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = false,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
activity_log_id: string;
|
||||
data_kv: key_val;
|
||||
params?: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`*** update_ae_obj__activity_log() *** activity_log_id=${activity_log_id}`,
|
||||
data_kv
|
||||
);
|
||||
console.log(`*** update_ae_obj__activity_log() *** activity_log_id=${activity_log_id}`);
|
||||
}
|
||||
ae_promises.update__activity_log_obj = await api
|
||||
.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
obj_id: activity_log_id,
|
||||
fields: data_kv,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (activity_log_obj_update_result) {
|
||||
if (activity_log_obj_update_result) {
|
||||
// if (try_cache) {
|
||||
// db_save_ae_obj_li__activity_log({
|
||||
// obj_type: 'activity_log', obj_li: [activity_log_obj_update_result]
|
||||
// });
|
||||
// }
|
||||
return activity_log_obj_update_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.update__activity_log_obj:', ae_promises.update__activity_log_obj);
|
||||
}
|
||||
ae_promises.update__activity_log_obj = await api.update_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
obj_id: activity_log_id,
|
||||
fields: data_kv,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
return ae_promises.update__activity_log_obj;
|
||||
}
|
||||
|
||||
// This new function is using CRUD v2. This should allow for more flexibility in the queries.
|
||||
// Updated 2024-10-23
|
||||
// Updated 2026-01-06
|
||||
export async function qry__activity_log({
|
||||
api_cfg,
|
||||
activity_log_id,
|
||||
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 = false,
|
||||
order_by_li = { created_on: 'DESC' },
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
activity_log_id: any;
|
||||
account_id: string;
|
||||
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
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
params?: any;
|
||||
try_cache?: boolean;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'>;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
console.log(
|
||||
`*** qry__activity_log() *** activity_log_id=${activity_log_id} qry_str=${qry_str}`
|
||||
);
|
||||
const search_query: any = { and: [] };
|
||||
|
||||
// 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 (account_id) {
|
||||
search_query.and.push({ field: 'account_id_random', op: 'eq', value: account_id });
|
||||
}
|
||||
|
||||
if (qry_start_datetime) {
|
||||
const qry_param = {
|
||||
type: 'AND',
|
||||
field: 'start_datetime',
|
||||
operator: '>',
|
||||
value: qry_start_datetime
|
||||
};
|
||||
params_json['qry'].push(qry_param);
|
||||
if (qry_str) {
|
||||
search_query.q = qry_str;
|
||||
}
|
||||
|
||||
const order_by_li: { [key: string]: 'ASC' | 'DESC' }[] = [
|
||||
{ priority: 'DESC' },
|
||||
{ sort: 'DESC' },
|
||||
{ start_datetime: 'ASC' },
|
||||
{ name: 'ASC' },
|
||||
{ updated_on: 'DESC' },
|
||||
{ created_on: 'DESC' }
|
||||
];
|
||||
ae_promises.load__activity_log_obj_li = await api.search_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
search_query,
|
||||
enabled,
|
||||
hidden,
|
||||
view,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
ae_promises.load__activity_log_obj_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: activity_log_id,
|
||||
use_alt_tbl: true, // NOTE: We want to use the alt table for activity_log 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(function (activity_log_obj_li_get_result) {
|
||||
if (activity_log_obj_li_get_result) {
|
||||
// db_save_ae_obj_li__activity_log({
|
||||
// obj_type: 'activity_log',
|
||||
// obj_li: activity_log_obj_li_get_result
|
||||
// });
|
||||
return activity_log_obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
'ae_promises.load__activity_log_obj_li:',
|
||||
ae_promises.load__activity_log_obj_li
|
||||
);
|
||||
}
|
||||
return ae_promises.load__activity_log_obj_li;
|
||||
}
|
||||
}
|
||||
@@ -132,10 +132,13 @@ export interface Person {
|
||||
address_country_alpha_2_code?: null | string; // ISO 3166-1 alpha-2 country code
|
||||
}
|
||||
|
||||
// Updated 2025-01-07
|
||||
// Updated 2026-01-06
|
||||
export class MySubClassedDexie extends Dexie {
|
||||
file!: Table<File>;
|
||||
person!: Table<Person>;
|
||||
account!: Table<any>;
|
||||
site!: Table<any>;
|
||||
site_domain!: Table<any>;
|
||||
// user!: Table<User>;
|
||||
|
||||
constructor() {
|
||||
@@ -160,6 +163,23 @@ export class MySubClassedDexie extends Dexie {
|
||||
given_name, family_name,
|
||||
full_name, affiliations, email,
|
||||
agree,
|
||||
enable, hide, priority, sort, group, created_on, updated_on`,
|
||||
|
||||
account: `
|
||||
id, account_id, account_id_random,
|
||||
code, name,
|
||||
enable, hide, priority, sort, group, created_on, updated_on`,
|
||||
|
||||
site: `
|
||||
id, site_id, site_id_random,
|
||||
account_id, account_id_random,
|
||||
code, name,
|
||||
enable, hide, priority, sort, group, created_on, updated_on`,
|
||||
|
||||
site_domain: `
|
||||
id, site_domain_id, site_domain_id_random,
|
||||
site_id, site_id_random,
|
||||
domain,
|
||||
enable, hide, priority, sort, group, created_on, updated_on`
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,6 +120,107 @@
|
||||
}
|
||||
|
||||
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
import { load_ae_obj_li__account, load_ae_obj_id__account } from '$lib/ae_core/ae_core__account';
|
||||
import { load_ae_obj_li__site, load_ae_obj_id__site } from '$lib/ae_core/ae_core__site';
|
||||
import { load_ae_obj_li__person, load_ae_obj_id__person } from '$lib/ae_core/ae_core__person';
|
||||
|
||||
async function test_account_v3_load() {
|
||||
console.log('*** test_account_v3_load() ***');
|
||||
v3_test_result = 'loading...';
|
||||
|
||||
const account_li = await load_ae_obj_li__account({
|
||||
api_cfg: $ae_api,
|
||||
enabled: 'all',
|
||||
hidden: 'all',
|
||||
log_lvl: 2
|
||||
});
|
||||
|
||||
if (account_li && account_li.length > 0) {
|
||||
const first_account_id = account_li[0].account_id_random;
|
||||
console.log('Loading single account:', first_account_id);
|
||||
const account_obj = await load_ae_obj_id__account({
|
||||
api_cfg: $ae_api,
|
||||
account_id: first_account_id,
|
||||
log_lvl: 1
|
||||
});
|
||||
v3_test_result = {
|
||||
list_count: account_li.length,
|
||||
single_account: account_obj
|
||||
};
|
||||
} else {
|
||||
v3_test_result = 'No accounts found';
|
||||
}
|
||||
}
|
||||
|
||||
async function test_site_v3_load() {
|
||||
console.log('*** test_site_v3_load() ***');
|
||||
v3_test_result = 'loading...';
|
||||
|
||||
const account_id = $ae_loc.account_id;
|
||||
if (!account_id) {
|
||||
v3_test_result = 'No account_id found in $ae_loc';
|
||||
return;
|
||||
}
|
||||
|
||||
const site_li = await load_ae_obj_li__site({
|
||||
api_cfg: $ae_api,
|
||||
for_obj_id: account_id,
|
||||
enabled: 'all',
|
||||
hidden: 'all',
|
||||
log_lvl: 2
|
||||
});
|
||||
|
||||
if (site_li && site_li.length > 0) {
|
||||
const first_site_id = site_li[0].site_id_random;
|
||||
const site_obj = await load_ae_obj_id__site({
|
||||
api_cfg: $ae_api,
|
||||
site_id: first_site_id,
|
||||
log_lvl: 2
|
||||
});
|
||||
v3_test_result = {
|
||||
account_id,
|
||||
list_count: site_li.length,
|
||||
single_site: site_obj
|
||||
};
|
||||
} else {
|
||||
v3_test_result = 'No sites found for account ' + account_id;
|
||||
}
|
||||
}
|
||||
|
||||
async function test_person_v3_load() {
|
||||
console.log('*** test_person_v3_load() ***');
|
||||
v3_test_result = 'loading...';
|
||||
|
||||
const account_id = $ae_loc.account_id;
|
||||
if (!account_id) {
|
||||
v3_test_result = 'No account_id found in $ae_loc';
|
||||
return;
|
||||
}
|
||||
|
||||
const person_li = await load_ae_obj_li__person({
|
||||
api_cfg: $ae_api,
|
||||
for_obj_id: account_id,
|
||||
enabled: 'all',
|
||||
hidden: 'all',
|
||||
log_lvl: 2
|
||||
});
|
||||
|
||||
if (person_li && person_li.length > 0) {
|
||||
const first_person_id = person_li[0].person_id_random;
|
||||
const person_obj = await load_ae_obj_id__person({
|
||||
api_cfg: $ae_api,
|
||||
person_id: first_person_id,
|
||||
log_lvl: 2
|
||||
});
|
||||
v3_test_result = {
|
||||
account_id,
|
||||
list_count: person_li.length,
|
||||
single_person: person_obj
|
||||
};
|
||||
} else {
|
||||
v3_test_result = 'No persons found for account ' + account_id;
|
||||
}
|
||||
}
|
||||
|
||||
async function test_journal_module_soft_delete() {
|
||||
console.log('*** test_journal_module_soft_delete() ***');
|
||||
@@ -193,6 +294,15 @@
|
||||
<button class="btn variant-filled-success" onclick={test_journal_module_soft_delete}>
|
||||
Test Journal Module Soft Deletes
|
||||
</button>
|
||||
<button class="btn variant-filled-primary" onclick={test_account_v3_load}>
|
||||
Test Account V3 Load
|
||||
</button>
|
||||
<button class="btn variant-filled-secondary" onclick={test_site_v3_load}>
|
||||
Test Site V3 Load
|
||||
</button>
|
||||
<button class="btn variant-filled-tertiary" onclick={test_person_v3_load}>
|
||||
Test Person V3 Load
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user