[PS-1928] Fix User Delete (#2463)

* Fix User Delete

* Formatting
This commit is contained in:
Justin Baur
2022-12-02 19:35:26 -05:00
committed by GitHub
parent 1652669667
commit 85e75c43b5
5 changed files with 56 additions and 76 deletions

View File

@@ -167,7 +167,15 @@ public class ProviderUserRepository :
public async Task<int> GetCountByOnlyOwnerAsync(Guid userId)
{
var query = new ProviderUserReadCountByOnlyOwnerQuery(userId);
return await GetCountFromQuery(query);
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
return await dbContext.ProviderUsers
.Where(pu => pu.Type == ProviderUserType.ProviderAdmin && pu.Status == ProviderUserStatusType.Confirmed)
.GroupBy(pu => pu.UserId)
.Select(g => new { UserId = g.Key, ConfirmedOwnerCount = g.Count() })
.Where(oc => oc.UserId == userId && oc.ConfirmedOwnerCount == 1)
.CountAsync();
}
}
}