Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
LinkTelegramEndpoint
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 handle
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace Olz\Api\Endpoints;
4
5use Olz\Api\OlzTypedEndpoint;
6use PhpTypeScriptApi\HttpError;
7
8/**
9 * @extends OlzTypedEndpoint<
10 *   ?array{},
11 *   array{
12 *     botName: non-empty-string,
13 *     pin: non-empty-string,
14 *   }
15 * >
16 */
17class LinkTelegramEndpoint extends OlzTypedEndpoint {
18    protected function handle(mixed $input): mixed {
19        $user = $this->authUtils()->getCurrentUser();
20        if (!$user) {
21            throw new HttpError(403, "Kein Zugriff!");
22        }
23
24        $bot_name = $this->telegramUtils()->getBotName();
25        $pin = $this->telegramUtils()->getFreshPinForUser($user);
26
27        return [
28            'botName' => $bot_name ?: '-',
29            'pin' => $pin ?: '-',
30        ];
31    }
32}