-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Patek
committed
Feb 10, 2025
1 parent
10ac2ea
commit c001170
Showing
3 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type TowersSearchParams = { | ||
query?: string; | ||
page?: number; | ||
county?: string; | ||
province?: string; | ||
location?: string; | ||
sort?: string; | ||
showFilter?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { OpeningHoursForbiddenType } from "@/types/OpeningHours"; | ||
import { TowersSearchParams } from "@/types/TowersSearchParams"; | ||
|
||
export class TowersFilter { | ||
private filters: string[] = []; | ||
|
||
constructor(searchParams: TowersSearchParams) { | ||
const province = searchParams?.province || ""; | ||
const county = searchParams?.county || ""; | ||
const showFilter = searchParams?.showFilter || ""; | ||
|
||
if (province) this.addFilter(`province:=${province}`); | ||
if (county) this.addFilter(`county:=${county}`); | ||
|
||
switch (showFilter) { | ||
case "showOnlyGone": | ||
this.addFilter(`openingHours.forbiddenType:=${OpeningHoursForbiddenType.Gone}`); | ||
break; | ||
case "showAll": | ||
break; | ||
default: | ||
this.addFilter(`openingHours.forbiddenType:!=${OpeningHoursForbiddenType.Gone}`); | ||
break; | ||
} | ||
} | ||
|
||
public addFilter(filter: string): void { | ||
this.filters.push(filter); | ||
} | ||
|
||
public getFilterString(): string { | ||
return this.filters.join(" && "); | ||
} | ||
} |