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\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsdb\Process;
13
14/**
15 * @SuppressWarnings(CouplingBetweenObjects)
16 */
17class ProcessPreconfirm extends 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\Zmsdb\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 Helper\User($request))->readWorkstation()->getUseraccount();
38        $process = (new 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 Exception\Process\ProcessNotReservedAnymore();
43        }
44
45        $process = (new Process())->updateProcessStatus(
46            $process,
47            'preconfirmed',
48            \App::$now,
49            $resolveReferences,
50            $userAccount
51        );
52        $message = 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 Process())->readAuthKeyByProcessId($entity->id);
63
64        if (! (new Process())->isAppointmentAllowedWithSameMail($entity)) {
65            throw new Exception\Process\MoreThanAllowedAppointmentsPerMail();
66        }
67
68        if (! $authCheck) {
69            throw new Exception\Process\ProcessNotFound();
70        } elseif ($authCheck['authKey'] !== $entity->authKey) {
71            throw new Exception\Process\AuthKeyMatchFailed();
72        }
73    }
74
75    protected function validateProcessLimits(\BO\Zmsentities\Process $process)
76    {
77        if (! (new Process())->isAppointmentSlotCountAllowed($process)) {
78            throw new Exception\Process\MoreThanAllowedSlotsPerAppointment();
79        }
80
81        if (! (new Process())->isServiceQuantityAllowed($process)) {
82            throw new Exception\Process\MoreThanAllowedQuantityPerService();
83        }
84    }
85}