|
@@ -5,7 +5,9 @@ namespace App\Repositories;
|
|
|
use App\Models\Action;
|
|
|
use App\Models\Enums\ActionObjectType;
|
|
|
use App\Models\Enums\ObjectAction;
|
|
|
+use App\Models\History;
|
|
|
use App\Models\Project;
|
|
|
+use App\Services\History\ModelChangeDetector;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
@@ -18,10 +20,11 @@ class ActionRepository
|
|
|
ObjectAction $action,
|
|
|
int|null $projectId = null,
|
|
|
string $comment = null,
|
|
|
- array $extraFields = []
|
|
|
+ array $extraFields = [],
|
|
|
+ array $objectChanges = [],
|
|
|
): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
|
|
|
{
|
|
|
- return Action::query()->create([
|
|
|
+ $action = Action::query()->create([
|
|
|
"object_id" => $objectId,
|
|
|
"object_type" => $objectType->value,
|
|
|
"action" => $action,
|
|
@@ -30,13 +33,20 @@ class ActionRepository
|
|
|
"extra_fields" => $extraFields ?: null,
|
|
|
"created_by" => Auth::id(),
|
|
|
]);
|
|
|
+
|
|
|
+ if ($objectChanges) {
|
|
|
+ History::query()->insert(array_map(fn($change) => [...$change, 'action_id' => $action->id], $objectChanges));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $action;
|
|
|
}
|
|
|
|
|
|
public static function createByProject(
|
|
|
Project $project,
|
|
|
ObjectAction $action,
|
|
|
string $comment = null,
|
|
|
- array $extraFields = []
|
|
|
+ array $extraFields = [],
|
|
|
+ array $objectChanges = [],
|
|
|
): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
|
|
|
{
|
|
|
return self::create(
|
|
@@ -45,7 +55,8 @@ class ActionRepository
|
|
|
$action,
|
|
|
$project->id,
|
|
|
$comment,
|
|
|
- $extraFields
|
|
|
+ $extraFields,
|
|
|
+ $objectChanges,
|
|
|
);
|
|
|
}
|
|
|
|