Skip to content

Commit

Permalink
fix: odata filter now correctly builds taking into consideration AND/…
Browse files Browse the repository at this point in the history
…OR combinations
  • Loading branch information
daniel-almeida-konkconsulting committed Oct 18, 2023
1 parent b76661b commit 3ffcf0c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export class ClientListComponent {
if (this.filter.clientId) this.clients = this.clients.filter((c) => c.clientId.toUpperCase().includes(this.filter.clientId!.toUpperCase()));
if (this.filter.displayName) this.clients = this.clients.filter((c) => c.displayName.toUpperCase().includes(this.filter.displayName!.toUpperCase()));
if (this.filter.tiers && this.filter.tiers.length > 0) this.clients = this.clients.filter((c) => this.filter.tiers!.includes(c.defaultTier));
if (this.filter.numberOfIdentities.value !== undefined && this.filter.numberOfIdentities.value !== null) {
if (this.filter.numberOfIdentities.value !== undefined) {
switch (this.filter.numberOfIdentities.operator) {
case "=":
this.clients = this.clients.filter((c) => c.numberOfIdentities == this.filter.numberOfIdentities.value!);
this.clients = this.clients.filter((c) => c.numberOfIdentities === this.filter.numberOfIdentities.value!);
break;
case ">":
this.clients = this.clients.filter((c) => c.numberOfIdentities > this.filter.numberOfIdentities.value!);
Expand All @@ -120,10 +120,10 @@ export class ClientListComponent {
break;
}
}
if (this.filter.createdAt.value !== undefined && this.filter.createdAt.value !== null) {
if (this.filter.createdAt.value !== undefined) {
switch (this.filter.createdAt.operator) {
case "=":
this.clients = this.clients.filter((c) => new Date(c.createdAt).toISOString() == this.filter.createdAt.value!.toISOString());
this.clients = this.clients.filter((c) => new Date(c.createdAt).toISOString() === this.filter.createdAt.value!.toISOString());
break;
case ">":
this.clients = this.clients.filter((c) => new Date(c.createdAt).toISOString() > this.filter.createdAt.value!.toISOString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import { PagedHttpResponseEnvelope } from "src/app/utils/paged-http-response-env
})
export class IdentityListComponent {
@ViewChild(MatPaginator) public paginator!: MatPaginator;
@ViewChild("addressFilter", { static: false }) public set addressFilter(addressFilterInput: ElementRef) {
@ViewChild("addressFilter", { static: false }) public set addressFilter(addressFilterInput: ElementRef | undefined) {
this.debounceFilter(addressFilterInput, "address");
}
@ViewChild("numberOfDevicesFilter", { static: false }) public set numberOfDevicesFilter(numberOfDevicesFilterInput: ElementRef) {
@ViewChild("numberOfDevicesFilter", { static: false }) public set numberOfDevicesFilter(numberOfDevicesFilterInput: ElementRef | undefined) {
this.debounceFilter(numberOfDevicesFilterInput, "numberOfDevices");
}
@ViewChild("datawalletVersionFilter", { static: false }) public set datawalletVersionFilter(datawalletVersionFilterInput: ElementRef) {
@ViewChild("datawalletVersionFilter", { static: false }) public set datawalletVersionFilter(datawalletVersionFilterInput: ElementRef | undefined) {
this.debounceFilter(datawalletVersionFilterInput, "datawalletVersion");
}
@ViewChild("identityVersionFilter", { static: false }) public set identityVersionFilter(identityVersionFilterInput: ElementRef) {
@ViewChild("identityVersionFilter", { static: false }) public set identityVersionFilter(identityVersionFilterInput: ElementRef | undefined) {
this.debounceFilter(identityVersionFilterInput, "identityVersion");
}

Expand Down Expand Up @@ -86,7 +86,7 @@ export class IdentityListComponent {
this.getClients();
}

private debounceFilter(filterElement: ElementRef, filterName: string): void {
private debounceFilter(filterElement: ElementRef | undefined, filterName: string): void {
if (filterElement !== undefined) {
fromEvent(filterElement.nativeElement, "keyup")
.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ export class IdentityService {
if (filter.address !== undefined && filter.address !== "") odataFilter.contains("address", filter.address);

if (filter.tiers !== undefined && filter.tiers.length > 0) {
var tiersFilter = new ODataFilterBuilder();
filter.tiers.forEach((tier) => {
odataFilter.eq("tierId", tier);
tiersFilter.or((x) => x.eq("tierId", tier));
});
odataFilter.and((_) => tiersFilter);
}

if (filter.clients !== undefined && filter.clients.length > 0) {
filter.clients.forEach((client) => {
odataFilter.eq("createdWithClient", client);
var clientsFilter = new ODataFilterBuilder();
filter.clients.forEach((client, index) => {
clientsFilter.or((x) => x.eq("createdWithClient", client));
});
odataFilter.and((_) => clientsFilter);
}

if (filter.createdAt.operator !== undefined && filter.createdAt.value !== undefined) {
Expand Down Expand Up @@ -97,7 +101,7 @@ export class IdentityService {
}
}

if (filter.numberOfDevices.operator !== undefined && filter.numberOfDevices.value !== undefined && filter.numberOfDevices.value !== null) {
if (filter.numberOfDevices.operator !== undefined && filter.numberOfDevices.value?.valueOf) {
switch (filter.numberOfDevices.operator) {
case ">":
odataFilter.gt("numberOfDevices", filter.numberOfDevices.value);
Expand All @@ -120,7 +124,7 @@ export class IdentityService {
}
}

if (filter.datawalletVersion.operator !== undefined && filter.datawalletVersion.value !== undefined && filter.datawalletVersion.value !== null) {
if (filter.datawalletVersion.operator !== undefined && filter.datawalletVersion.value?.valueOf) {
switch (filter.datawalletVersion.operator) {
case ">":
odataFilter.gt("datawalletVersion", filter.datawalletVersion.value);
Expand All @@ -143,7 +147,7 @@ export class IdentityService {
}
}

if (filter.identityVersion.operator !== undefined && filter.identityVersion.value !== undefined && filter.identityVersion.value !== null) {
if (filter.identityVersion.operator !== undefined && filter.identityVersion.value?.valueOf) {
switch (filter.identityVersion.operator) {
case ">":
odataFilter.gt("identityVersion", filter.identityVersion.value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface NumberFilter {
operator?: string;
value?: number;
value?: number | null;
}

0 comments on commit 3ffcf0c

Please sign in to comment.