feat(projects): Plan 5 Task 6 — destroy + sync + toggle-active + bulk endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Дмитрий
2026-05-11 19:06:07 +03:00
parent 32135e62d2
commit 458fa0b84d
6 changed files with 239 additions and 0 deletions
@@ -42,6 +42,37 @@ class ProjectService
return $project->fresh();
}
public function archive(Project $project): void
{
if ($project->archived_at !== null) {
throw new HttpResponseException(response()->json([
'message' => 'Project уже архивирован.',
], 409));
}
$project->update([
'is_active' => false,
'archived_at' => now(),
]);
}
public function triggerSync(Project $project): void
{
SyncSupplierProjectJob::dispatch($project->id);
}
public function bulkAction(int $tenantId, string $action, array $ids): int
{
$query = Project::where('tenant_id', $tenantId)->whereIn('id', $ids);
$update = match ($action) {
'pause' => ['is_active' => false],
'resume' => ['is_active' => true],
'archive' => ['is_active' => false, 'archived_at' => now()],
};
return $query->update($update);
}
public function create(Tenant $tenant, array $data): Project
{
$limit = (int) ($tenant->limits['max_projects'] ?? 10);