1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Http\Resources\API;
- use App\Models\Enums\ObjectApprovalStatus;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class TaskResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- return [
- "id" => $this->id,
- "name" => $this->name,
- "parent_id" => $this->parent_id,
- "begin" => $this->begin,
- "end" => $this->end,
- "status" => $this->status,
- 'approval_status' => match ($this->approval_status) {
- ObjectApprovalStatus::WAIT->value => 'Not Submitted',
- ObjectApprovalStatus::DOING->value => 'Pending for Approval',
- ObjectApprovalStatus::APPROVED->value => 'A-Approved & B-Approved w/comment',
- ObjectApprovalStatus::REJECTED->value => 'D-Rejected',
- ObjectApprovalStatus::CANCELED->value => 'Cancelled',
- ObjectApprovalStatus::RESUBMISSION->value => "C-Resubmission Reg'd",
- default => 'Not Submitted'
- },
- "assign_to" => new UserProfileResource($this->assignTo),
- "created_by" => new UserProfileResource($this->createdBy),
- //"children" => TaskResource::collection($this->children),
- 'display_id'=>$this->display_id,
- 'children' => $this->when($this->children->isNotEmpty(),function (){
- return $this->children->map(function ($child){
- return new TaskResource($child);
- })->all();
- }),
- 'created_at'=>(string)$this->created_at,
- 'belong_project' =>new ProjectSimpleResource($this->project),
- ];
- }
- }
|