refactor(events): Centralize editable fields for event objects
- Implemented a whitelist for editable fields for the 'event' object type to prevent sending read-only fields in POST/PATCH requests. - Created a new file to define the editable fields. - Modified and to use this whitelist. - Removed the temporary cleaning logic from the event settings page. - Corrected Svelte 5 to in event settings components. - Updated Dexie interfaces for badge, badge_template, and device to use string IDs.
This commit is contained in:
50
src/lib/ae_events/ae_events__event.editable_fields.ts
Normal file
50
src/lib/ae_events/ae_events__event.editable_fields.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
export const editable_fields = [
|
||||||
|
'code',
|
||||||
|
'conference',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'summary',
|
||||||
|
'description',
|
||||||
|
'start_datetime',
|
||||||
|
'end_datetime',
|
||||||
|
'timezone',
|
||||||
|
'location_address_json',
|
||||||
|
'location_text',
|
||||||
|
'attend_json',
|
||||||
|
'attend_text',
|
||||||
|
'status',
|
||||||
|
'mod_abstracts_json',
|
||||||
|
'mod_badges_json',
|
||||||
|
'mod_exhibits_json',
|
||||||
|
'mod_meetings_json',
|
||||||
|
'mod_pres_mgmt_json',
|
||||||
|
'cfg_json',
|
||||||
|
'enable',
|
||||||
|
'hide',
|
||||||
|
'priority',
|
||||||
|
'sort',
|
||||||
|
'group',
|
||||||
|
'notes',
|
||||||
|
'contact_li_json',
|
||||||
|
'external_person_id',
|
||||||
|
'physical',
|
||||||
|
'virtual',
|
||||||
|
'recurring',
|
||||||
|
'recurring_pattern',
|
||||||
|
'recurring_start_time',
|
||||||
|
'recurring_end_time',
|
||||||
|
'recurring_text',
|
||||||
|
'weekday_sunday',
|
||||||
|
'weekday_monday',
|
||||||
|
'weekday_tuesday',
|
||||||
|
'weekday_wednesday',
|
||||||
|
'weekday_thursday',
|
||||||
|
'weekday_friday',
|
||||||
|
'weekday_saturday',
|
||||||
|
'attend_url',
|
||||||
|
'attend_url_text',
|
||||||
|
'attend_url_code',
|
||||||
|
'attend_url_passcode',
|
||||||
|
'attend_phone',
|
||||||
|
'attend_phone_passcode'
|
||||||
|
];
|
||||||
@@ -596,13 +596,20 @@ export async function create_ae_obj__event({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cleaned_data_kv = Object.keys(data_kv)
|
||||||
|
.filter((key) => editable_fields.includes(key))
|
||||||
|
.reduce((obj, key) => {
|
||||||
|
obj[key] = data_kv[key];
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
|
||||||
ae_promises.create__event = await api
|
ae_promises.create__event = await api
|
||||||
.create_ae_obj_crud({
|
.create_ae_obj_crud({
|
||||||
api_cfg: api_cfg,
|
api_cfg: api_cfg,
|
||||||
obj_type: 'event',
|
obj_type: 'event',
|
||||||
fields: {
|
fields: {
|
||||||
account_id_random: account_id,
|
account_id_random: account_id,
|
||||||
...data_kv
|
...cleaned_data_kv
|
||||||
},
|
},
|
||||||
key: api_cfg.api_crud_super_key,
|
key: api_cfg.api_crud_super_key,
|
||||||
params: params,
|
params: params,
|
||||||
@@ -700,6 +707,8 @@ export async function delete_ae_obj_id__event({
|
|||||||
return ae_promises.delete__event_obj;
|
return ae_promises.delete__event_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import { editable_fields } from './ae_events__event.editable_fields';
|
||||||
|
|
||||||
// Updated 2024-09-25
|
// Updated 2024-09-25
|
||||||
export async function update_ae_obj__event({
|
export async function update_ae_obj__event({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
@@ -719,13 +728,26 @@ export async function update_ae_obj__event({
|
|||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** update_ae_obj__event() *** event_id=${event_id}`, data_kv);
|
console.log(`*** update_ae_obj__event() *** event_id=${event_id}`, data_kv);
|
||||||
}
|
}
|
||||||
// ae_promises.update__event_obj = 'test';
|
|
||||||
|
const cleaned_data_kv = Object.keys(data_kv)
|
||||||
|
.filter((key) => editable_fields.includes(key))
|
||||||
|
.reduce((obj, key) => {
|
||||||
|
obj[key] = data_kv[key];
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// Rename 'account_id' to 'account_id_random' if present
|
||||||
|
if (cleaned_data_kv.account_id !== undefined) {
|
||||||
|
cleaned_data_kv.account_id_random = cleaned_data_kv.account_id;
|
||||||
|
delete cleaned_data_kv.account_id;
|
||||||
|
}
|
||||||
|
|
||||||
ae_promises.update__event_obj = await api
|
ae_promises.update__event_obj = await api
|
||||||
.update_ae_obj_id_crud({
|
.update_ae_obj_id_crud({
|
||||||
api_cfg: api_cfg,
|
api_cfg: api_cfg,
|
||||||
obj_type: 'event',
|
obj_type: 'event',
|
||||||
obj_id: event_id,
|
obj_id: event_id,
|
||||||
fields: data_kv,
|
fields: cleaned_data_kv, // <--- This is the payload being sent
|
||||||
key: api_cfg.api_crud_super_key,
|
key: api_cfg.api_crud_super_key,
|
||||||
params: params,
|
params: params,
|
||||||
return_obj: true,
|
return_obj: true,
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export interface Event {
|
|||||||
|
|
||||||
// Updated 2025-10-06
|
// Updated 2025-10-06
|
||||||
export interface Badge {
|
export interface Badge {
|
||||||
id: number;
|
id: string;
|
||||||
// id_random: string;
|
// id_random: string;
|
||||||
event_badge_id: string;
|
event_badge_id: string;
|
||||||
event_badge_id_random: string;
|
event_badge_id_random: string;
|
||||||
@@ -190,7 +190,7 @@ export interface Badge {
|
|||||||
|
|
||||||
// Updated 2025-10-06
|
// Updated 2025-10-06
|
||||||
export interface Badge_template {
|
export interface Badge_template {
|
||||||
id: number;
|
id: string;
|
||||||
// id_random: string;
|
// id_random: string;
|
||||||
|
|
||||||
event_id: string;
|
event_id: string;
|
||||||
@@ -249,7 +249,7 @@ export interface Badge_template {
|
|||||||
|
|
||||||
// Updated 2024-10-16
|
// Updated 2024-10-16
|
||||||
export interface Device {
|
export interface Device {
|
||||||
id: number;
|
id: string;
|
||||||
// id_random: string;
|
// id_random: string;
|
||||||
event_device_id: string;
|
event_device_id: string;
|
||||||
// event_device_id_random: string;
|
// event_device_id_random: string;
|
||||||
|
|||||||
@@ -72,8 +72,8 @@
|
|||||||
<summary class="summary">General Config (cfg_json)</summary>
|
<summary class="summary">General Config (cfg_json)</summary>
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<button class="btn btn-sm" on:click={() => (cfg_json_view = 'form')}>Form</button>
|
<button class="btn btn-sm" onclick={() => (cfg_json_view = 'form')}>Form</button>
|
||||||
<button class="btn btn-sm" on:click={() => (cfg_json_view = 'json')}>JSON</button>
|
<button class="btn btn-sm" onclick={() => (cfg_json_view = 'json')}>JSON</button>
|
||||||
</div>
|
</div>
|
||||||
{#if cfg_json_view === 'form'}
|
{#if cfg_json_view === 'form'}
|
||||||
<Ae_comp_event_settings_form
|
<Ae_comp_event_settings_form
|
||||||
@@ -92,10 +92,9 @@
|
|||||||
event_obj.cfg_json = e.detail;
|
event_obj.cfg_json = e.detail;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="btn preset-tonal-primary"
|
class="btn preset-tonal-primary"
|
||||||
on:click={() => handle_save('cfg_json', event_obj.cfg_json)}>Save</button
|
onclick={() => handle_save('cfg_json', event_obj.cfg_json)}>Save</button>
|
||||||
>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
@@ -104,10 +103,10 @@
|
|||||||
<summary class="summary">Presentation Management (mod_pres_mgmt_json)</summary>
|
<summary class="summary">Presentation Management (mod_pres_mgmt_json)</summary>
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<button class="btn btn-sm" on:click={() => (pres_mgmt_json_view = 'form')}
|
<button class="btn btn-sm" onclick={() => (pres_mgmt_json_view = 'form')}
|
||||||
>Form</button
|
>Form</button
|
||||||
>
|
>
|
||||||
<button class="btn btn-sm" on:click={() => (pres_mgmt_json_view = 'json')}
|
<button class="btn btn-sm" onclick={() => (pres_mgmt_json_view = 'json')}
|
||||||
>JSON</button
|
>JSON</button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@@ -128,12 +127,11 @@
|
|||||||
event_obj.mod_pres_mgmt_json = e.detail;
|
event_obj.mod_pres_mgmt_json = e.detail;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="btn preset-tonal-primary"
|
class="btn preset-tonal-primary"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
handle_save('mod_pres_mgmt_json', event_obj.mod_pres_mgmt_json)}
|
handle_save('mod_pres_mgmt_json', event_obj.mod_pres_mgmt_json)}
|
||||||
>Save</button
|
>Save</button>
|
||||||
>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
@@ -142,8 +140,8 @@
|
|||||||
<summary class="summary">Badges (mod_badges_json)</summary>
|
<summary class="summary">Badges (mod_badges_json)</summary>
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<button class="btn btn-sm" on:click={() => (badges_json_view = 'form')}>Form</button>
|
<button class="btn btn-sm" onclick={() => (badges_json_view = 'form')}>Form</button>
|
||||||
<button class="btn btn-sm" on:click={() => (badges_json_view = 'json')}>JSON</button>
|
<button class="btn btn-sm" onclick={() => (badges_json_view = 'json')}>JSON</button>
|
||||||
</div>
|
</div>
|
||||||
{#if badges_json_view === 'form'}
|
{#if badges_json_view === 'form'}
|
||||||
<Ae_comp_event_settings_badges_form
|
<Ae_comp_event_settings_badges_form
|
||||||
@@ -162,11 +160,10 @@
|
|||||||
event_obj.mod_badges_json = e.detail;
|
event_obj.mod_badges_json = e.detail;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="btn preset-tonal-primary"
|
class="btn preset-tonal-primary"
|
||||||
on:click={() => handle_save('mod_badges_json', event_obj.mod_badges_json)}
|
onclick={() => handle_save('mod_badges_json', event_obj.mod_badges_json)}
|
||||||
>Save</button
|
>Save</button>
|
||||||
>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
@@ -175,10 +172,10 @@
|
|||||||
<summary class="summary">Abstracts (mod_abstracts_json)</summary>
|
<summary class="summary">Abstracts (mod_abstracts_json)</summary>
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<button class="btn btn-sm" on:click={() => (abstracts_json_view = 'form')}
|
<button class="btn btn-sm" onclick={() => (abstracts_json_view = 'form')}
|
||||||
>Form</button
|
>Form</button
|
||||||
>
|
>
|
||||||
<button class="btn btn-sm" on:click={() => (abstracts_json_view = 'json')}
|
<button class="btn btn-sm" onclick={() => (abstracts_json_view = 'json')}
|
||||||
>JSON</button
|
>JSON</button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@@ -199,11 +196,10 @@
|
|||||||
event_obj.mod_abstracts_json = e.detail;
|
event_obj.mod_abstracts_json = e.detail;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="btn preset-tonal-primary"
|
class="btn preset-tonal-primary"
|
||||||
on:click={() => handle_save('mod_abstracts_json', event_obj.mod_abstracts_json)}
|
onclick={() => handle_save('mod_abstracts_json', event_obj.mod_abstracts_json)}
|
||||||
>Save</button
|
>Save</button>
|
||||||
>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
@@ -222,11 +218,10 @@
|
|||||||
event_obj.mod_exhibits_json = e.detail;
|
event_obj.mod_exhibits_json = e.detail;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="btn preset-tonal-primary"
|
class="btn preset-tonal-primary"
|
||||||
on:click={() => handle_save('mod_exhibits_json', event_obj.mod_exhibits_json)}
|
onclick={() => handle_save('mod_exhibits_json', event_obj.mod_exhibits_json)}
|
||||||
>Save</button
|
>Save</button>
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@@ -244,11 +239,10 @@
|
|||||||
event_obj.mod_meetings_json = e.detail;
|
event_obj.mod_meetings_json = e.detail;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="btn preset-tonal-primary"
|
class="btn preset-tonal-primary"
|
||||||
on:click={() => handle_save('mod_meetings_json', event_obj.mod_meetings_json)}
|
onclick={() => handle_save('mod_meetings_json', event_obj.mod_meetings_json)}
|
||||||
>Save</button
|
>Save</button>
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -95,5 +95,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn preset-tonal-primary" on:click={save}>Save</button>
|
<button class="btn preset-tonal-primary" onclick={save}>Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -86,5 +86,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn preset-tonal-primary" on:click={save}>Save</button>
|
<button class="btn preset-tonal-primary" onclick={save}>Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -70,5 +70,5 @@
|
|||||||
<textarea class="textarea" bind:value={event_obj.notes}></textarea>
|
<textarea class="textarea" bind:value={event_obj.notes}></textarea>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn preset-tonal-primary" on:click={save}>Save</button>
|
<button class="btn preset-tonal-primary" onclick={save}>Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -28,5 +28,5 @@
|
|||||||
<input type="text" class="input" bind:value={cfg_json.med_name} />
|
<input type="text" class="input" bind:value={cfg_json.med_name} />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn preset-tonal-primary" on:click={save}>Save</button>
|
<button class="btn preset-tonal-primary" onclick={save}>Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -134,5 +134,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn preset-tonal-primary" on:click={save}>Save</button>
|
<button class="btn preset-tonal-primary" onclick={save}>Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user