Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 00e46ee

Browse files
author
Manuel Proß
committed
refactor(web): use flatMap to filter undefined values directly
1 parent 7f51c7e commit 00e46ee

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

web/src/app/api/[homepage]/route.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ export async function GET() {
1919
return Response.json("Homepage contains no data");
2020
}
2121

22-
const newsSections = homePageData.data.attributes.body.map((contentEntry, i) => {
22+
const newsSections = homePageData.data.attributes.body.flatMap((contentEntry, i) => {
2323
if ("newsCount" in contentEntry) return { index: i, newsCount: contentEntry.newsCount };
24+
else return [];
2425
});
2526

2627
for (const newsSectionEntry of newsSections) {
27-
if (newsSectionEntry) {
28-
const fetchedNews = await getNews(newsSectionEntry.newsCount);
29-
30-
homePageData.data.attributes.body[newsSectionEntry.index] = fetchedNews;
31-
}
28+
const fetchedNews = await getNews(newsSectionEntry.newsCount);
29+
homePageData.data.attributes.body[newsSectionEntry.index] = fetchedNews;
3230
}
3331

3432
return Response.json(homePageData.data.attributes);

0 commit comments

Comments
 (0)