mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 20:32:09 +00:00
34 lines
886 B
PHP
34 lines
886 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\Player;
|
|
use App\Models\Room;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class RoomPlayerResource extends JsonResource
|
|
{
|
|
public function __construct(Player $resource, private readonly Room $room)
|
|
{
|
|
parent::__construct($resource);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$vote = $this->resource->votes->first();
|
|
|
|
return [
|
|
'id' => $this->resource->id,
|
|
'name' => $this->resource->name,
|
|
'is_moderator' => $this->resource->is_moderator,
|
|
'is_owner' => $this->resource->user_id === $this->room->owner_id,
|
|
'has_voted' => $vote !== null,
|
|
'vote' => $this->room->revealed_at !== null ? $vote?->value : null,
|
|
];
|
|
}
|
|
}
|