diff --git a/zmscitizenapi/package.json b/zmscitizenapi/package.json index eaf91178c..dda7ae5a6 100644 --- a/zmscitizenapi/package.json +++ b/zmscitizenapi/package.json @@ -2,7 +2,6 @@ "name": "zmscitizenapi", "version": "1.0.0", "description": "This application offers a REST-like interface for ZMS functions and database access.", - "main": "index.js", "private": true, "scripts": { "preinstall": "", diff --git a/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php b/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php index 43491109d..bd4d57aee 100644 --- a/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php +++ b/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php @@ -56,12 +56,12 @@ public function readResponse(RequestInterface $request, ResponseInterface $respo } $freeAppointments = new ProcessList(); - $freeAppointments = ZmsApiFacadeService::getFreeAppointments([ - 'officeId' => $officeId, - 'serviceIds' => $serviceIds, - 'serviceCounts' => $serviceCounts, - 'date' => UtilityHelper::getInternalDateFromTimestamp($timestamp) - ]); + $freeAppointments = ZmsApiFacadeService::getFreeAppointments( + $officeId, + $serviceIds, + $serviceCounts, + UtilityHelper::getInternalDateFromTimestamp($timestamp) + ); $processArray = json_decode(json_encode($freeAppointments), true); @@ -106,17 +106,17 @@ public function readResponse(RequestInterface $request, ResponseInterface $respo } } - $appointment = new ThinnedProcess(); - $appointment = UtilityHelper::processToThinnedProcess($reservedProcess); + $thinnedProcess = new ThinnedProcess(); + $thinnedProcess = UtilityHelper::processToThinnedProcess($reservedProcess); - $appointment = array_merge($appointment->toArray(), ['officeId' => $officeId]); + $thinnedProcess = array_merge($thinnedProcess->toArray(), ['officeId' => $officeId]); - return $this->createJsonResponse($response, $appointment, 200); + return $this->createJsonResponse($response, $thinnedProcess, 200); } catch (\Exception $e) { return $this->createJsonResponse($response, [ 'errorCode' => 'internalServerError', - 'errorMessage' => $e->getMessage() + 'errorMessage' => 'An internal server error occurred' ], 500); } } diff --git a/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php b/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php index b18d176a6..288f70bae 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php +++ b/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php @@ -51,16 +51,27 @@ public static function uniqueElementsFilter($value, $index, $self): bool return array_search($value, $self) === $index; } + public static function getClientIp(): string + { + $headers = ['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR']; + foreach ($headers as $header) { + if (isset($_SERVER[$header]) && filter_var($_SERVER[$header], FILTER_VALIDATE_IP)) { + return $_SERVER[$header]; + } + } + return '127.0.0.1'; + } + public static function processToThinnedProcess(Process $myProcess): ThinnedProcess { if (!$myProcess || !isset($myProcess->id)) { return null; } - + $subRequestCounts = []; $mainServiceId = null; $mainServiceCount = 0; - + $requests = $myProcess->requests ?? []; if ($requests) { $requests = is_array($requests) ? $requests : iterator_to_array($requests); @@ -96,7 +107,7 @@ public static function processToThinnedProcess(Process $myProcess): ThinnedProce $thinnedProcess->subRequestCounts = array_values($subRequestCounts); $thinnedProcess->serviceId = $mainServiceId; $thinnedProcess->serviceCount = $mainServiceCount; - + return $thinnedProcess; } @@ -105,23 +116,23 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess): if (!$thinnedProcess || !isset($thinnedProcess->processId)) { return null; } - + $processEntity = new Process(); $processEntity->id = $thinnedProcess->processId; $processEntity->authKey = $thinnedProcess->authKey ?? null; - + $client = new Client(); $client->familyName = $thinnedProcess->familyName ?? null; $client->email = $thinnedProcess->email ?? null; $client->telephone = $thinnedProcess->telephone ?? null; $client->customTextfield = $thinnedProcess->customTextfield ?? null; - + $processEntity->clients = [$client]; - + $thinnedProcess = new Appointment(); $thinnedProcess->date = $thinnedProcess->timestamp ?? null; $processEntity->appointments = [$thinnedProcess]; - + $scope = new Scope(); if (isset($thinnedProcess->officeName)) { $scope->contact = new Contact(); @@ -133,11 +144,11 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess): $scope->provider->source = \App::$source_name; } $processEntity->scope = $scope; - + $mainServiceId = $thinnedProcess->serviceId ?? null; $mainServiceCount = $thinnedProcess->serviceCount ?? 0; $subRequestCounts = $thinnedProcess->subRequestCounts ?? []; - + $requests = []; for ($i = 0; $i < $mainServiceCount; $i++) { $request = new Request(); @@ -154,13 +165,13 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess): } } $processEntity->requests = $requests; - + $processEntity->lastChange = time(); - $processEntity->createIP = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1'; + $processEntity->createIP = self::getClientIp(); $processEntity->createTimestamp = time(); - + return $processEntity; } - + } diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php index ca905eff3..4752d9931 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class AppointmentCancel extends Entity { - public static $schema = "citizenapi/appointmentCancel.json"; + public static $schema = "zmsentities/schema/citizenapi/appointmentCancel.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentConfirm.php b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentConfirm.php index f9ba05422..6c0652e00 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentConfirm.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentConfirm.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class AppointmentConfirm extends Entity { - public static $schema = "citizenapi/appointmentConfirm.json"; + public static $schema = "zmsentities/schema/citizenapi/appointmentConfirm.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentPreConfirm.php b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentPreConfirm.php index de0f065ee..da170c4b8 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentPreConfirm.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentPreConfirm.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class AppointmentPreConfirm extends Entity { - public static $schema = "citizenapi/appointmentPreConfirm.json"; + public static $schema = "zmsentities/schema/citizenapi/appointmentPreConfirm.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentReserve.php b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentReserve.php index a83110e8f..9f03d66ed 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentReserve.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentReserve.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class AppointmentReserve extends Entity { - public static $schema = "citizenapi/appointmentReserve.json"; + public static $schema = "zmsentities/schema/citizenapi/appointmentReserve.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentUpdate.php b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentUpdate.php index 17fc5e8ec..556d6c578 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentUpdate.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentUpdate.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class AppointmentUpdate extends Entity { - public static $schema = "citizenapi/appointmentUpdate.json"; + public static $schema = "zmsentities/schema/citizenapi/appointmentUpdate.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AvailableAppointments.php b/zmscitizenapi/src/Zmscitizenapi/Models/AvailableAppointments.php index a2aa9c631..0b1127005 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/AvailableAppointments.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AvailableAppointments.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class AvailableAppointments extends Entity { - public static $schema = "citizenapi/availableAppointments.json"; + public static $schema = "zmsentities/schema/citizenapi/availableAppointments.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AvailableDays.php b/zmscitizenapi/src/Zmscitizenapi/Models/AvailableDays.php index 67871d206..4a9387a2e 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/AvailableDays.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AvailableDays.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class AvailableDays extends Entity { - public static $schema = "citizenapi/availableDays.json"; + public static $schema = "zmsentities/schema/citizenapi/availableDays.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/CaptchaDetails.php b/zmscitizenapi/src/Zmscitizenapi/Models/CaptchaDetails.php index 94cc0ee0f..35dd01d59 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/CaptchaDetails.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/CaptchaDetails.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class CaptchaDetails extends Entity { - public static $schema = "citizenapi/captchaDetails.json"; + public static $schema = "zmsentities/schema/citizenapi/captchaDetails.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/Offices.php b/zmscitizenapi/src/Zmscitizenapi/Models/Offices.php index 5698cfb78..70638f82a 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/Offices.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/Offices.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class Offices extends Entity { - public static $schema = "citizenapi/offices.json"; + public static $schema = "zmsentities/schema/citizenapi/offices.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/OfficesAndServices.php b/zmscitizenapi/src/Zmscitizenapi/Models/OfficesAndServices.php index 70253134e..a040cd62d 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/OfficesAndServices.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/OfficesAndServices.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class OfficesAndServices extends Entity { - public static $schema = "citizenapi/officesAndServices.json"; + public static $schema = "zmsentities/schema/citizenapi/officesAndServices.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/OfficesByService.php b/zmscitizenapi/src/Zmscitizenapi/Models/OfficesByService.php index 8d7fdfcc9..f6a19df28 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/OfficesByService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/OfficesByService.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class OfficesByService extends Entity { - public static $schema = "citizenapi/officesByService.json"; + public static $schema = "zmsentities/schema/citizenapi/officesByService.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/Scope.php b/zmscitizenapi/src/Zmscitizenapi/Models/Scope.php index a6e4ce55b..350704729 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/Scope.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/Scope.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class Scope extends Entity { - public static $schema = "citizenapi/scope.json"; + public static $schema = "zmsentities/schema/citizenapi/scope.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/Scopes.php b/zmscitizenapi/src/Zmscitizenapi/Models/Scopes.php index 39111e315..c84630307 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/Scopes.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/Scopes.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class Scopes extends Entity { - public static $schema = "citizenapi/scopes.json"; + public static $schema = "zmsentities/schema/citizenapi/scopes.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/Services.php b/zmscitizenapi/src/Zmscitizenapi/Models/Services.php index ca8b20c91..b9184640d 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/Services.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/Services.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class Services extends Entity { - public static $schema = "citizenapi/services.json"; + public static $schema = "zmsentities/schema/citizenapi/services.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/ServicesByOffice.php b/zmscitizenapi/src/Zmscitizenapi/Models/ServicesByOffice.php index 6de18b350..da6adb0e1 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/ServicesByOffice.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/ServicesByOffice.php @@ -5,15 +5,9 @@ use \BO\Zmsentities\Helper\Property; use \BO\Zmsentities\Schema\Entity; -/** - * @SuppressWarnings(Complexity) - * @SuppressWarnings(Coupling) - * @SuppressWarnings(Public) - * - */ class ServicesByOffice extends Entity { - public static $schema = "citizenapi/servicesByOffice.json"; + public static $schema = "zmsentities/schema/citizenapi/servicesByOffice.json"; } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/ThinnedProcess.php b/zmscitizenapi/src/Zmscitizenapi/Models/ThinnedProcess.php index a20e5bb24..32896e245 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Models/ThinnedProcess.php +++ b/zmscitizenapi/src/Zmscitizenapi/Models/ThinnedProcess.php @@ -6,7 +6,7 @@ class ThinnedProcess extends Entity { - public static $schema = "citizenapi/thinnedProcess.json"; + public static $schema = "zmsentities/schema/citizenapi/thinnedProcess.json"; // Add properties based on schema (or dynamically handle them in Entity class) diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php index 4e8560671..d571fdb70 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php @@ -2,6 +2,7 @@ namespace BO\Zmscitizenapi\Services; +use BO\Zmscitizenapi\Helper\UtilityHelper; use \BO\Zmsentities\Calendar as Calendar; use \BO\Zmsentities\Process as Process; use \BO\Zmsentities\Collection\SourceList; @@ -126,7 +127,7 @@ public static function reserveTimeslot(Process $appointmentProcess, array $servi $processEntity->requests = $requests; $processEntity->lastChange = $appointmentProcess['lastChange'] ?? time(); - $processEntity->createIP = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1'; + $processEntity->createIP = UtilityHelper::getClientIp(); $processEntity->createTimestamp = time(); if (isset($appointmentProcess['queue'])) { @@ -175,25 +176,25 @@ public function confirmProcess(?Process $process): Process public function cancelAppointment(?Process $process): Process { - $url = "/process/{$process['id']}/{$process['authKey']}/"; + $url = "/process/{$process->id}/{$process->authKey}/"; return \App::$http->readDeleteResult($url, $process)->getEntity(); } public function sendConfirmationEmail(?Process $process): Process { - $url = "/process/{$process['id']}/{$process['authKey']}/confirmation/mail/"; + $url = "/process/{$process->id}/{$process->authKey}/confirmation/mail/"; return \App::$http->readPostResult($url, $process)->getEntity(); } public function sendPreconfirmationEmail(?Process $process): Process { - $url = "/process/{$process['id']}/{$process['authKey']}/preconfirmation/mail/"; + $url = "/process/{$process->id}/{$process->authKey}/preconfirmation/mail/"; return \App::$http->readPostResult($url, $process)->getEntity(); } public function sendCancelationEmail(?Process $process): Process { - $url = "/process/{$process['id']}/{$process['authKey']}/delete/mail/"; + $url = "/process/{$process->id}/{$process->authKey}/delete/mail/"; return \App::$http->readPostResult($url, $process)->getEntity(); } diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php index 21d955753..68921faa1 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php @@ -439,36 +439,38 @@ public static function getBookableFreeDays(array $queryParams): array } } - public static function getFreeAppointments(array $params): ProcessList|array - { + public static function getFreeAppointments( + int $officeId, + array $serviceIds, + array $serviceCounts, + array $date + ): ProcessList|array { $office = [ - 'id' => $params['officeId'], + 'id' => $officeId, 'source' => \App::$source_name ]; - + $requests = []; - - foreach ($params['serviceIds'] as $index => $serviceId) { + + foreach ($serviceIds as $index => $serviceId) { $service = [ 'id' => $serviceId, 'source' => \App::$source_name, - 'slotCount' => $params['serviceCounts'][$index] + 'slotCount' => $serviceCounts[$index] ]; $requests = array_merge($requests, array_fill(0, $service['slotCount'], $service)); } - + try { - $freeSlots = new ProcessList(); $freeSlots = ZmsApiClientService::getFreeTimeslots( new ProviderList([$office]), new RequestList($requests), - $params['date'], - $params['date'] + $date, + $date ); - + return $freeSlots; - } catch (\Exception $e) { return [ 'appointmentTimestamps' => [], @@ -478,6 +480,7 @@ public static function getFreeAppointments(array $params): ProcessList|array ]; } } + public static function getAvailableAppointments(array $queryParams): array {