feat: history and calculate needs for user
CI / 🧪 Tests Laravel (push) Failing after 2m18s
CI / 🐳 Build & Push Images (push) Has been skipped

This commit is contained in:
2026-08-14 12:45:37 +02:00
parent ea5a5737ec
commit 69372a49ed
51 changed files with 2226 additions and 305 deletions
+22 -10
View File
@@ -15,14 +15,19 @@ class UserResource extends JsonResource
*/
public function toArray(Request $request): array
{
$this->resource->loadMissing(['activeNutritionPlan', 'latestWeightEntry']);
$nutritionPlan = $this->activeNutritionPlan;
return [
'id' => $this->id, // à voir si suppression par la suite
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'locale' => $this->locale,
'emailVerified' => $this->hasVerifiedEmail(),
'emailVerifiedAt' => $this->email_verified_at?->toISOString(),
'height' => $this->height,
'currentWeight' => $this->latestWeightEntry?->weight_kg,
'targetWeight' => $this->target_weight,
'avatarUrl' => $this->avatar_url ? asset(Storage::url($this->avatar_url)) : null,
'bio' => $this->bio,
'role' => $this->role,
@@ -38,20 +43,27 @@ class UserResource extends JsonResource
'hasActiveSubscription' => $this->hasActiveSubscription(),
'suspendedAt' => $this->suspended_at?->toISOString(),
'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,
'onboardingStatus' => $this->hasCompletedNutritionOnboarding() ? 'completed' : 'required',
'missingOnboardingFields' => $this->hasCompletedNutritionOnboarding() ? [] : [
'dateOfBirth',
'sex',
'heightCm',
'weightKg',
'physicalActivityLevel',
'weightGoal',
'pacePreference',
],
'nutritionPlan' => NutritionPlanResource::make($nutritionPlan),
'nutritionGoals' => $nutritionPlan ? [
'calories' => $nutritionPlan->calories,
'proteins' => $nutritionPlan->proteins,
'carbs' => $nutritionPlan->carbs,
'fats' => $nutritionPlan->fats,
] : null,
];
}
}