-
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
1 parent
9df7c9f
commit 7472ddf
Showing
7 changed files
with
78 additions
and
21 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 TranslatedName = { | ||
fi?: string, | ||
en?: string, | ||
sv?: string | ||
} | ||
|
||
export enum Language { | ||
FI, EN, SV | ||
} |
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,37 @@ | ||
import { configuration } from "./configuration"; | ||
import axios from "axios"; | ||
import { TranslatedName, Language } from "./common"; | ||
|
||
export type Koodi = { | ||
koodiUri: string, | ||
nimi: TranslatedName, | ||
} | ||
|
||
async function getKoodit(koodisto: string): Promise<Koodi[]> { | ||
const headers = { | ||
accept: 'application/json', | ||
'Caller-id': 'valintojen-toteuttaminen' | ||
}; | ||
|
||
const getTranslatedNimi = (language: Language, metadata: [{nimi: string, kieli: string}]): string => { | ||
const matchingData= metadata.find((m: {nimi: string, kieli: string}) => | ||
Language[m.kieli.toUpperCase() as keyof typeof Language] === language); | ||
return matchingData ? matchingData.nimi : ''; | ||
} | ||
|
||
const response = await axios.get(configuration.kooditUrl + koodisto, {headers}); | ||
return response.data.map((k: { koodiUri: string, metadata: [{nimi: string, kieli: string}]}) => { | ||
const translated = { | ||
fi: getTranslatedNimi(Language.FI, k.metadata), | ||
sv: getTranslatedNimi(Language.SV, k.metadata), | ||
en: getTranslatedNimi(Language.EN, k.metadata), | ||
}; | ||
return {koodiUri: k.koodiUri, nimi: translated}; | ||
}); | ||
} | ||
|
||
export async function getHakutavat(): Promise<Koodi[]> { | ||
return await getKoodit('hakutapa'); | ||
} | ||
|
||
|
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