From 4c74dd799572c62f17382ccb22f9cdf3a8e32f06 Mon Sep 17 00:00:00 2001 From: Jepp9350 <2jepp9350@gmail.com> Date: Tue, 28 Jan 2025 15:57:10 +0100 Subject: [PATCH] Add booking synchronization and handling improvements Introduce functionality to synchronize bookings, including creating or updating bookings based on provided details. Added strong typing to the `addOrUpdate` method for improved robustness and code clarity. --- objects/bookings_o.php | 2 +- routes/bookingsRoute.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/objects/bookings_o.php b/objects/bookings_o.php index fa26de45..8d2ed61f 100644 --- a/objects/bookings_o.php +++ b/objects/bookings_o.php @@ -166,7 +166,7 @@ class bookings_o extends db return $db->fetch_all($result); } - public function addOrUpdate($id, $customer_number, $wash_type, $contact_email, $reference_number, $regNrTraekker, $regNrTrailer, $washCertificateEmail, $date, $department, $pickup_bool, $notes, $washCertificateStatus, $washCertificateUrl, $status): void + public function addOrUpdate(int $id, $customer_number, $wash_type, $contact_email, $reference_number, $regNrTraekker, $regNrTrailer, $washCertificateEmail, $date, $department, $pickup_bool, $notes, $washCertificateStatus, $washCertificateUrl, $status): void { global $db; // Avoid SQL injection diff --git a/routes/bookingsRoute.php b/routes/bookingsRoute.php index 41c5afda..51258c61 100644 --- a/routes/bookingsRoute.php +++ b/routes/bookingsRoute.php @@ -85,6 +85,43 @@ class bookingsRoute if ($this->fromRequest('auth_key') !== 'earm8BX4MFTgS6JCNQdqW5EzHUutv2Vx') $this->requirePermission('sync_bookings'); // Check if the request was successful + $booking = [ + 'id' => $this->fromRequest('id'), + 'customer_number' => $this->fromRequest('customer_number'), + 'wash_type' => $this->fromRequest('wash_type'), + 'contact_email' => $this->fromRequest('contact_email'), + 'reference_number' => $this->fromRequest('reference_number'), + 'regNrTraekker' => $this->fromRequest('regNrTraekker'), + 'regNrTrailer' => $this->fromRequest('regNrTrailer'), + 'washCertificateEmail' => $this->fromRequest('washCertificateEmail'), + 'date' => $this->fromRequest('date'), + 'department' => $this->fromRequest('department'), + 'pickup_bool' => $this->fromRequest('pickup_bool'), + 'notes' => $this->fromRequest('notes'), + 'washCertificateStatus' => $this->fromRequest('washCertificateStatus'), + 'washCertificateUrl' => $this->fromRequest('washCertificateUrl'), + 'status' => $this->fromRequest('status'), + ]; + // Log the incident + (new logs_o())->add('bookings', 'global', 1, 0, 'SYNC_BOOKINGS', 'Successfully synced bookings'); + // Add the booking, if it doesn't exist, update it if it does + (new bookings_o())->addOrUpdate( + (int)$booking['id'], + (int)$booking['customer_number'], + (string)$booking['wash_type'], + (string)$booking['contact_email'], + (string)$booking['reference_number'], + (string)$booking['regNrTraekker'], + (string)$booking['regNrTrailer'], + (string)$booking['washCertificateEmail'], + (string)$booking['date'], + (string)$booking['department'], + (string)$booking['pickup_bool'], + (string)$booking['notes'], + (string)$booking['washCertificateStatus'], + (string)$booking['washCertificateUrl'], + (string)$booking['status'] + ); $response->success( ['message' => 'Successfully synced booking'] );