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

Commit 4cb75e0

Browse files
author
Manuel Proß
committed
fix(web): readd correct data structuring for news section
1 parent a1272a9 commit 4cb75e0

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { HomePageContent } from "@/types/strapi";
1+
import { getNews } from "@/helpers/homepage";
2+
import { SingleType } from "@/types/strapi";
23

34
export async function GET() {
45
const res = await fetch(`${process.env.CMS_API}/home?populate=deep`, {
@@ -7,10 +8,25 @@ export async function GET() {
78
"API-Key": process.env.CMS_API_TOKEN!,
89
},
910
});
11+
1012
if (!res.ok) {
1113
throw new Error("Fetching single type component home failed");
1214
}
1315

14-
const content = (await res.json()) as HomePageContent;
15-
return Response.json(content.data.attributes);
16+
const homePageData = (await res.json()) as SingleType;
17+
18+
const news = homePageData.data.attributes.body
19+
.map((el, i) => {
20+
if ("newsCount" in el) return { index: i, newsCount: el.newsCount };
21+
})
22+
.filter(Boolean);
23+
24+
for (const newsEntry of news) {
25+
if (!newsEntry) break;
26+
const fetchedNews = await getNews(newsEntry?.newsCount);
27+
28+
homePageData.data.attributes.body[newsEntry.index] = fetchedNews;
29+
}
30+
31+
return Response.json(homePageData.data.attributes);
1632
}

0 commit comments

Comments
 (0)