From ff766e0e7da836362ec11ac3baf78b639e057869 Mon Sep 17 00:00:00 2001 From: Tobias Frauenfelder Date: Mon, 18 Mar 2024 18:30:39 +0100 Subject: [PATCH] Fix bugs --- api/app/Http/Controllers/CampController.php | 9 ++++++++- frontend/src/views/Dashboard/Form.vue | 11 ++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/app/Http/Controllers/CampController.php b/api/app/Http/Controllers/CampController.php index f1d040c..66cdf49 100644 --- a/api/app/Http/Controllers/CampController.php +++ b/api/app/Http/Controllers/CampController.php @@ -68,6 +68,9 @@ public function syncExternalCamps() { $setting = Setting::find(1); $token = $setting->midata_api_key; + if(!$token) { + return response()->json(['message' => 'MiData API key not found'], 404); + } $midataId = $setting->midata_id; $midataBaseUrl = config('services.midata.base_url'); $response = Http::get("{$midataBaseUrl}/de/groups/{$midataId}/events/camp.json?token={$token}"); @@ -78,12 +81,16 @@ public function syncExternalCamps() foreach ($externalCamps['events'] as $externalCamp) { $eventDateIds = $externalCamp['links']['dates'] ?? []; $eventDate = collect($eventDateIds)->map(fn($id) => $eventDatesMap->get($id))->first(); + + $cost = $externalCamp['cost']; + $numericCost = preg_replace('/[^0-9.]+/', '', $cost); + $floatCost = $cost === '' ? null : floatval($numericCost); Camp::updateOrCreate( ['midata_id' => $externalCamp['id']], [ 'name' => $externalCamp['name'], 'description' => $externalCamp['description'], - 'cost' => $externalCamp['cost'] == '' ? null : $externalCamp['cost'], + 'cost' => $floatCost, 'maximum_participants' => $externalCamp['maximum_participants'], 'participant_count' => $externalCamp['participant_count'], 'location' => $externalCamp['location'], diff --git a/frontend/src/views/Dashboard/Form.vue b/frontend/src/views/Dashboard/Form.vue index fa86bb8..1909ed0 100644 --- a/frontend/src/views/Dashboard/Form.vue +++ b/frontend/src/views/Dashboard/Form.vue @@ -116,7 +116,7 @@ > setTimeout(resolve, 10)); const textFieldToFocus = document.getElementById( - `selectFieldOption-${field.id}-${field.optionFields.length - 1}`, + `selectFieldOption-${field.sort}-${field.optionFields.length - 1}`, ); textFieldToFocus.childNodes[1].focus(); }, @@ -215,7 +218,9 @@ export default { }, addField(field) { this.content.fields.push(field); - this.updateForm(); + this.content.fields = this.content.fields.sort((a, b) => a.sort - b.sort); + this.content.fields.forEach((f, i) => (f.sort = i)); + //this.updateForm(); }, deleteField(idAndType) { this.content.fields = this.content.fields.filter(