Files
solidtime/app/Http/Resources/V1/TimeEntry/TimeEntryResource.php
Constantin Graf 7a3a9d7089 Fix Scramble API docs warnings
Remove redundant @var annotations from API resources and defer the user
access in the email unique rule of UserUpdateRequest, so rules() can be
evaluated by Scramble without route model binding. Add a test that fails
on any Scramble diagnostic and tests for the email unique rule.
2026-10-08 12:57:56 +02:00

55 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources\V1\TimeEntry;
use App\Http\Resources\V1\BaseResource;
use App\Models\TimeEntry;
use Illuminate\Http\Request;
/**
* @property TimeEntry $resource
*/
class TimeEntryResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, string|bool|int|null|array<string>>
*/
public function toArray(Request $request): array
{
return [
/** ID of time entry */
'id' => $this->resource->id,
/**
* Start of time entry (ISO 8601 format, UTC timezone, example: 2024-02-26T17:17:17Z)
*/
'start' => $this->formatDateTime($this->resource->start),
/**
* @var string|null $end End of time entry (ISO 8601 format, UTC timezone, example: 2024-02-26T17:17:17Z)
*/
'end' => $this->formatDateTime($this->resource->end),
/** @var int|null $duration Duration of time entry in seconds */
'duration' => (int) $this->resource->getDuration()?->totalSeconds,
/** @var string|null $description Description of time entry */
'description' => $this->resource->description,
/** ID of task */
'task_id' => $this->resource->task_id,
/** ID of project */
'project_id' => $this->resource->project_id,
/** ID of organization */
'organization_id' => $this->resource->organization_id,
/** ID of user */
'user_id' => $this->resource->user_id,
/** List of tag IDs */
'tags' => $this->resource->tags ?? [],
/** Whether time entry is billable */
'billable' => $this->resource->billable,
/** Type of the time entry (`work` time or a `break`) */
'type' => $this->resource->type->value,
];
}
}