Wrapping up for the day. Now with ability to add a person.
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_core } from "$lib/db_core";
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
|
||||
// Updated 2024-06-24
|
||||
export async function handle_create_ae_obj__person(
|
||||
{
|
||||
api_cfg,
|
||||
user_id,
|
||||
data_kv,
|
||||
params={},
|
||||
log_lvl=0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
user_id?: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
console.log(`*** handle_create_ae_obj__person() *** user_id=${user_id}`);
|
||||
|
||||
ae_promises.create__person = await api.create_ae_obj_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'person',
|
||||
fields: {
|
||||
user_id_random: user_id,
|
||||
...data_kv
|
||||
},
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params: params,
|
||||
return_obj: true,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (person_obj_create_result) {
|
||||
if (person_obj_create_result) {
|
||||
handle_db_save_ae_obj_li__person(
|
||||
{
|
||||
obj_type: 'person', obj_li: [person_obj_create_result]
|
||||
});
|
||||
return person_obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.create__person:', ae_promises.create__person);
|
||||
}
|
||||
return ae_promises.create__person;
|
||||
}
|
||||
|
||||
// Updated 2024-06-10
|
||||
export function handle_db_save_ae_obj_li__person(
|
||||
{
|
||||
obj_type,
|
||||
obj_li
|
||||
}: {
|
||||
obj_type: string,
|
||||
obj_li: any
|
||||
}
|
||||
) {
|
||||
console.log(`*** handle_db_save_ae_obj_li__person() ***`);
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
obj_li.forEach(async function (obj: any) {
|
||||
// console.log(`ae_obj ${obj_type}:`, obj);
|
||||
|
||||
try {
|
||||
const id_random = await db_core.person.put({
|
||||
id: obj.person_id_random,
|
||||
// id_random: obj.person_id_random,
|
||||
person_id: obj.person_id_random,
|
||||
person_id_random: obj.person_id_random,
|
||||
|
||||
external_id: obj.external_id,
|
||||
// code: obj.code,
|
||||
|
||||
account_id: obj.account_id_random,
|
||||
|
||||
person_profile_id: obj.person_profile_id_random,
|
||||
person_profile_id_random: obj.person_profile_id_random, // The new table person_profile will be used soon...
|
||||
|
||||
user_id: obj.user_id_random,
|
||||
|
||||
pronouns: obj.pronouns,
|
||||
informal_name: obj.informal_name,
|
||||
title_names: obj.title_names,
|
||||
given_name: obj.given_name,
|
||||
middle_name: obj.middle_name,
|
||||
family_name: obj.family_name,
|
||||
designations: obj.designations,
|
||||
|
||||
professional_title: obj.professional_title,
|
||||
|
||||
full_name: obj.full_name,
|
||||
|
||||
affiliations: obj.affiliations,
|
||||
|
||||
primary_email: obj.primary_email,
|
||||
|
||||
biography: obj.biography,
|
||||
|
||||
agree: obj.agree,
|
||||
comments: obj.comments,
|
||||
|
||||
passcode: obj.passcode,
|
||||
|
||||
data_json: obj.data_json,
|
||||
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
group: obj.group,
|
||||
notes: obj.notes,
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
|
||||
// From SQL view
|
||||
username: obj.username,
|
||||
});
|
||||
// console.log(`Put obj with ID: ${obj.person_id_random} or ${id_random}`);
|
||||
} catch (error) {
|
||||
let status = `Failed to put ${obj.person_id_random}: ${error}`;
|
||||
console.log(status);
|
||||
}
|
||||
|
||||
// const id_random = await db_core.person.put(obj);
|
||||
// console.log(`Put obj with ID: ${obj.person_id_random}`);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,15 @@ import { browser } from '$app/environment';
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
|
||||
import {
|
||||
// handle_load_ae_obj_id__person,
|
||||
// handle_load_ae_obj_li__person,
|
||||
handle_create_ae_obj__person,
|
||||
// handle_update_ae_obj__person,
|
||||
// handle_db_save_ae_obj_li__person
|
||||
} from "$lib/ae_core__person";
|
||||
|
||||
// import { liveQuery } from "dexie";
|
||||
// import { db_core } from "$lib/db_core";
|
||||
|
||||
@@ -424,6 +433,7 @@ let export_obj = {
|
||||
handle_load_ae_obj_id__site_domain: handle_load_ae_obj_id__site_domain,
|
||||
handle_load_ae_obj_code__data_store: handle_load_ae_obj_code__data_store,
|
||||
handle_load_ae_obj_li__person: handle_load_ae_obj_li__person,
|
||||
handle_create_ae_obj__person: handle_create_ae_obj__person,
|
||||
handle_update_ae_obj_id_crud: handle_update_ae_obj_id_crud,
|
||||
handle_download_export__obj_type: handle_download_export__obj_type,
|
||||
};
|
||||
|
||||
85
src/lib/db_core.ts
Normal file
85
src/lib/db_core.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import Dexie, { type Table } from 'dexie';
|
||||
|
||||
// li = list
|
||||
// kv = key value list
|
||||
|
||||
// Updated 2024-06-10
|
||||
export interface Person {
|
||||
id: string;
|
||||
// id_random: string;
|
||||
person_id: string;
|
||||
person_id_random: string;
|
||||
|
||||
external_id: string;
|
||||
code: string;
|
||||
|
||||
account_id: string;
|
||||
|
||||
person_profile_id: null|string;
|
||||
person_profile_id_random: null|string; // The new table person_profile will be used soon...
|
||||
|
||||
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;
|
||||
|
||||
affiliations: null|string;
|
||||
|
||||
primary_email: string;
|
||||
|
||||
biography: null|string;
|
||||
|
||||
agree: null|boolean;
|
||||
comments: 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;
|
||||
|
||||
// Additional fields for convenience (database views)
|
||||
username: null|string;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-24
|
||||
export class MySubClassedDexie extends Dexie {
|
||||
person!: Table<Person>;
|
||||
// user!: Table<User>;
|
||||
|
||||
constructor() {
|
||||
super('ae_core_db');
|
||||
this.version(1).stores({
|
||||
person: `
|
||||
id, person_id, person_id_random,
|
||||
external_id, code,
|
||||
account_id, user_id,
|
||||
account_id_random, user_id_random,
|
||||
person_profile_id,
|
||||
person_profile_id_random,
|
||||
given_name, family_name,
|
||||
full_name, affiliations, email,
|
||||
agree,
|
||||
enable, hide, priority, sort, group, created_on, updated_on`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const db_core = new MySubClassedDexie();
|
||||
@@ -1322,6 +1322,40 @@ function send_sign_in_poc_email(
|
||||
</button>
|
||||
{/if} -->
|
||||
|
||||
<div class="float-right space-2 flex flex-row items-center">
|
||||
{#if $ae_loc.administrator_access }
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => {
|
||||
console.log('Add Person');
|
||||
|
||||
let person_data = {
|
||||
account_id_random: $slct.account_id,
|
||||
// user_id_random: user_obj.user_id_random,
|
||||
given_name: 'New',
|
||||
family_name: 'Presenter',
|
||||
primary_email: 'test+newpres@oneskyit.com',
|
||||
code: 'new_presenter',
|
||||
enable: true,
|
||||
}
|
||||
|
||||
core_func.handle_create_ae_obj__person({
|
||||
api_cfg: $ae_api,
|
||||
// user_id: $ae_loc.user_id,
|
||||
data_kv: person_data,
|
||||
log_lvl: 1,
|
||||
})
|
||||
|
||||
// We then need to update the event_presenter with the new person_id.
|
||||
}}
|
||||
class="btn btn-sm variant-soft-warning hover:variant-filled-warning"
|
||||
>
|
||||
<span class="fas fa-plus mx-1"></span>
|
||||
Add Person
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user