Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| UpdateLinkEndpoint | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| handle | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Service\Endpoints; |
| 4 | |
| 5 | use Olz\Api\OlzUpdateEntityTypedEndpoint; |
| 6 | use PhpTypeScriptApi\HttpError; |
| 7 | |
| 8 | /** |
| 9 | * @phpstan-import-type OlzLinkId from LinkEndpointTrait |
| 10 | * @phpstan-import-type OlzLinkData from LinkEndpointTrait |
| 11 | * |
| 12 | * @extends OlzUpdateEntityTypedEndpoint<OlzLinkId, OlzLinkData> |
| 13 | */ |
| 14 | class UpdateLinkEndpoint extends OlzUpdateEntityTypedEndpoint { |
| 15 | use LinkEndpointTrait; |
| 16 | |
| 17 | protected function handle(mixed $input): mixed { |
| 18 | $this->checkPermission('any'); |
| 19 | |
| 20 | $entity = $this->getEntityById($input['id']); |
| 21 | |
| 22 | if (!$this->entityUtils()->canUpdateOlzEntity($entity, $input['meta'], 'links')) { |
| 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 | |
| 32 | return [ |
| 33 | 'id' => $entity->getId() ?? 0, |
| 34 | ]; |
| 35 | } |
| 36 | } |