mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 16:12:09 +00:00
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class DashboardRoomResource extends JsonResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->resource->id,
|
|
'title' => $this->resource->title,
|
|
'join_code' => $this->resource->join_code,
|
|
'current_round' => $this->resource->current_round,
|
|
'players_count' => $this->resource->players_count,
|
|
'players' => $this->resource->relationLoaded('players')
|
|
? $this->resource->players
|
|
->map(fn ($player): array => [
|
|
'id' => $player->id,
|
|
'name' => $player->name,
|
|
'is_moderator' => $player->is_moderator,
|
|
'is_owner' => $player->user_id === $this->resource->owner_id,
|
|
])
|
|
->values()
|
|
->all()
|
|
: [],
|
|
'last_activity_at' => $this->resource->last_activity_at?->toIso8601String(),
|
|
'closed_at' => $this->resource->closed_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|