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:
Scott Idem
2025-11-19 12:12:29 -05:00
parent 2e70ce312b
commit d99e9ee1b0
9 changed files with 115 additions and 49 deletions

View 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'
];

View File

@@ -596,13 +596,20 @@ export async function create_ae_obj__event({
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
.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'event',
fields: {
account_id_random: account_id,
...data_kv
...cleaned_data_kv
},
key: api_cfg.api_crud_super_key,
params: params,
@@ -700,6 +707,8 @@ export async function delete_ae_obj_id__event({
return ae_promises.delete__event_obj;
}
import { editable_fields } from './ae_events__event.editable_fields';
// Updated 2024-09-25
export async function update_ae_obj__event({
api_cfg,
@@ -719,13 +728,26 @@ export async function update_ae_obj__event({
if (log_lvl) {
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
.update_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event',
obj_id: event_id,
fields: data_kv,
fields: cleaned_data_kv, // <--- This is the payload being sent
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,

View File

@@ -99,7 +99,7 @@ export interface Event {
// Updated 2025-10-06
export interface Badge {
id: number;
id: string;
// id_random: string;
event_badge_id: string;
event_badge_id_random: string;
@@ -190,7 +190,7 @@ export interface Badge {
// Updated 2025-10-06
export interface Badge_template {
id: number;
id: string;
// id_random: string;
event_id: string;
@@ -249,7 +249,7 @@ export interface Badge_template {
// Updated 2024-10-16
export interface Device {
id: number;
id: string;
// id_random: string;
event_device_id: string;
// event_device_id_random: string;