feat: history and calculate needs for user
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\NutritionPlanSource;
|
||||
use App\Models\User;
|
||||
|
||||
class CompleteNutritionOnboarding
|
||||
{
|
||||
public function __construct(private RecalculateNutritionPlan $recalculateNutritionPlan) {}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function execute(User $user, array $data): User
|
||||
{
|
||||
if ($user->hasCompletedNutritionOnboarding()) {
|
||||
return $user->loadMissing(['activeNutritionPlan', 'latestWeightEntry']);
|
||||
}
|
||||
|
||||
return $this->recalculateNutritionPlan->execute(
|
||||
user: $user,
|
||||
data: $data,
|
||||
source: NutritionPlanSource::ONBOARDING,
|
||||
completeOnboarding: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user