Lines 0.00% 0 / 29
Functions and Methods 0.00% 0 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ProcessPreconfirm 0.00% 0 / 29 0.00% 0 / 2 42 0.00% 0 / 1
 readResponse 0.00% 0 / 22 0.00% 0 / 1 6
 testProcessData 0.00% 0 / 7 0.00% 0 / 1 20
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsbackend\Process\Api;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsbackend\Process\Service\Process;
13
14/**
15 * @SuppressWarnings(CouplingBetweenObjects)
16 */
17class ProcessPreconfirm extends \BO\Zmsbackend\Api\BaseController
18{
19    /**
20     * @SuppressWarnings(Param)
21     * @return \Psr\Http\Message\ResponseInterface
22     */
23    #[\Override]
24    public function readResponse(
25        \Psr\Http\Message\RequestInterface $request,
26        \Psr\Http\Message\ResponseInterface $response,
27        array $args
28    ) {
29        \BO\Zmsbackend\Connection\Select::setCriticalReadSession();
30
31        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(3)->getValue();
32        $input = Validator::input()->isJson()->assertValid()->getValue();
33        $entity = new \BO\Zmsentities\Process($input);
34        $entity->testValid();
35        $this->testProcessData($entity);
36
37        $userAccount = (new \BO\Zmsbackend\Helper\User($request))->readWorkstation()->getUseraccount();
38        $process = (new \BO\Zmsbackend\Process\Service\Process())->readEntity($entity->id, $entity->authKey, 2);
39
40        if ('reserved' != $process->status) {
41            throw new \BO\Zmsbackend\Process\Exception\ProcessNotReservedAnymore();
42        }
43
44        $process = (new \BO\Zmsbackend\Process\Service\Process())->updateProcessStatus(
45            $process,
46            'preconfirmed',
47            \App::$now,
48            $resolveReferences,
49            $userAccount
50        );
51        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
52        $message->data = $process;
53
54        $response = Render::withLastModified($response, time(), '0');
55        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
56        return $response;
57    }
58
59    /**
60     * @return void
61     */
62    protected function testProcessData(\BO\Zmsentities\Process $entity)
63    {
64        $authCheck = (new \BO\Zmsbackend\Process\Service\Process())->readAuthKeyByProcessId($entity->id);
65
66        if (! (new \BO\Zmsbackend\Process\Service\Process())->isAppointmentAllowedWithSameMail($entity)) {
67            throw new \BO\Zmsbackend\Process\Exception\MoreThanAllowedAppointmentsPerMail();
68        }
69
70        if (! $authCheck) {
71            throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound();
72        } elseif ($authCheck['authKey'] !== $entity->authKey) {
73            throw new \BO\Zmsbackend\Process\Exception\AuthKeyMatchFailed();
74        }
75    }
76}