refactor: Less nesting, easier to read

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-04-06 23:59:59 +02:00
parent 23ce666847
commit 0982cb002c
No known key found for this signature in database
GPG Key ID: E59C7734F0E10EB5
1 changed files with 68 additions and 62 deletions

View File

@ -47,8 +47,7 @@ async function withDownloadLink(
}
}
export const nrkRadio = {
search: async (query: string): Promise<SearchResultList | null> => {
async function search(query: string): Promise<SearchResultList | null> {
if (query === "") {
console.error("Empty search query.");
return null;
@ -62,10 +61,11 @@ export const nrkRadio = {
console.error(`Something went wrong with ${query} - got status ${status}`);
return null;
},
getSerieData: async (
}
async function getSerieData(
seriesId: string,
): Promise<{ episodes: OriginalEpisode[] } & (RadioSeries["series"] | Podcast["series"]) | null> => {
): Promise<{ episodes: OriginalEpisode[] } & (RadioSeries["series"] | Podcast["series"]) | null> {
let [
{ status: episodeStatus, body: episodeResponse },
{ status: seriesStatus, body: serieResponse },
@ -108,8 +108,9 @@ export const nrkRadio = {
`Error getting episodes for ${seriesId}: EpisodeStatus: ${episodeStatus}. SerieStatus: ${seriesStatus}`,
);
return null;
},
getEpisode: async (seriesId: string, episodeId: string): Promise<PodcastEpisode | null> => {
}
async function getEpisode(seriesId: string, episodeId: string): Promise<PodcastEpisode | null> {
const url = `${nrkAPI}/radio/catalog/podcast/${seriesId}/episodes/${episodeId}`;
const { status, body: episode } = await get<PodcastEpisode>(url);
if (status === STATUS_CODE.OK && episode) {
@ -117,5 +118,10 @@ export const nrkRadio = {
}
console.error(`Error getting episode ${episodeId}. Status: ${status}. Series: ${seriesId}`);
return null;
},
}
export const nrkRadio = {
search,
getSerieData,
getEpisode,
};