Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| UpdateTerminEndpoint | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
4.00 | |
0.00% |
0 / 1 |
| handle | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
4.00 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Termine\Endpoints; |
| 4 | |
| 5 | use Olz\Api\OlzUpdateEntityTypedEndpoint; |
| 6 | use PhpTypeScriptApi\HttpError; |
| 7 | |
| 8 | /** |
| 9 | * @phpstan-import-type OlzTerminId from TerminEndpointTrait |
| 10 | * @phpstan-import-type OlzTerminData from TerminEndpointTrait |
| 11 | * |
| 12 | * @extends OlzUpdateEntityTypedEndpoint<OlzTerminId, OlzTerminData> |
| 13 | */ |
| 14 | class UpdateTerminEndpoint extends OlzUpdateEntityTypedEndpoint { |
| 15 | use TerminEndpointTrait; |
| 16 | |
| 17 | protected function handle(mixed $input): mixed { |
| 18 | $this->checkPermission('any'); |
| 19 | |
| 20 | $entity = $this->getEntityById($input['id']); |
| 21 | |
| 22 | $current_user = $this->authUtils()->getCurrentUser(); |
| 23 | $organizer_user = $entity->getOrganizerUser(); |
| 24 | $is_organizer = ($organizer_user && $current_user?->getId() === $organizer_user->getId()); |
| 25 | |
| 26 | if ( |
| 27 | !$this->entityUtils()->canUpdateOlzEntity($entity, $input['meta'], 'termine_admin') |
| 28 | && !$is_organizer |
| 29 | ) { |
| 30 | throw new HttpError(403, "Kein Zugriff!"); |
| 31 | } |
| 32 | |
| 33 | $this->entityUtils()->updateOlzEntity($entity, $input['meta']); |
| 34 | $this->updateEntityWithData($entity, $input['data']); |
| 35 | |
| 36 | $this->entityManager()->persist($entity); |
| 37 | $this->entityManager()->flush(); |
| 38 | $this->persistUploads($entity, $input['data']); |
| 39 | |
| 40 | return [ |
| 41 | 'id' => $entity->getId() ?? 0, |
| 42 | ]; |
| 43 | } |
| 44 | } |