Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateQuestionEndpoint
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 handle
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Olz\Faq\Endpoints;
4
5use Olz\Api\OlzUpdateEntityTypedEndpoint;
6use PhpTypeScriptApi\HttpError;
7
8/**
9 * @phpstan-import-type OlzQuestionId from QuestionEndpointTrait
10 * @phpstan-import-type OlzQuestionData from QuestionEndpointTrait
11 *
12 * @extends OlzUpdateEntityTypedEndpoint<OlzQuestionId, OlzQuestionData>
13 */
14class UpdateQuestionEndpoint extends OlzUpdateEntityTypedEndpoint {
15    use QuestionEndpointTrait;
16
17    protected function handle(mixed $input): mixed {
18        $this->checkPermission('faq');
19
20        $entity = $this->getEntityById($input['id']);
21
22        if (!$this->entityUtils()->canUpdateOlzEntity($entity, $input['meta'], 'faq')) {
23            throw new HttpError(403, "Kein Zugriff!");
24        }
25
26        $this->entityUtils()->updateOlzEntity($entity, $input['meta']);
27        $this->updateEntityWithData($entity, $input['data']);
28
29        $this->entityManager()->persist($entity);
30        $this->entityManager()->flush();
31        $this->persistUploads($entity, $input['data']);
32
33        return [
34            'id' => $entity->getId() ?? 0,
35        ];
36    }
37}