diff --git a/zmsadmin/package-lock.json b/zmsadmin/package-lock.json index 4f081e326..fafdb39ed 100644 --- a/zmsadmin/package-lock.json +++ b/zmsadmin/package-lock.json @@ -2892,108 +2892,6 @@ "node": ">= 8" } }, - "node_modules/css-select": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", - "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", - "dev": true, - "license": "BSD-2-Clause", - "optional": true, - "peer": true, - "dependencies": { - "boolbase": "^1.0.0", - "css-what": "^6.1.0", - "domhandler": "^5.0.2", - "domutils": "^3.0.1", - "nth-check": "^2.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, - "node_modules/css-select/node_modules/dom-serializer": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", - "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.2", - "entities": "^4.2.0" - }, - "funding": { - "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" - } - }, - "node_modules/css-select/node_modules/domhandler": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", - "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", - "dev": true, - "license": "BSD-2-Clause", - "optional": true, - "peer": true, - "dependencies": { - "domelementtype": "^2.3.0" - }, - "engines": { - "node": ">= 4" - }, - "funding": { - "url": "https://github.com/fb55/domhandler?sponsor=1" - } - }, - "node_modules/css-select/node_modules/domutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz", - "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==", - "dev": true, - "license": "BSD-2-Clause", - "optional": true, - "peer": true, - "dependencies": { - "dom-serializer": "^2.0.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3" - }, - "funding": { - "url": "https://github.com/fb55/domutils?sponsor=1" - } - }, - "node_modules/css-select/node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "dev": true, - "license": "BSD-2-Clause", - "optional": true, - "peer": true, - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, - "node_modules/css-tree": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz", - "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "mdn-data": "2.0.30", - "source-map-js": "^1.0.1" - }, - "engines": { - "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0" - } - }, "node_modules/css-what": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", @@ -3007,48 +2905,6 @@ "url": "https://github.com/sponsors/fb55" } }, - "node_modules/csso": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/csso/-/csso-5.0.5.tgz", - "integrity": "sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "css-tree": "~2.2.0" - }, - "engines": { - "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/csso/node_modules/css-tree": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.2.1.tgz", - "integrity": "sha512-OA0mILzGc1kCOCSJerOeqDxDQ4HOh+G8NbOJFOTgOCzpw7fCBubk0fEyxp8AgOL/jvLgYA/uV0cMbe43ElF1JA==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "mdn-data": "2.0.28", - "source-map-js": "^1.0.1" - }, - "engines": { - "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/csso/node_modules/mdn-data": { - "version": "2.0.28", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.28.tgz", - "integrity": "sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==", - "dev": true, - "license": "CC0-1.0", - "optional": true, - "peer": true - }, "node_modules/data-view-buffer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/data-view-buffer/-/data-view-buffer-1.0.1.tgz", @@ -4846,7 +4702,8 @@ "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true }, "node_modules/js-yaml": { "version": "3.14.1", @@ -5267,6 +5124,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dev": true, "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" }, @@ -5282,15 +5140,6 @@ "node": ">= 0.8.0" } }, - "node_modules/mdn-data": { - "version": "2.0.30", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", - "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==", - "dev": true, - "license": "CC0-1.0", - "optional": true, - "peer": true - }, "node_modules/micromatch": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", @@ -5845,6 +5694,7 @@ "version": "18.3.1", "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "dev": true, "dependencies": { "loose-envify": "^1.1.0" }, @@ -6339,21 +6189,6 @@ "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "dev": true }, - "node_modules/srcset": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/srcset/-/srcset-5.0.1.tgz", - "integrity": "sha512-/P1UYbGfJVlxZag7aABNRrulEXAwCSDo7fklafOQrantuPTDmYgijJMks2zusPCVzgW9+4P69mq7w6pYuZpgxw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/ssr-window": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ssr-window/-/ssr-window-3.0.0.tgz", @@ -6544,34 +6379,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/svgo": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/svgo/-/svgo-3.3.2.tgz", - "integrity": "sha512-OoohrmuUlBs8B8o6MB2Aevn+pRIH9zDALSR+6hhqVfa6fRwG/Qw9VUMSMW9VNg2CFc/MTIfabtdOVl9ODIJjpw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "@trysound/sax": "0.2.0", - "commander": "^7.2.0", - "css-select": "^5.1.0", - "css-tree": "^2.3.1", - "css-what": "^6.1.0", - "csso": "^5.0.5", - "picocolors": "^1.0.0" - }, - "bin": { - "svgo": "bin/svgo" - }, - "engines": { - "node": ">=14.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/svgo" - } - }, "node_modules/swiper": { "version": "6.8.4", "resolved": "https://registry.npmjs.org/swiper/-/swiper-6.8.4.tgz", diff --git a/zmscalldisplay/package-lock.json b/zmscalldisplay/package-lock.json index 87a516364..79ee0a2b1 100644 --- a/zmscalldisplay/package-lock.json +++ b/zmscalldisplay/package-lock.json @@ -6485,4 +6485,4 @@ } } } -} \ No newline at end of file +} diff --git a/zmscitizenapi/bootstrap.php b/zmscitizenapi/bootstrap.php index 5599065f2..a4c3de3c1 100644 --- a/zmscitizenapi/bootstrap.php +++ b/zmscitizenapi/bootstrap.php @@ -1,9 +1,4 @@ get( '/scope-by-id/', - '\BO\Zmscitizenapi\ScopeByIdGet' + '\BO\Zmscitizenapi\ScopeById' ) - ->setName("ScopeByIdGet"); + ->setName("ScopeById"); /** * @swagger @@ -294,7 +294,7 @@ * meta: * $ref: "schema/metaresult.json" * data: - * $ref: "schema/citizenapi/appointment.json" + * $ref: "schema/citizenapi/thinnedProcess.json" * 400: * description: Invalid input * schema: @@ -318,9 +318,9 @@ */ \App::$slim->get( '/appointment/', - '\BO\Zmscitizenapi\AppointmentGet' + '\BO\Zmscitizenapi\AppointmentById' ) - ->setName("AppointmentGet"); + ->setName("AppointmentById"); /** * @swagger @@ -342,9 +342,9 @@ */ \App::$slim->get( '/captcha-details/', - '\BO\Zmscitizenapi\CaptchaGet' + '\BO\Zmscitizenapi\Captcha' ) - ->setName("CaptchaGet"); + ->setName("Captcha"); /** * @swagger @@ -369,7 +369,7 @@ * meta: * $ref: "schema/metaresult.json" * data: - * $ref: "schema/citizenapi/appointment.json" + * $ref: "schema/citizenapi/thinnedProcess.json" * 400: * description: Invalid input * schema: @@ -420,7 +420,7 @@ * meta: * $ref: "schema/metaresult.json" * data: - * $ref: "schema/citizenapi/appointment.json" + * $ref: "schema/citizenapi/thinnedProcess.json" * 400: * description: Invalid input * schema: @@ -471,7 +471,7 @@ * meta: * $ref: "schema/metaresult.json" * data: - * $ref: "schema/citizenapi/appointment.json" + * $ref: "schema/citizenapi/thinnedProcess.json" * 400: * description: Invalid input * schema: @@ -522,7 +522,7 @@ * meta: * $ref: "schema/metaresult.json" * data: - * $ref: "schema/citizenapi/appointment.json" + * $ref: "schema/citizenapi/thinnedProcess.json" * 400: * description: Invalid input * schema: @@ -573,7 +573,7 @@ * meta: * $ref: "schema/metaresult.json" * data: - * $ref: "schema/citizenapi/appointment.json" + * $ref: "schema/citizenapi/thinnedProcess.json" * 400: * description: Invalid input * schema: diff --git a/zmscitizenapi/src/Zmscitizenapi/AppointmentById.php b/zmscitizenapi/src/Zmscitizenapi/AppointmentById.php new file mode 100644 index 000000000..01a099a1c --- /dev/null +++ b/zmscitizenapi/src/Zmscitizenapi/AppointmentById.php @@ -0,0 +1,35 @@ +getQueryParams(); + $processId = isset($queryParams['processId']) && is_numeric($queryParams['processId']) ? (int)$queryParams['processId'] : null; + $authKey = isset($queryParams['authKey']) && is_string($queryParams['authKey']) && trim($queryParams['authKey']) !== '' ? $queryParams['authKey'] : null; + + $result = ZmsApiFacadeService::getThinnedProcessById($processId, $authKey); + + if (!empty($result['errors'])) { + $errorCodes = array_column($result['errors'], 'errorCode'); + $statusCode = in_array('appointmentNotFound', $errorCodes) ? 404 : 400; + return $this->createJsonResponse($response, $result, $statusCode); + } + + if (isset($result) && $result instanceof ThinnedProcess) { + $thinnedProcess = $result; + return $this->createJsonResponse($response, $thinnedProcess->toArray(), 200); + } + + return $this->createJsonResponse($response, $result, 400); + } + +} diff --git a/zmscitizenapi/src/Zmscitizenapi/AppointmentGet.php b/zmscitizenapi/src/Zmscitizenapi/AppointmentGet.php deleted file mode 100644 index 71e29dbd1..000000000 --- a/zmscitizenapi/src/Zmscitizenapi/AppointmentGet.php +++ /dev/null @@ -1,23 +0,0 @@ -getQueryParams(); - $processId = isset($queryParams['processId']) && is_numeric($queryParams['processId']) ? (int)$queryParams['processId'] : null; - $authKey = isset($queryParams['authKey']) && is_string($queryParams['authKey']) && trim($queryParams['authKey']) !== '' ? $queryParams['authKey'] : null; - - $result = ZmsApiFacadeService::getProcessById($processId, $authKey); - - return $this->createJsonResponse($response, $result['data'] ?? $result, $result['status']); - } - -} diff --git a/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php b/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php index ace057fbb..43491109d 100644 --- a/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php +++ b/zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php @@ -9,6 +9,7 @@ use \BO\Zmscitizenapi\Services\MapperService; use \BO\Zmscitizenapi\Services\ValidationService; use \BO\Zmscitizenapi\Services\ZmsApiFacadeService; +use \BO\Zmscitizenapi\Models\ThinnedProcess; use \BO\Zmsentities\Process; use \BO\Zmsentities\Scope; use \BO\Zmsentities\Collection\ProcessList; @@ -105,10 +106,12 @@ public function readResponse(RequestInterface $request, ResponseInterface $respo } } - $thinnedProcessData = UtilityHelper::getThinnedProcessData($reservedProcess); - $thinnedProcessData = array_merge($thinnedProcessData, ['officeId' => $officeId]); + $appointment = new ThinnedProcess(); + $appointment = UtilityHelper::processToThinnedProcess($reservedProcess); - return $this->createJsonResponse($response, $thinnedProcessData, 200); + $appointment = array_merge($appointment->toArray(), ['officeId' => $officeId]); + + return $this->createJsonResponse($response, $appointment, 200); } catch (\Exception $e) { return $this->createJsonResponse($response, [ diff --git a/zmscitizenapi/src/Zmscitizenapi/AppointmentUpdate.php b/zmscitizenapi/src/Zmscitizenapi/AppointmentUpdate.php index c779eab45..f9f077011 100644 --- a/zmscitizenapi/src/Zmscitizenapi/AppointmentUpdate.php +++ b/zmscitizenapi/src/Zmscitizenapi/AppointmentUpdate.php @@ -3,10 +3,12 @@ namespace BO\Zmscitizenapi; use \BO\Zmscitizenapi\BaseController; -use \BO\Zmscitizenapi\Services\ZmsApiFacadeService; -use \BO\Zmscitizenapi\Services\ValidationService; use \BO\Zmscitizenapi\Helper\UtilityHelper; -use BO\Zmscitizenapi\Services\ExceptionService; +use \BO\Zmscitizenapi\Models\ThinnedProcess; +use \BO\Zmscitizenapi\Services\ExceptionService; +use \BO\Zmscitizenapi\Services\ValidationService; +use \BO\Zmscitizenapi\Services\ZmsApiFacadeService; +use \BO\Zmsentities\Client; use \BO\Zmsentities\Process; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -17,7 +19,7 @@ class AppointmentUpdate extends BaseController public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { $request = $request instanceof ServerRequestInterface ? $request : null; - + $body = $request->getParsedBody(); $processId = $body['processId'] ?? null; $authKey = $body['authKey'] ?? null; @@ -25,35 +27,38 @@ public function readResponse(RequestInterface $request, ResponseInterface $respo $email = $body['email'] ?? null; $telephone = $body['telephone'] ?? null; $customTextfield = $body['customTextfield'] ?? null; - + $errors = ValidationService::validateUpdateAppointmentInputs($processId, $authKey, $familyName, $email, $telephone, $customTextfield); if (!empty($errors['errors'])) { return $this->createJsonResponse($response, $errors, 400); } - + try { - - $reservedProcess = ZmsApiFacadeService::getProcessById($processId, $authKey); + $reservedProcess = new ThinnedProcess(); + $reservedProcess = ZmsApiFacadeService::getThinnedProcessById($processId, $authKey); if (!empty($reservedProcess['errors'])) { return $this->createJsonResponse($response, $reservedProcess, 404); } - - $reservedProcess['clients'][0]['familyName'] = $familyName; - $reservedProcess['clients'][0]['email'] = $email; - $reservedProcess['clients'][0]['telephone'] = $telephone; - $reservedProcess['customTextfield'] = $customTextfield; - - $updatedProcess = ZmsApiFacadeService::updateClientData(new Process($reservedProcess)); - + + $reservedProcess->familyName = $familyName ?? $reservedProcess->familyName ?? null; + $reservedProcess->email = $email ?? $reservedProcess->email ?? null; + $reservedProcess->telephone = $telephone ?? $reservedProcess->telephone ?? null; + $reservedProcess->customTextfield = $customTextfield ?? $reservedProcess->customTextfield ?? null; + + $processEntity = UtilityHelper::thinnedProcessToProcess($reservedProcess); + + $updatedProcess = ZmsApiFacadeService::updateClientData($processEntity); + if (isset($updatedProcess['error']) && $updatedProcess['error'] === 'tooManyAppointmentsWithSameMail') { return $this->createJsonResponse($response, ExceptionService::tooManyAppointmentsWithSameMail(), 406); } - - $thinnedProcessData = UtilityHelper::getThinnedProcessData($updatedProcess); - return $this->createJsonResponse($response, $thinnedProcessData, 200); - + + $appointment = UtilityHelper::processToThinnedProcess($updatedProcess); + return $this->createJsonResponse($response, $appointment->toArray(), 200); + } catch (\Exception $e) { throw $e; } } + } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/CaptchaGet.php b/zmscitizenapi/src/Zmscitizenapi/Captcha.php similarity index 92% rename from zmscitizenapi/src/Zmscitizenapi/CaptchaGet.php rename to zmscitizenapi/src/Zmscitizenapi/Captcha.php index 9d5818ecb..671e06a26 100644 --- a/zmscitizenapi/src/Zmscitizenapi/CaptchaGet.php +++ b/zmscitizenapi/src/Zmscitizenapi/Captcha.php @@ -7,7 +7,7 @@ use Psr\Http\Message\ResponseInterface; use \BO\Zmscitizenapi\Services\FriendlyCaptchaService; -class CaptchaGet extends BaseController +class Captcha extends BaseController { public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { diff --git a/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php b/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php index 9a7a552c4..b18d176a6 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php +++ b/zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php @@ -1,7 +1,15 @@ id)) { - return []; + return null; } - + $subRequestCounts = []; $mainServiceId = null; $mainServiceCount = 0; - + $requests = $myProcess->requests ?? []; if ($requests) { $requests = is_array($requests) ? $requests : iterator_to_array($requests); @@ -74,21 +82,85 @@ public static function getThinnedProcessData(?Process $myProcess): array } } - return [ - 'processId' => $myProcess->id, - 'timestamp' => isset($myProcess->appointments[0]) ? $myProcess->appointments[0]->date : null, - 'authKey' => $myProcess->authKey ?? null, - 'familyName' => isset($myProcess->clients[0]) ? $myProcess->clients[0]->familyName : null, - 'customTextfield' => $myProcess->customTextfield ?? null, - 'email' => isset($myProcess->clients[0]) ? $myProcess->clients[0]->email : null, - 'telephone' => isset($myProcess->clients[0]) ? $myProcess->clients[0]->telephone : null, - 'officeName' => $myProcess->scope->contact->name ?? null, - 'officeId' => $myProcess->scope->provider->id ?? null, - 'scope' => $myProcess->scope ?? null, - 'subRequestCounts' => array_values($subRequestCounts), - 'serviceId' => $mainServiceId, - 'serviceCount' => $mainServiceCount, - ]; + $thinnedProcess = new ThinnedProcess(); + $thinnedProcess->processId = $myProcess->id; + $thinnedProcess->timestamp = isset($myProcess->appointments[0]) ? $myProcess->appointments[0]->date : null; + $thinnedProcess->authKey = $myProcess->authKey ?? null; + $thinnedProcess->familyName = isset($myProcess->clients[0]) ? $myProcess->clients[0]->familyName : null; + $thinnedProcess->customTextfield = $myProcess->customTextfield ?? null; + $thinnedProcess->email = isset($myProcess->clients[0]) ? $myProcess->clients[0]->email : null; + $thinnedProcess->telephone = isset($myProcess->clients[0]) ? $myProcess->clients[0]->telephone : null; + $thinnedProcess->officeName = $myProcess->scope->contact->name ?? null; + $thinnedProcess->officeId = $myProcess->scope->provider->id ?? null; + $thinnedProcess->scope = $myProcess->scope ?? null; + $thinnedProcess->subRequestCounts = array_values($subRequestCounts); + $thinnedProcess->serviceId = $mainServiceId; + $thinnedProcess->serviceCount = $mainServiceCount; + + return $thinnedProcess; + } + + public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess): Process + { + 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(); + $scope->contact->name = $thinnedProcess->officeName; + } + if (isset($thinnedProcess->officeId)) { + $scope->provider = new Provider(); + $scope->provider->id = $thinnedProcess->officeId; + $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(); + $request->id = $mainServiceId; + $request->source = \App::$source_name; + $requests[] = $request; + } + foreach ($subRequestCounts as $subRequest) { + for ($i = 0; $i < ($subRequest['count'] ?? 0); $i++) { + $request = new Request(); + $request->id = $subRequest['id']; + $request->source = \App::$source_name; + $requests[] = $request; + } + } + $processEntity->requests = $requests; + + $processEntity->lastChange = time(); + $processEntity->createIP = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1'; + $processEntity->createTimestamp = time(); + + return $processEntity; } + } diff --git a/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php new file mode 100644 index 000000000..ca905eff3 --- /dev/null +++ b/zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php @@ -0,0 +1,19 @@ + $this->processId ?? null, + 'timestamp' => $this->timestamp ?? null, + 'authKey' => $this->authKey ?? null, + 'familyName' => $this->familyName ?? null, + 'customTextfield' => $this->customTextfield ?? null, + 'email' => $this->email ?? null, + 'telephone' => $this->telephone ?? null, + 'officeName' => $this->officeName ?? null, + 'officeId' => $this->officeId ?? null, + 'scope' => $this->scope ?? null, + 'subRequestCounts' => $this->subRequestCounts ?? [], + 'serviceId' => $this->serviceId ?? null, + 'serviceCount' => $this->serviceCount ?? 0, + ]; + } +} diff --git a/zmscitizenapi/src/Zmscitizenapi/ScopeByIdGet.php b/zmscitizenapi/src/Zmscitizenapi/ScopeById.php similarity index 96% rename from zmscitizenapi/src/Zmscitizenapi/ScopeByIdGet.php rename to zmscitizenapi/src/Zmscitizenapi/ScopeById.php index 415be20a6..36159a456 100644 --- a/zmscitizenapi/src/Zmscitizenapi/ScopeByIdGet.php +++ b/zmscitizenapi/src/Zmscitizenapi/ScopeById.php @@ -8,7 +8,7 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -class ScopeByIdGet extends BaseController +class ScopeById extends BaseController { public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/ValidationService.php b/zmscitizenapi/src/Zmscitizenapi/Services/ValidationService.php index 53e467262..2b4fe3625 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/ValidationService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/ValidationService.php @@ -67,7 +67,7 @@ public static function validateGetProcessById(?int $processId, ?string $authKey) $errors[] = [ 'status' => 400, 'errorCode' => 'invalidProcessId', - 'errorMessage' => 'processId should be a 32-bit integer.', + 'errorMessage' => 'processId should be a positive 32-bit integer.', ]; } @@ -344,6 +344,7 @@ public static function validateUpdateAppointmentInputs(?int $processId, ?string 'status' => 400, 'errorCode' => 'invalidProcessId', 'errorMessage' => 'processId should be a positive 32-bit integer.', + //'errorMessage' => 'processId should be a positive 32-bit integer.', ]; } diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php index 9bbfc5306..4e8560671 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php @@ -141,26 +141,11 @@ public static function reserveTimeslot(Process $appointmentProcess, array $servi public static function submitClientData(Process $process): Process|array { - $processEntity = new Process(); - $processEntity->id = $process['data']['processId'] ?? null; - $processEntity->authKey = $process['data']['authKey'] ?? null; - $processEntity->appointments = $process['appointments'] ?? []; - $processEntity->clients = $process['clients'] ?? []; - $processEntity->scope = $process['data']['scope'] ?? null; - $processEntity->customTextfield = $process['customTextfield'] ?? null; - $processEntity->lastChange = $process['lastChange'] ?? time(); - - if (isset($process['queue'])) { - $processEntity->queue = $process['queue']; - } - - $processEntity->createIP = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1'; - $processEntity->createTimestamp = time(); - - $url = "/process/{$processEntity->id}/{$processEntity->authKey}/"; + + $url = "/process/{$process->id}/{$process->authKey}/"; try { - $result = \App::$http->readPostResult($url, $processEntity); + $result = \App::$http->readPostResult($url, $process); return $result->getEntity(); } catch (\Exception $e) { $exceptionName = json_decode(json_encode($e), true)['template'] ?? null; @@ -174,6 +159,7 @@ public static function submitClientData(Process $process): Process|array } } } + public function preconfirmProcess(?Process $process): Process { diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php index c2d53237c..21d955753 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiFacadeService.php @@ -3,6 +3,7 @@ namespace BO\Zmscitizenapi\Services; use \BO\Zmscitizenapi\Helper\UtilityHelper; +use \BO\Zmscitizenapi\Models\ThinnedProcess; use \BO\Zmscitizenapi\Services\ZmsApiClientService; use \BO\Zmsentities\Process; use \BO\Zmsentities\Scope; @@ -569,7 +570,7 @@ public static function reserveTimeslot(Process $appointmentProcess, array $servi return ZmsApiClientService::reserveTimeslot($appointmentProcess, $serviceIds, $serviceCounts); } - public static function getProcessById(?int $processId, ?string $authKey): array + public static function getThinnedProcessById(?int $processId, ?string $authKey): ThinnedProcess|array { $errors = ValidationService::validateGetProcessById($processId, $authKey); if (!empty($errors['errors'])) { @@ -585,8 +586,10 @@ public static function getProcessById(?int $processId, ?string $authKey): array return $errors; } - $responseData = UtilityHelper::getThinnedProcessData($process); - return ['data' => $responseData, 'status' => 200]; + $thinnedProcess = new ThinnedProcess(); + $thinnedProcess = UtilityHelper::processToThinnedProcess($process); + + return $thinnedProcess; } catch (\Exception $e) { if (strpos($e->getMessage(), 'kein Termin gefunden') !== false) { diff --git a/zmscitizenapi/tests/Zmscitizenapi/AppointmentGetTest.php b/zmscitizenapi/tests/Zmscitizenapi/AppointmentByIdTest.php similarity index 96% rename from zmscitizenapi/tests/Zmscitizenapi/AppointmentGetTest.php rename to zmscitizenapi/tests/Zmscitizenapi/AppointmentByIdTest.php index 2e4b60bd8..26254a690 100644 --- a/zmscitizenapi/tests/Zmscitizenapi/AppointmentGetTest.php +++ b/zmscitizenapi/tests/Zmscitizenapi/AppointmentByIdTest.php @@ -2,11 +2,11 @@ namespace BO\Zmscitizenapi\Tests; -use BO\Zmscitizenapi\AppointmentGet; +use BO\Zmscitizenapi\AppointmentById; -class AppointmentGetTest extends Base +class AppointmentByIdTest extends Base { - protected $classname = "AppointmentGet"; + protected $classname = "AppointmentById"; public function testRendering() { @@ -171,7 +171,7 @@ public function testMissingProcessId() [ 'status' => 400, 'errorCode' => 'invalidProcessId', - 'errorMessage' => 'processId should be a 32-bit integer.' + 'errorMessage' => 'processId should be a positive 32-bit integer.' ] ], 'status' => 400 @@ -216,7 +216,7 @@ public function testInvalidProcessId() [ 'status' => 400, 'errorCode' => 'invalidProcessId', - 'errorMessage' => 'processId should be a 32-bit integer.' + 'errorMessage' => 'processId should be a positive 32-bit integer.' ] ], 'status' => 400 @@ -259,7 +259,7 @@ public function testBothParametersMissing() [ 'status' => 400, 'errorCode' => 'invalidProcessId', - 'errorMessage' => 'processId should be a 32-bit integer.', + 'errorMessage' => 'processId should be a positive 32-bit integer.', ], [ 'status' => 400, diff --git a/zmscitizenapi/tests/Zmscitizenapi/CaptchaGetTest.php b/zmscitizenapi/tests/Zmscitizenapi/CaptchaTest.php similarity index 95% rename from zmscitizenapi/tests/Zmscitizenapi/CaptchaGetTest.php rename to zmscitizenapi/tests/Zmscitizenapi/CaptchaTest.php index 140dd9eca..a64141acb 100644 --- a/zmscitizenapi/tests/Zmscitizenapi/CaptchaGetTest.php +++ b/zmscitizenapi/tests/Zmscitizenapi/CaptchaTest.php @@ -4,9 +4,9 @@ use \BO\Zmscitizenapi\Application; -class CaptchaGetTest extends Base +class CaptchaTest extends Base { - protected $classname = "CaptchaGet"; + protected $classname = "Captcha"; public function setUp(): void { diff --git a/zmscitizenapi/tests/Zmscitizenapi/ScopeByIdGetTest.php b/zmscitizenapi/tests/Zmscitizenapi/ScopeByIdTest.php similarity index 99% rename from zmscitizenapi/tests/Zmscitizenapi/ScopeByIdGetTest.php rename to zmscitizenapi/tests/Zmscitizenapi/ScopeByIdTest.php index 10557ec2e..2651f3241 100644 --- a/zmscitizenapi/tests/Zmscitizenapi/ScopeByIdGetTest.php +++ b/zmscitizenapi/tests/Zmscitizenapi/ScopeByIdTest.php @@ -4,10 +4,10 @@ use BO\Slim\Render; -class ScopeByIdGetTest extends Base +class ScopeByIdTest extends Base { - protected $classname = "ScopeByIdGet"; + protected $classname = "ScopeById"; public function testRendering() { diff --git a/zmsentities/schema/citizenapi/appointment.json b/zmsentities/schema/citizenapi/thinnedProcess.json similarity index 100% rename from zmsentities/schema/citizenapi/appointment.json rename to zmsentities/schema/citizenapi/thinnedProcess.json diff --git a/zmsentities/src/Zmsentities/Process.php b/zmsentities/src/Zmsentities/Process.php index ad187fc94..0692bca58 100644 --- a/zmsentities/src/Zmsentities/Process.php +++ b/zmsentities/src/Zmsentities/Process.php @@ -13,23 +13,23 @@ class Process extends Schema\Entity { const PRIMARY = 'id'; - public const STATUS_FREE = 'free'; - public const STATUS_RESERVED = 'reserved'; - public const STATUS_CONFIRMED = 'confirmed'; - public const STATUS_PRECONFIRMED = 'preconfirmed'; - public const STATUS_QUEUED = 'queued'; - public const STATUS_CALLED = 'called'; + public const STATUS_FREE = 'free'; + public const STATUS_RESERVED = 'reserved'; + public const STATUS_CONFIRMED = 'confirmed'; + public const STATUS_PRECONFIRMED = 'preconfirmed'; + public const STATUS_QUEUED = 'queued'; + public const STATUS_CALLED = 'called'; public const STATUS_PROCESSING = 'processing'; - public const STATUS_PENDING = 'pending'; - public const STATUS_PICKUP = 'pickup'; - public const STATUS_FINISHED = 'finished'; - public const STATUS_MISSED = 'missed'; - public const STATUS_PARKED = 'parked'; - public const STATUS_ARCHIVED = 'archived'; - public const STATUS_DELETED = 'deleted'; + public const STATUS_PENDING = 'pending'; + public const STATUS_PICKUP = 'pickup'; + public const STATUS_FINISHED = 'finished'; + public const STATUS_MISSED = 'missed'; + public const STATUS_PARKED = 'parked'; + public const STATUS_ARCHIVED = 'archived'; + public const STATUS_DELETED = 'deleted'; public const STATUS_ANONYMIZED = 'anonymized'; - public const STATUS_BLOCKED = 'blocked'; - public const STATUS_CONFLICT = 'conflict'; + public const STATUS_BLOCKED = 'blocked'; + public const STATUS_CONFLICT = 'conflict'; public static $schema = "process.json"; @@ -114,7 +114,7 @@ public function addRequests($source, $requestCSV) { $requestList = $this->getRequests(); foreach (explode(',', $requestCSV) as $id) { - if (! $requestList->hasRequests($id)) { + if (!$requestList->hasRequests($id)) { $this->requests[] = new Request(array( 'source' => $source, 'id' => $id @@ -149,22 +149,22 @@ public function hasScopeAdmin() public function sendAdminMailOnConfirmation() { - return (bool)((int)$this->toProperty()->scope->preferences->client->adminMailOnAppointment->get()); + return (bool) ((int) $this->toProperty()->scope->preferences->client->adminMailOnAppointment->get()); } - + public function sendAdminMailOnDeleted() { - return (bool)((int)$this->toProperty()->scope->preferences->client->adminMailOnDeleted->get()); + return (bool) ((int) $this->toProperty()->scope->preferences->client->adminMailOnDeleted->get()); } public function sendAdminMailOnUpdated() { - return (bool)((int)$this->toProperty()->scope->preferences->client->adminMailOnUpdated->get()); + return (bool) ((int) $this->toProperty()->scope->preferences->client->adminMailOnUpdated->get()); } public function shouldSendAdminMailOnClerkMail() { - return (bool)((int)$this->toProperty()->scope->preferences->client->adminMailOnMailSent->get()); + return (bool) ((int) $this->toProperty()->scope->preferences->client->adminMailOnMailSent->get()); } public function withUpdatedData($requestData, \DateTimeInterface $dateTime, $scope = null, $notice = '') @@ -248,7 +248,7 @@ public function getAppointments() if (!$this['appointments'] instanceof Collection\AppointmentList) { $this['appointments'] = new Collection\AppointmentList($this['appointments']); foreach ($this['appointments'] as $index => $appointment) { - if (! $appointment instanceof Appointment) { + if (!$appointment instanceof Appointment) { $this['appointments'][$index] = new Appointment($appointment); } } @@ -265,7 +265,7 @@ public function getClients() if (!$this['clients'] instanceof Collection\ClientList) { $this['clients'] = new Collection\ClientList($this['clients']); foreach ($this['clients'] as $index => $client) { - if (! $client instanceof Client) { + if (!$client instanceof Client) { $this['clients'][$index] = new Client($client); } } @@ -488,7 +488,7 @@ public function withLessData(array $keepArray = []) { $entity = clone $this; - if (! in_array('availability', $keepArray)) { + if (!in_array('availability', $keepArray)) { foreach ($entity['appointments'] as $appointment) { if ($appointment->toProperty()->scope->isAvailable()) { $scopeId = $appointment['scope']['id']; @@ -513,36 +513,26 @@ public function withLessData(array $keepArray = []) if ($entity->status == 'free') { // delete keys - foreach ([ - 'authKey', - 'queue', - 'requests', - ] as $key) { - if (! in_array($key, $keepArray) && $entity->toProperty()->$key->isAvailable()) { + foreach (['authKey', 'queue', 'requests',] as $key) { + if (!in_array($key, $keepArray) && $entity->toProperty()->$key->isAvailable()) { unset($entity[$key]); } } // delete if empty - foreach ([ - 'amendment', - 'id', - 'authKey', - 'archiveId', - 'reminderTimestamp', - ] as $key) { - if (! in_array($key, $keepArray) && $entity->toProperty()->$key->isAvailable() && !$entity[$key]) { + foreach (['amendment', 'id', 'authKey', 'archiveId', 'reminderTimestamp',] as $key) { + if (!in_array($key, $keepArray) && $entity->toProperty()->$key->isAvailable() && !$entity[$key]) { unset($entity[$key]); } } - if (! in_array('provider', $keepArray) && $entity->toProperty()->scope->provider->data->isAvailable()) { + if (!in_array('provider', $keepArray) && $entity->toProperty()->scope->provider->data->isAvailable()) { unset($entity['scope']['provider']['data']); } } - if (! in_array('dayoff', $keepArray) && $entity->toProperty()->scope->dayoff->isAvailable()) { + if (!in_array('dayoff', $keepArray) && $entity->toProperty()->scope->dayoff->isAvailable()) { unset($entity['scope']['dayoff']); } - if (! in_array('scope', $keepArray) && $entity->toProperty()->scope->preferences->isAvailable()) { + if (!in_array('scope', $keepArray) && $entity->toProperty()->scope->preferences->isAvailable()) { unset($entity['scope']['preferences']); } return $entity; @@ -659,11 +649,11 @@ public function __toString() { $string = "process#"; $string .= $this->id ?: $this->archiveId; - $string .= ":".$this->authKey; + $string .= ":" . $this->authKey; $string .= " (" . $this->status . ")"; $string .= " " . $this->getFirstAppointment()->toDateTime()->format('c'); $string .= " " . ($this->isWithAppointment() ? "appoint" : "arrival:" . $this->getArrivalTime()->format('c')); - $string .= " " . $this->getFirstAppointment()->slotCount."slots"; + $string .= " " . $this->getFirstAppointment()->slotCount . "slots"; $string .= "*" . count($this->appointments); foreach ($this->getRequests() as $request) { $string .= " " . $request['source'] . "." . $request['id'];