Refactored organisation entities and endpoints

This commit is contained in:
2026-10-04 10:11:28 +02:00
parent 8fed46961a
commit 5fb67df9ac
17 changed files with 2664 additions and 20 deletions
@@ -6,7 +6,7 @@ namespace PostFundManagement.Infrastructure.Database;
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options,
ITenantContextService tenantService) : DbContext(options)
{
private bool BypassFilter => tenantService.IsAdmin || tenantService.ByPassTenantQueryFilter;
private bool BypassFilter => tenantService.ByPassTenantQueryFilter;
private long CurrentTenantId => tenantService.TenantId;
public DbSet<TenantUser> TenantUsers => Set<TenantUser>();
@@ -84,14 +84,14 @@ public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext>
}
}
modelBuilder.Entity<Organisation>().HasQueryFilter(o => BypassFilter == false &&
modelBuilder.Entity<Organisation>().HasQueryFilter(o => BypassFilter ||
Set<TenantOrganisation>().Any(to => to.TenantId == CurrentTenantId && to.OrganisationId == o.Id));
modelBuilder.Entity<TenantOrganisation>()
.HasQueryFilter(to => BypassFilter == false && to.TenantId == CurrentTenantId);
.HasQueryFilter(to => BypassFilter || to.TenantId == CurrentTenantId);
modelBuilder.Entity<TenantUser>()
.HasQueryFilter(to => BypassFilter == false && to.TenantId == CurrentTenantId);
.HasQueryFilter(to => BypassFilter || to.TenantId == CurrentTenantId);
}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)