-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(journey-maps): extend poi-url-generation with preview flag (#1899)
- Loading branch information
1 parent
2e4d621
commit 366ead8
Showing
6 changed files
with
46 additions
and
29 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
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
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 |
---|---|---|
@@ -1,21 +1,35 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { SbbPointsOfInterestEnvironmentType } from '../../journey-maps.interfaces'; | ||
import { | ||
SbbPointsOfInterestEnvironmentType, | ||
SbbPointsOfInterestOptions, | ||
} from '../../journey-maps.interfaces'; | ||
|
||
const URL_SPLITTER = '.json'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class SbbMapUrlService { | ||
getPoiSourceUrlByEnvironment( | ||
url: string, | ||
poiEnvironment?: SbbPointsOfInterestEnvironmentType | ||
): string { | ||
if (poiEnvironment === 'int') { | ||
// Set poi source to integration if needed | ||
return url.replace('journey_pois', 'journey_pois_integration'); | ||
} else if (poiEnvironment === 'prod') { | ||
// Reset poi source to prod if needed | ||
return url.replace('_integration', ''); | ||
getPoiSourceUrlByOptions(url: string, options?: SbbPointsOfInterestOptions): string { | ||
const [urlStart, urlEnd] = url.split(URL_SPLITTER); | ||
let newUrlStart = urlStart.replace('_integration', '').replace('_preview', ''); | ||
|
||
newUrlStart = this._setEnvironment(newUrlStart, options?.environment); | ||
newUrlStart = this._setPreview(newUrlStart, options?.includePreview); | ||
|
||
return newUrlStart + URL_SPLITTER + urlEnd; | ||
} | ||
|
||
private _setPreview(url: string, includePreview?: boolean): string { | ||
if (includePreview) { | ||
return url + '_preview'; | ||
} | ||
return url; | ||
} | ||
|
||
private _setEnvironment(url: string, environment?: SbbPointsOfInterestEnvironmentType): string { | ||
if (environment === 'int') { | ||
return url + '_integration'; | ||
} | ||
return url; | ||
} | ||
} |