Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ListTerminReactionsEndpoint
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 handle
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3namespace Olz\Termine\Endpoints;
4
5use Olz\Api\OlzTypedEndpoint;
6use Olz\Entity\Termine\TerminReaction;
7
8/**
9 * @phpstan-type OlzTerminReactionFilter array{terminId: int<1, max>}
10 * @phpstan-type OlzReaction array{
11 *   userId: int,
12 *   name: ?non-empty-string,
13 *   emoji: non-empty-string,
14 * }
15 *
16 * @extends OlzTypedEndpoint<
17 *   array{
18 *     filter: OlzTerminReactionFilter
19 *   },
20 *   array{
21 *     result: array<OlzReaction>
22 *   }
23 * >
24 */
25class ListTerminReactionsEndpoint extends OlzTypedEndpoint {
26    protected function handle(mixed $input): mixed {
27        $has_any_access = $this->authUtils()->hasPermission('any');
28        $termin_reaction_repo = $this->entityManager()->getRepository(TerminReaction::class);
29        $reactions = $termin_reaction_repo->findBy([
30            'termin' => $input['filter']['terminId'],
31        ]);
32        $result = [];
33        foreach ($reactions as $reaction) {
34            $result[] = [
35                'userId' => $reaction->getUser()->getId() ?? 0,
36                'name' => $has_any_access ? $reaction->getUser()->getFullName() ?: '?' : null,
37                'emoji' => $reaction->getEmoji() ?: '?',
38            ];
39        }
40        return [
41            'result' => $result,
42        ];
43    }
44}