Files
exchange-2.0/app/Classes/Modules/Milestones/Services/CreatesMilestoneProgress.php
T
2023-07-17 21:29:19 +08:00

41 lines
1.1 KiB
PHP

<?php
namespace App\Classes\Modules\Milestones\Services;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Models\Milestone;
use App\Models\MilestoneProgress;
class CreatesMilestoneProgress extends AbstractUpdateRelationshipRecord
{
/** @var CheckIfMilestoneProgressExists */
private $isMilestoneProgressExists;
/**
* CreatesMilestoneProgress constructor.
* @param CheckIfMilestoneProgressExists $isMilestoneProgressExists
*/
public function __construct(CheckIfMilestoneProgressExists $isMilestoneProgressExists)
{
$this->isMilestoneProgressExists = $isMilestoneProgressExists;
}
/**
* @param Milestone $milestone
* @param string $userId
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function execute(Milestone $milestone, string $userId) {
if(!$this->isMilestoneProgressExists->execute($userId, $milestone->id))
{
$model = new MilestoneProgress();
$model->user_id = $userId;
return $this->handler($milestone->progress(), $model);
}
return null;
}
}