fix(ui-services): add route type getter

This commit is contained in:
Karol Sójko
2022-10-21 10:13:49 +02:00
parent 83b484002c
commit 401a35f4db
2 changed files with 9 additions and 3 deletions

View File

@@ -14,14 +14,18 @@ import { RouteType } from './RouteType'
export class RouteParser implements RouteParserInterface {
private url: URL
private readonly path: string
public readonly type: RouteType
private readonly parsedType: RouteType
private readonly searchParams: URLSearchParams
constructor(url: string) {
this.url = new URL(url)
this.path = this.url.pathname
this.searchParams = this.url.searchParams
this.type = this.parseTypeFromQueryParameters()
this.parsedType = this.parseTypeFromQueryParameters()
}
get type(): RouteType {
return this.parsedType
}
get subscriptionInviteParams(): SubscriptionInviteParams {
@@ -66,7 +70,7 @@ export class RouteParser implements RouteParserInterface {
}
private checkForProperRouteType(type: RouteType): void {
if (this.type !== type) {
if (this.parsedType !== type) {
throw new Error('Accessing invalid params')
}
}

View File

@@ -3,6 +3,7 @@ import { OnboardingParams } from './Params/OnboardingParams'
import { PurchaseParams } from './Params/PurchaseParams'
import { SettingsParams } from './Params/SettingsParams'
import { SubscriptionInviteParams } from './Params/SubscriptionInviteParams'
import { RouteType } from './RouteType'
export interface RouteParserInterface {
get demoParams(): DemoParams
@@ -10,4 +11,5 @@ export interface RouteParserInterface {
get purchaseParams(): PurchaseParams
get onboardingParams(): OnboardingParams
get subscriptionInviteParams(): SubscriptionInviteParams
get type(): RouteType
}