Files
ERP_Distribution/Distribution/Infra/Authorization/Scope/ScopeAccessService.cs
T

31 lines
1.2 KiB
C#

namespace Distribution.Infra.Authorization;
public class ScopeAccessService(IScopeRepository repo) : IScopeAccessService
{
public Task<bool> HasStoreScopeAsync(Guid userId, Guid storeId) =>
repo.HasStoreScopeAsync(userId, storeId);
public Task<bool> HasRouteScopeAsync(Guid userId, Guid routeId) =>
repo.HasRouteScopeAsync(userId, routeId);
public Task<bool> HasRegionScopeAsync(Guid userId, Guid regionId) =>
repo.HasRegionScopeAsync(userId, regionId);
public async Task<List<Guid>> GetAccessibleStoreIdsAsync(Guid userId)
{
var directStoreIds = await repo.GetDirectStoreIdsAsync(userId);
var routeIds = await repo.GetRouteIdsAsync(userId);
var regionIds = await repo.GetRegionIdsAsync(userId);
var storeIdsViaRoute = await repo.GetStoreIdsByRouteIdsAsync(routeIds);
var routeIdsViaRegion = await repo.GetRouteIdsByRegionIdsAsync(regionIds);
var storeIdsViaRegion = await repo.GetStoreIdsByRouteIdsAsync(routeIdsViaRegion);
return directStoreIds
.Concat(storeIdsViaRoute)
.Concat(storeIdsViaRegion)
.Distinct()
.ToList();
}
}