fix client query
This commit is contained in:
parent
ad9248c65c
commit
71f00b41bd
@ -111,7 +111,7 @@ app.UseCors(options =>
|
||||
var origins = new List<string> {"https://hoppscotch.io"};
|
||||
if (builder.Environment.IsDevelopment())
|
||||
{
|
||||
origins.Add("http://localhost:8100");
|
||||
origins.Add("http://localhost:4200");
|
||||
}
|
||||
|
||||
options.WithOrigins(origins.ToArray());
|
||||
|
@ -9,6 +9,6 @@
|
||||
"ConnectionString": "Host=workstation;Port=5432;Database=digital-operations;Username=planb;Password=-mbd2018-"
|
||||
},
|
||||
"JwtBearer": {
|
||||
"Authority": "https://login-planb.openharbor.io/realms/plan-b"
|
||||
"Authority": "https://login-planb.openharbor.io/realms/digital-ops"
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
using DigitalOps.Authority.Services;
|
||||
using DigitalOps.Dal;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PoweredSoft.DynamicLinq;
|
||||
using OpenHarbor.CQRS.DynamicQuery.Abstractions;
|
||||
|
||||
namespace DigitalOps.CQRS.Queries.Client;
|
||||
|
||||
public class ClientParams
|
||||
{
|
||||
public long OrganizationId { get; set; }
|
||||
}
|
||||
|
||||
public class ClientItem
|
||||
{
|
||||
public long Id { get; set; }
|
||||
@ -18,10 +23,28 @@ public class ClientQueryableProvider(MainDbContext dbContext, UserIdentityServic
|
||||
{
|
||||
public async Task<IQueryable<ClientItem>> GetQueryableAsync(object query, CancellationToken cancellationToken = default)
|
||||
{
|
||||
long? organizationId = null;
|
||||
|
||||
if (query is IDynamicQueryParams<ClientParams> dynamicQuery)
|
||||
{
|
||||
var queryParams = dynamicQuery.GetParams();
|
||||
organizationId = queryParams?.OrganizationId;
|
||||
}
|
||||
|
||||
if (organizationId is null)
|
||||
{
|
||||
// don't bother to call the database if organizationId is not set
|
||||
return Enumerable.Empty<ClientItem>().AsQueryable();
|
||||
}
|
||||
|
||||
var user = await userIdentityService.GetUserOrDefaultAsync(cancellationToken);
|
||||
|
||||
var queryable = dbContext.Clients
|
||||
.AsNoTracking();
|
||||
|
||||
var result = dbContext.Clients
|
||||
.AsNoTracking()
|
||||
.Where(client => client.OrganizationClients.Any(organizationClient => organizationClient.OrganizationId == organizationId))
|
||||
.Where(client =>
|
||||
client.OrganizationClients.Any(organizationClient => organizationClient.Organization.OrganizationUsers.Any(organizationUser => organizationUser.UserId == user!.Id)))
|
||||
.Select(client => new ClientItem
|
||||
@ -33,6 +56,6 @@ public class ClientQueryableProvider(MainDbContext dbContext, UserIdentityServic
|
||||
UpdatedAt = client.UpdatedAt
|
||||
});
|
||||
|
||||
return queryable;
|
||||
return result;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ public class RegisterClientQueriesModule : IModule
|
||||
{
|
||||
public IServiceCollection ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDynamicQuery<ClientItem>()
|
||||
services.AddDynamicQueryWithParams<ClientItem, ClientParams>()
|
||||
.AddQueryableProviderOverride<ClientItem, ClientQueryableProvider>();
|
||||
|
||||
return services;
|
||||
|
Loading…
Reference in New Issue
Block a user