simplify assignment persistence
This commit is contained in:
parent
9f53245987
commit
0466552c4f
1 changed files with 3 additions and 10 deletions
|
|
@ -122,16 +122,6 @@ class EloquentScheduleRepository implements ScheduleRepository
|
||||||
public function updateAssignment(
|
public function updateAssignment(
|
||||||
ScheduleAssignment $assignment,
|
ScheduleAssignment $assignment,
|
||||||
): ScheduleAssignment {
|
): ScheduleAssignment {
|
||||||
$query = ScheduleAssignmentModel::query()
|
|
||||||
->whereKey($assignment->getId());
|
|
||||||
if ($assignment->getCompletedAt() === null) {
|
|
||||||
$query->update(['completed_at' => null]);
|
|
||||||
} else {
|
|
||||||
$query->whereNull('completed_at')->update([
|
|
||||||
'completed_at' => $assignment->getCompletedAt(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$model = ScheduleAssignmentModel::find($assignment->getId());
|
$model = ScheduleAssignmentModel::find($assignment->getId());
|
||||||
if ($model === null) {
|
if ($model === null) {
|
||||||
throw new DomainException(
|
throw new DomainException(
|
||||||
|
|
@ -139,6 +129,9 @@ class EloquentScheduleRepository implements ScheduleRepository
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$model->completed_at = $assignment->getCompletedAt();
|
||||||
|
$model->save();
|
||||||
|
|
||||||
return $this->assignmentToDomain($model);
|
return $this->assignmentToDomain($model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue