TenantAtlas/app/Services/Inventory/DependencyQueryService.php
ahmido 361e301f67 feat/042-inventory-dependencies-graph (#49)
Ordering + limit-only Test für created_at DESC in DependencyExtractionFeatureTest.php
UI Test für masked Identifier (ID: 123456…) + Guest-Access blocked in InventoryItemDependenciesTest.php
Quickstart ergänzt um manuellen <2s Check in quickstart.md
pr-gate Checkbox-Format normalisiert (kein leading space) in pr-gate.md

Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local>
Reviewed-on: #49
2026-01-10 00:20:14 +00:00

41 lines
1.3 KiB
PHP

<?php
namespace App\Services\Inventory;
use App\Models\InventoryItem;
use App\Models\InventoryLink;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
class DependencyQueryService
{
public function getOutboundEdges(InventoryItem $item, ?string $relationshipType = null, int $limit = 50): EloquentCollection
{
$query = InventoryLink::query()
->where('tenant_id', $item->tenant_id)
->where('source_type', 'inventory_item')
->where('source_id', $item->external_id)
->orderByDesc('created_at');
if ($relationshipType !== null) {
$query->where('relationship_type', $relationshipType);
}
return $query->limit($limit)->get();
}
public function getInboundEdges(InventoryItem $item, ?string $relationshipType = null, int $limit = 50): EloquentCollection
{
$query = InventoryLink::query()
->where('tenant_id', $item->tenant_id)
->where('target_type', 'inventory_item')
->where('target_id', $item->external_id)
->orderByDesc('created_at');
if ($relationshipType !== null) {
$query->where('relationship_type', $relationshipType);
}
return $query->limit($limit)->get();
}
}