Skip to content

Commit

Permalink
Hook the optional field checks to all CRUD controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Aug 13, 2024
1 parent 99cf4c8 commit ca66429
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 5 deletions.
13 changes: 13 additions & 0 deletions application/controllers/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -110,8 +119,12 @@ public function save(): void

$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']);
}
Expand Down
12 changes: 12 additions & 0 deletions application/controllers/Admins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -139,8 +147,12 @@ public function store(): void

$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);
Expand Down
8 changes: 8 additions & 0 deletions application/controllers/Appointments.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Appointments extends EA_Controller
'id_services',
];

public array $optional_appointment_fields = [
//
];

/**
* Appointments constructor.
*/
Expand Down Expand Up @@ -104,6 +108,8 @@ public function store(): void

$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);
Expand Down Expand Up @@ -153,6 +159,8 @@ public function update(): void

$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([
Expand Down
8 changes: 8 additions & 0 deletions application/controllers/Blocked_periods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -120,6 +124,8 @@ public function store(): void

$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);
Expand Down Expand Up @@ -169,6 +175,8 @@ public function update(): void

$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);
Expand Down
6 changes: 6 additions & 0 deletions application/controllers/Booking_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -104,6 +108,8 @@ public function save(): void

$this->settings_model->only($setting, $this->allowed_setting_fields);

$this->settings_model->optional($setting, $this->optional_setting_fields);

$this->settings_model->save($setting);
}

Expand Down
10 changes: 9 additions & 1 deletion application/controllers/Business_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -102,7 +108,9 @@ public function save(): void
$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);
}
Expand Down
13 changes: 13 additions & 0 deletions application/controllers/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -53,6 +58,10 @@ class Calendar extends EA_Controller
'id_services',
];

public array $optional_appointment_fields = [
//
];

/**
* Calendar constructor.
*/
Expand Down Expand Up @@ -237,6 +246,8 @@ public function save_appointment(): void

$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);
}

Expand Down Expand Up @@ -266,6 +277,8 @@ public function save_appointment(): void

$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);
}

Expand Down
8 changes: 8 additions & 0 deletions application/controllers/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Customers extends EA_Controller
'ldap_dn',
];

public array $optional_customer_fields = [
//
];

/**
* Customers constructor.
*/
Expand Down Expand Up @@ -220,6 +224,8 @@ public function store(): void

$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);
Expand Down Expand Up @@ -255,6 +261,8 @@ public function update(): void

$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);
Expand Down
11 changes: 7 additions & 4 deletions application/controllers/Providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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.
*/
Expand Down
6 changes: 6 additions & 0 deletions application/controllers/Service_categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -117,6 +119,8 @@ public function store(): void

$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);
Expand Down Expand Up @@ -166,6 +170,8 @@ public function update(): void

$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);
Expand Down
8 changes: 8 additions & 0 deletions application/controllers/Unavailabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Unavailabilities extends EA_Controller
'id_users_provider',
];

public array $optional_unavailability_fields = [
//
];

/**
* Unavailabilities constructor.
*/
Expand Down Expand Up @@ -85,6 +89,8 @@ public function store(): void

$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);
Expand Down Expand Up @@ -138,6 +144,8 @@ public function update(): void

$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);
Expand Down
8 changes: 8 additions & 0 deletions application/controllers/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -136,6 +140,8 @@ public function store(): void

$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([
Expand All @@ -161,6 +167,8 @@ public function update(): void

$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([
Expand Down

0 comments on commit ca66429

Please sign in to comment.