Refactor Inertia responses to use resources
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TicketResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'acceptance_criteria' => $this->acceptance_criteria,
|
||||
'assignee' => $this->whenLoaded(
|
||||
'assignee',
|
||||
fn (): ?array => $this->assignee === null
|
||||
? null
|
||||
: UserResource::make($this->assignee)->resolve(),
|
||||
),
|
||||
'assignee_user_id' => $this->assignee_user_id,
|
||||
'author' => $this->whenLoaded(
|
||||
'author',
|
||||
fn (): ?array => $this->author === null
|
||||
? null
|
||||
: UserResource::make($this->author)->resolve(),
|
||||
),
|
||||
'author_user_id' => $this->author_user_id,
|
||||
'blocked_comment' => $this->blocked_comment,
|
||||
'description' => $this->description,
|
||||
'field_values' => $this->whenLoaded(
|
||||
'fieldValues',
|
||||
fn (): array => TicketFieldValueResource::collection($this->fieldValues)->resolve(),
|
||||
),
|
||||
'is_blocked' => $this->is_blocked,
|
||||
'parent_ticket_id' => $this->parent_ticket_id,
|
||||
'project_id' => $this->project_id,
|
||||
'sequence_number' => $this->sequence_number,
|
||||
'story_points' => $this->story_points,
|
||||
'ticket_key' => $this->ticket_key,
|
||||
'ticket_priority' => $this->whenLoaded(
|
||||
'ticketPriority',
|
||||
fn (): ?array => $this->ticketPriority === null
|
||||
? null
|
||||
: TicketPriorityResource::make($this->ticketPriority)->resolve(),
|
||||
),
|
||||
'ticket_priority_id' => $this->ticket_priority_id,
|
||||
'ticket_status' => $this->whenLoaded(
|
||||
'ticketStatus',
|
||||
fn (): ?array => $this->ticketStatus === null
|
||||
? null
|
||||
: TicketStatusResource::make($this->ticketStatus)->resolve(),
|
||||
),
|
||||
'ticket_status_id' => $this->ticket_status_id,
|
||||
'ticket_type' => $this->whenLoaded(
|
||||
'ticketType',
|
||||
fn (): ?array => $this->ticketType === null
|
||||
? null
|
||||
: TicketTypeResource::make($this->ticketType)->resolve(),
|
||||
),
|
||||
'ticket_type_id' => $this->ticket_type_id,
|
||||
'title' => $this->title,
|
||||
'worklog_entries' => $this->whenLoaded(
|
||||
'worklogEntries',
|
||||
fn (): array => TicketWorklogEntryResource::collection($this->worklogEntries)->resolve(),
|
||||
),
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user