Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessPreconfirm
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 readResponse
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
6
 testProcessData
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
20
 validateProcessLimits
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
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        //$this->validateProcessLimits($process); Should be moved to zmscitizenapi.
41        if ('reserved' != $process->status) {
42            throw new \BO\Zmsbackend\Process\Exception\ProcessNotReservedAnymore();
43        }
44
45        $process = (new \BO\Zmsbackend\Process\Service\Process())->updateProcessStatus(
46            $process,
47            'preconfirmed',
48            \App::$now,
49            $resolveReferences,
50            $userAccount
51        );
52        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
53        $message->data = $process;
54
55        $response = Render::withLastModified($response, time(), '0');
56        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
57        return $response;
58    }
59
60    /**
61     * @return void
62     */
63    protected function testProcessData(\BO\Zmsentities\Process $entity)
64    {
65        $authCheck = (new \BO\Zmsbackend\Process\Service\Process())->readAuthKeyByProcessId($entity->id);
66
67        if (! (new \BO\Zmsbackend\Process\Service\Process())->isAppointmentAllowedWithSameMail($entity)) {
68            throw new \BO\Zmsbackend\Process\Exception\MoreThanAllowedAppointmentsPerMail();
69        }
70
71        if (! $authCheck) {
72            throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound();
73        } elseif ($authCheck['authKey'] !== $entity->authKey) {
74            throw new \BO\Zmsbackend\Process\Exception\AuthKeyMatchFailed();
75        }
76    }
77
78    /**
79     * @psalm-api
80     *
81     * @return void
82     */
83    protected function validateProcessLimits(\BO\Zmsentities\Process $process)
84    {
85        if (! (new \BO\Zmsbackend\Process\Service\Process())->isAppointmentSlotCountAllowed($process)) {
86            throw new \BO\Zmsbackend\Process\Exception\MoreThanAllowedSlotsPerAppointment();
87        }
88
89        if (! (new \BO\Zmsbackend\Process\Service\Process())->isServiceQuantityAllowed($process)) {
90            throw new \BO\Zmsbackend\Process\Exception\MoreThanAllowedQuantityPerService();
91        }
92    }
93}