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    protected function testProcessData($entity)
61    {
62        $authCheck = (new \BO\Zmsbackend\Process\Service\Process())->readAuthKeyByProcessId($entity->id);
63
64        if (! (new \BO\Zmsbackend\Process\Service\Process())->isAppointmentAllowedWithSameMail($entity)) {
65            throw new \BO\Zmsbackend\Process\Exception\MoreThanAllowedAppointmentsPerMail();
66        }
67
68        if (! $authCheck) {
69            throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound();
70        } elseif ($authCheck['authKey'] !== $entity->authKey) {
71            throw new \BO\Zmsbackend\Process\Exception\AuthKeyMatchFailed();
72        }
73    }
74
75    protected function validateProcessLimits(\BO\Zmsentities\Process $process)
76    {
77        if (! (new \BO\Zmsbackend\Process\Service\Process())->isAppointmentSlotCountAllowed($process)) {
78            throw new \BO\Zmsbackend\Process\Exception\MoreThanAllowedSlotsPerAppointment();
79        }
80
81        if (! (new \BO\Zmsbackend\Process\Service\Process())->isServiceQuantityAllowed($process)) {
82            throw new \BO\Zmsbackend\Process\Exception\MoreThanAllowedQuantityPerService();
83        }
84    }
85}