46 lines
1.7 KiB
PHP
46 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class UserResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'name' => $this->name,
|
|
'email' => $this->email,
|
|
'locale' => $this->locale,
|
|
'emailVerified' => $this->hasVerifiedEmail(),
|
|
'emailVerifiedAt' => $this->email_verified_at?->toISOString(),
|
|
'height' => $this->height,
|
|
'avatarUrl' => $this->avatar_url ? asset(Storage::url($this->avatar_url)) : null,
|
|
'bio' => $this->bio,
|
|
'accountVerified' => $this->account_verified_at !== null,
|
|
'physicalActivityLevel' => $this->physical_activity_level,
|
|
'physicalActivityLevelLabel' => $this->physical_activity_level?->getLabel(),
|
|
'weightGoal' => $this->weight_goal,
|
|
'weightGoalLabel' => $this->weight_goal?->getLabel(),
|
|
'pacePreference' => $this->pace_preference,
|
|
'pacePreferenceLabel' => $this->pace_preference?->getLabel(),
|
|
'sex' => $this->sex,
|
|
'sexLabel' => $this->sex?->getLabel(),
|
|
'dateOfBirth' => $this->date_of_birth?->toDateString(),
|
|
'nutritionGoals' => [
|
|
'calories' => (int) $this->daily_calorie_goal,
|
|
'proteins' => (float) $this->daily_protein_goal,
|
|
'carbs' => (float) $this->daily_carbs_goal,
|
|
'fats' => (float) $this->daily_fats_goal,
|
|
],
|
|
];
|
|
}
|
|
}
|