52 lines
2.2 KiB
PHP
52 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Actions\Projects\ResolveProjectTemplateState;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class ProjectResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$this->resource->loadMissing('projectTemplate');
|
|
|
|
$templateState = app(ResolveProjectTemplateState::class)->handle($this->resource);
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'key' => $this->key,
|
|
'project_template_id' => $this->project_template_id,
|
|
'project_template' => $this->projectTemplate === null
|
|
? null
|
|
: ProjectTemplateResource::make($this->projectTemplate)->resolve(),
|
|
'template_state' => $templateState === null
|
|
? null
|
|
: [
|
|
'effective_configuration' => Arr::get($templateState, 'effectiveConfiguration', []),
|
|
'inherited_areas' => Arr::get($templateState, 'inheritedAreas', []),
|
|
'inherited_configuration' => Arr::get($templateState, 'inheritedConfiguration', []),
|
|
'inherits_from_template' => Arr::get($templateState, 'inheritsFromTemplate', false),
|
|
'overridden_areas' => Arr::get($templateState, 'overriddenAreas', []),
|
|
'overridden_configuration' => Arr::get($templateState, 'overriddenConfiguration', []),
|
|
'template_configuration' => Arr::get($templateState, 'templateConfiguration', []),
|
|
'template_id' => Arr::get($templateState, 'templateId'),
|
|
'template_name' => Arr::get($templateState, 'templateName'),
|
|
'template_slug' => Arr::get($templateState, 'templateSlug'),
|
|
],
|
|
'show_author' => $this->show_author,
|
|
'show_story_points' => $this->show_story_points,
|
|
'created_at' => $this->created_at?->toISOString(),
|
|
'updated_at' => $this->updated_at?->toISOString(),
|
|
];
|
|
}
|
|
}
|