Hook the optional field checks to all CRUD controllers

This commit is contained in:
Alex Tselegidis 2024-08-13 13:34:03 +02:00
parent 99cf4c8da2
commit ca664294e9
12 changed files with 106 additions and 5 deletions

View file

@ -36,8 +36,17 @@ class Account extends EA_Controller
'language',
'settings',
];
public array $optional_user_fields = [
//
];
public array $allowed_user_setting_fields = ['username', 'password', 'notifications', 'calendar_view'];
public array $optional_user_setting_fields = [
//
];
/**
* Account constructor.
*/
@ -110,8 +119,12 @@ class Account extends EA_Controller
$this->users_model->only($account, $this->allowed_user_fields);
$this->users_model->optional($account, $this->optional_user_fields);
$this->users_model->only($account['settings'], $this->allowed_user_setting_fields);
$this->users_model->optional($account['settings'], $this->optional_user_setting_fields);
if (empty($account['password'])) {
unset($account['password']);
}

View file

@ -38,8 +38,16 @@ class Admins extends EA_Controller
'settings',
];
public array $optional_admin_fields = [
//
];
public array $allowed_admin_setting_fields = ['username', 'password', 'notifications', 'calendar_view'];
public array $optional_admin_settings_fields = [
//
];
/**
* Admins constructor.
*/
@ -139,8 +147,12 @@ class Admins extends EA_Controller
$this->admins_model->only($admin, $this->allowed_admin_fields);
$this->admins_model->optional($admin, $this->optional_admin_fields);
$this->admins_model->only($admin['settings'], $this->allowed_admin_setting_fields);
$this->admins_model->optional($admin['settings'], $this->optional_admin_setting_fields);
$admin_id = $this->admins_model->save($admin);
$admin = $this->admins_model->find($admin_id);

View file

@ -37,6 +37,10 @@ class Appointments extends EA_Controller
'id_services',
];
public array $optional_appointment_fields = [
//
];
/**
* Appointments constructor.
*/
@ -104,6 +108,8 @@ class Appointments extends EA_Controller
$this->appointments_model->only($appointment, $this->allowed_appointment_fields);
$this->appointments_model->optional($appointment, $this->optional_appointment_fields);
$appointment_id = $this->appointments_model->save($appointment);
$appointment = $this->appointments_model->find($appointment);
@ -153,6 +159,8 @@ class Appointments extends EA_Controller
$this->appointments_model->only($appointment, $this->allowed_appointment_fields);
$this->appointments_model->optional($appointment, $this->optional_appointment_fields);
$appointment_id = $this->appointments_model->save($appointment);
json_response([

View file

@ -22,6 +22,10 @@ class Blocked_periods extends EA_Controller
{
public array $allowed_blocked_period_fields = ['id', 'name', 'start_datetime', 'end_datetime', 'notes'];
public array $optional_blocked_period_fields = [
//
];
/**
* Blocked_periods constructor.
*/
@ -120,6 +124,8 @@ class Blocked_periods extends EA_Controller
$this->blocked_periods_model->only($blocked_period, $this->allowed_blocked_period_fields);
$this->blocked_periods_model->optional($blocked_period, $this->optional_blocked_period_fields);
$blocked_period_id = $this->blocked_periods_model->save($blocked_period);
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
@ -169,6 +175,8 @@ class Blocked_periods extends EA_Controller
$this->blocked_periods_model->only($blocked_period, $this->allowed_blocked_period_fields);
$this->blocked_periods_model->optional($blocked_period, $this->optional_blocked_period_fields);
$blocked_period_id = $this->blocked_periods_model->save($blocked_period);
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);

View file

@ -22,6 +22,10 @@ class Booking_settings extends EA_Controller
{
public array $allowed_setting_fields = ['id', 'name', 'value'];
public array $optional_setting_fields = [
//
];
/**
* Booking_settings constructor.
*/
@ -104,6 +108,8 @@ class Booking_settings extends EA_Controller
$this->settings_model->only($setting, $this->allowed_setting_fields);
$this->settings_model->optional($setting, $this->optional_setting_fields);
$this->settings_model->save($setting);
}

View file

@ -20,6 +20,12 @@
*/
class Business_settings extends EA_Controller
{
public array $allowed_setting_fields = ['id', 'name', 'value'];
public array $optional_setting_fields = [
//
];
/**
* Business_logic constructor.
*/
@ -102,7 +108,9 @@ class Business_settings extends EA_Controller
$setting['id'] = $existing_setting['id'];
}
$this->settings_model->only($setting, ['id', 'name', 'value']);
$this->settings_model->only($setting, $this->allowed_setting_fields);
$this->settings_model->optional($setting, $this->optional_setting_fields);
$this->settings_model->save($setting);
}

View file

@ -39,6 +39,11 @@ class Calendar extends EA_Controller
'custom_field_4',
'custom_field_5',
];
public array $optional_customer_fields = [
//
];
public array $allowed_appointment_fields = [
'id',
'start_datetime',
@ -53,6 +58,10 @@ class Calendar extends EA_Controller
'id_services',
];
public array $optional_appointment_fields = [
//
];
/**
* Calendar constructor.
*/
@ -237,6 +246,8 @@ class Calendar extends EA_Controller
$this->customers_model->only($customer, $this->allowed_customer_fields);
$this->customers_model->optional($customer, $this->optional_customer_fields);
$customer['id'] = $this->customers_model->save($customer);
}
@ -266,6 +277,8 @@ class Calendar extends EA_Controller
$this->appointments_model->only($appointment, $this->allowed_appointment_fields);
$this->appointments_model->optional($appointment, $this->optional_appointment_fields);
$appointment['id'] = $this->appointments_model->save($appointment);
}

View file

@ -41,6 +41,10 @@ class Customers extends EA_Controller
'ldap_dn',
];
public array $optional_customer_fields = [
//
];
/**
* Customers constructor.
*/
@ -220,6 +224,8 @@ class Customers extends EA_Controller
$this->customers_model->only($customer, $this->allowed_customer_fields);
$this->customers_model->optional($customer, $this->optional_customer_fields);
$customer_id = $this->customers_model->save($customer);
$customer = $this->customers_model->find($customer_id);
@ -255,6 +261,8 @@ class Customers extends EA_Controller
$this->customers_model->only($customer, $this->allowed_customer_fields);
$this->customers_model->optional($customer, $this->optional_customer_fields);
$customer_id = $this->customers_model->save($customer);
$customer = $this->customers_model->find($customer_id);

View file

@ -40,6 +40,11 @@ class Providers extends EA_Controller
'settings',
'services',
];
public array $optional_provider_fields = [
'services' => [],
];
public array $allowed_provider_setting_fields = [
'username',
'password',
@ -48,16 +53,14 @@ class Providers extends EA_Controller
'notifications',
'calendar_view',
];
public array $allowed_service_fields = ['id', 'name'];
public array $optional_provider_fields = [
'services' => [],
];
public array $optional_provider_setting_fields = [
'working_plan' => null,
'working_plan_exceptions' => '{}',
];
public array $allowed_service_fields = ['id', 'name'];
/**
* Providers constructor.
*/

View file

@ -22,6 +22,8 @@ class Service_categories extends EA_Controller
{
public array $allowed_service_category_fields = ['id', 'name', 'description'];
public array $optional_service_category_fields = [];
/**
* Service-categories constructor.
*/
@ -117,6 +119,8 @@ class Service_categories extends EA_Controller
$this->service_categories_model->only($service_category, $this->allowed_service_category_fields);
$this->service_categories_model->optional($service_category, $this->optional_service_category_fields);
$service_category_id = $this->service_categories_model->save($service_category);
$service_category = $this->service_categories_model->find($service_category_id);
@ -166,6 +170,8 @@ class Service_categories extends EA_Controller
$this->service_categories_model->only($service_category, $this->allowed_service_category_fields);
$this->service_categories_model->optional($service_category, $this->optional_service_category_fields);
$service_category_id = $this->service_categories_model->save($service_category);
$service_category = $this->service_categories_model->find($service_category_id);

View file

@ -30,6 +30,10 @@ class Unavailabilities extends EA_Controller
'id_users_provider',
];
public array $optional_unavailability_fields = [
//
];
/**
* Unavailabilities constructor.
*/
@ -85,6 +89,8 @@ class Unavailabilities extends EA_Controller
$this->unavailabilities_model->only($unavailability, $this->allowed_unavailability_fields);
$this->unavailabilities_model->optional($unavailability, $this->optional_unavailability_fields);
$unavailability_id = $this->unavailabilities_model->save($unavailability);
$unavailability = $this->unavailabilities_model->find($unavailability_id);
@ -138,6 +144,8 @@ class Unavailabilities extends EA_Controller
$this->unavailabilities_model->only($unavailability, $this->allowed_unavailability_fields);
$this->unavailabilities_model->optional($unavailability, $this->optional_unavailability_fields);
$unavailability_id = $this->unavailabilities_model->save($unavailability);
$unavailability = $this->unavailabilities_model->find($unavailability_id);

View file

@ -22,6 +22,10 @@ class Webhooks extends EA_Controller
{
public array $allowed_webhook_fields = ['id', 'name', 'url', 'actions', 'secret_token', 'is_ssl_verified', 'notes'];
public array $optional_webhook_fields = [
//
];
/**
* Webhooks constructor.
*/
@ -136,6 +140,8 @@ class Webhooks extends EA_Controller
$this->webhooks_model->only($webhook, $this->allowed_webhook_fields);
$this->webhooks_model->optional($webhook, $this->optional_webhook_fields);
$webhook_id = $this->webhooks_model->save($webhook);
json_response([
@ -161,6 +167,8 @@ class Webhooks extends EA_Controller
$this->webhooks_model->only($webhook, $this->allowed_webhook_fields);
$this->webhooks_model->optional($webhook, $this->optional_webhook_fields);
$webhook_id = $this->webhooks_model->save($webhook);
json_response([