feat: history and calculate needs for user
This commit is contained in:
@@ -2,7 +2,13 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\NutritionPlanSource;
|
||||
use App\Enums\PacePreference;
|
||||
use App\Enums\PhysicalActivityLevel;
|
||||
use App\Enums\UserRole;
|
||||
use App\Enums\UserSex;
|
||||
use App\Enums\WeightGoal;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -32,14 +38,50 @@ class UserFactory extends Factory
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'avatar_url' => null,
|
||||
'daily_calorie_goal' => 2000,
|
||||
'daily_protein_goal' => 120,
|
||||
'daily_carbs_goal' => 250,
|
||||
'daily_fats_goal' => 70,
|
||||
'height' => 175,
|
||||
'target_weight' => 70,
|
||||
'date_of_birth' => '1990-01-01',
|
||||
'sex' => UserSex::MAN,
|
||||
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT,
|
||||
'pace_preference' => PacePreference::NORMAL,
|
||||
'onboarding_completed_at' => now(),
|
||||
'nutrition_estimate_accepted_at' => now(),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterCreating(function (User $user): void {
|
||||
if (! $user->hasCompletedNutritionOnboarding()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user->weightEntries()->create([
|
||||
'weight_kg' => 70,
|
||||
'measured_at' => now(),
|
||||
]);
|
||||
|
||||
$user->nutritionPlans()->create([
|
||||
'source' => NutritionPlanSource::ONBOARDING,
|
||||
'formula_version' => 'mifflin_st_jeor_v1',
|
||||
'calories' => 2200,
|
||||
'proteins' => 112,
|
||||
'carbs' => 286,
|
||||
'fats' => 61,
|
||||
'resting_metabolism' => 1650,
|
||||
'maintenance_calories' => 2200,
|
||||
'calorie_adjustment_percent' => 0,
|
||||
'calculation_details' => [
|
||||
'activityFactor' => 1.55,
|
||||
'inputWeightKg' => 70,
|
||||
],
|
||||
'effective_from' => now(),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
@@ -49,4 +91,34 @@ class UserFactory extends Factory
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function onboarded(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'height' => 175,
|
||||
'target_weight' => 70,
|
||||
'date_of_birth' => '1990-01-01',
|
||||
'sex' => UserSex::MAN,
|
||||
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT,
|
||||
'pace_preference' => PacePreference::NORMAL,
|
||||
'onboarding_completed_at' => now(),
|
||||
'nutrition_estimate_accepted_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function withoutNutritionOnboarding(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'height' => null,
|
||||
'target_weight' => null,
|
||||
'date_of_birth' => null,
|
||||
'sex' => null,
|
||||
'physical_activity_level' => null,
|
||||
'weight_goal' => null,
|
||||
'pace_preference' => null,
|
||||
'onboarding_completed_at' => null,
|
||||
'nutrition_estimate_accepted_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user