mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-22 22:16:29 +01:00
refactoring type usage in existing functions & refactor fetchAttractions into own file
This commit is contained in:
parent
0a3636fda8
commit
d377c68975
3 changed files with 57 additions and 50 deletions
30
api/src/lib/fetch-attractions.ts
Normal file
30
api/src/lib/fetch-attractions.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { AttractionImport } from '../types/attraction'
|
||||
import httpRequest from '../lib/http-request'
|
||||
|
||||
/**
|
||||
* Fetching the attractions from a specified park
|
||||
* @param park API Code for request themepark
|
||||
* @param endpoint Endpoint where to fetch data from (default: https://api.wartezeiten.app/v1/parks)
|
||||
* @param lang Language used for API request
|
||||
* @returns Interface with attraction code & name
|
||||
*/
|
||||
export default async function fetchAttractions(
|
||||
park: string,
|
||||
endpoint: string = "https://api.wartezeiten.app/v1/waitingtimes",
|
||||
lang: string = 'de'
|
||||
): Promise<AttractionImport[]>{
|
||||
try{
|
||||
const headers = {
|
||||
'language':lang,
|
||||
'park':park
|
||||
};
|
||||
|
||||
const result = await httpRequest<AttractionImport[]>(endpoint, {
|
||||
headers: headers
|
||||
});
|
||||
return result;
|
||||
}
|
||||
catch(e){
|
||||
throw new Error(`Failed to fetch attractions: ${e}`);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue