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

Commit 1b65d2a

Browse files
author
Manuel Proß
committed
refactor(web): change logic of method to fetch news per newscount to be readable
1 parent 444ec43 commit 1b65d2a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getNews } from "@/helpers/homepage";
2-
import { NewsSection, SingleType } from "@/types/strapi";
2+
import { SingleType } from "@/types/strapi";
33

44
export async function GET() {
55
const res = await fetch(`${process.env.CMS_API}/home?populate=deep`, {
@@ -20,15 +20,15 @@ export async function GET() {
2020
}
2121

2222
const newsSections = homePageData.data.attributes.body.map((contentEntry, i) => {
23-
if ("newsCount" in contentEntry) return { index: i, news: { headline: contentEntry.headline, newsCount: contentEntry.newsCount } as NewsSection };
23+
if ("newsCount" in contentEntry) return { index: i, newsCount: contentEntry.newsCount };
2424
});
2525

2626
for (const newsSectionEntry of newsSections) {
27-
if (!newsSectionEntry) break;
28-
const fetchedNews = await getNews(newsSectionEntry?.news.newsCount);
29-
fetchedNews.headline = newsSectionEntry.news.headline;
27+
if (newsSectionEntry) {
28+
const fetchedNews = await getNews(newsSectionEntry.newsCount);
3029

31-
homePageData.data.attributes.body[newsSectionEntry.index] = fetchedNews;
30+
homePageData.data.attributes.body[newsSectionEntry.index] = fetchedNews;
31+
}
3232
}
3333

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

0 commit comments

Comments
 (0)