diff --git a/app/articles/[categoryName]/[articleName]/page.tsx b/app/articles/[categoryName]/[articleName]/page.tsx index 501b56d..7f15275 100644 --- a/app/articles/[categoryName]/[articleName]/page.tsx +++ b/app/articles/[categoryName]/[articleName]/page.tsx @@ -7,7 +7,11 @@ import { ArticleWithIncludes, FetchManager } from "../../../../manager/fetchMana import { formatTextToUrlName } from "../../../../utils"; //* MAIN -export default async function ArticlePage({ params }: { params: { articleName: string; categoryName: string } }) { +export default async function ArticlePage({ + params, +}: { + params: { articleName: string; categoryName: string; test: string }; +}) { const articleName: string = formatTextToUrlName(params.articleName); const article: ArticleWithIncludes = await FetchManager.Article.getByName(articleName); @@ -16,6 +20,7 @@ export default async function ArticlePage({ params }: { params: { articleName: s const dateOptions: Intl.DateTimeFormatOptions = { month: "long", day: "numeric", year: "numeric" }; const markdown: string = article?.markdown ?? ""; + console.log(params.test); return (
@@ -61,3 +66,8 @@ export async function generateStaticParams() { })) ); } + +export function getServerSideProps() { + console.log("-----------------------------------"); + return { test: "weird test" }; +} diff --git a/pages/api/articles/[articleId].ts b/pages/api/articles/[articleId].ts index 6c37332..c8108cc 100644 --- a/pages/api/articles/[articleId].ts +++ b/pages/api/articles/[articleId].ts @@ -12,22 +12,28 @@ type ArticleWithIncludes = Prisma.ArticleGetPayload<{ include: { contentTableEnt export default async function handler(req: NextApiRequest, res: NextApiResponse) { const articleId: string = formatTextToUrlName(req.query.articleId.toString()) + console.log(`API articleId: ${articleId}`) if (req.method == "GET") { //* GET + console.log("get") await prisma.article .findUnique({ where: { id: articleId }, include: { category: true, image: true } }) .then((result: ArticleWithIncludes) => { if (result !== null) { + console.log("result", result) res.json(result); } else { + console.log("no article found") const error: ResponseError = { code: "404", message: "No article with this name found!", }; res.status(404).json(error); } + }, (err) => { + console.log("reason", err) }) .catch((err) => { - + console.log("catch", err) const error: ResponseError = { code: "500", message: err, diff --git a/pages/api/articles/index.ts b/pages/api/articles/index.ts index 6bd756a..d3f5455 100644 --- a/pages/api/articles/index.ts +++ b/pages/api/articles/index.ts @@ -10,12 +10,16 @@ import { UpdateArticle } from "../../../types/api"; import type { NextApiRequest, NextApiResponse } from 'next' export default async function handler(req: NextApiRequest, res: NextApiResponse) { + console.log("articles index.ts") if (req.method == "GET") { //* GET + console.log("get") const categoryName: string = req.query.categoryName?.toString() ?? ""; const limit: number = req.query.limit ? Number(req.query.limit) : undefined; const orderBy: string = req.query.orderBy?.toString() ?? ""; const category = await prisma.category.findUnique({ where: { name: categoryName } }); + console.log(categoryName, limit, orderBy, category) + let orderByObj: Prisma.Enumerable; if (orderBy === "recent") { @@ -28,12 +32,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) await prisma.article .findMany({ - where: { category: categoryName.length > 0 ? category : undefined }, + where: { category: category ?? undefined }, include: { category: true }, take: limit, orderBy: orderByObj }) .then((result: Article[]) => { //! ContentTableEntries not sorted + console.log("result", result) if (result !== null) { res.end(JSON.stringify(result)); } else { @@ -43,8 +48,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }; res.status(404).json(error); } + }, (err) => { + console.log("reason", err) }) .catch((err) => { + console.log("catch", err) const error: ResponseError = { code: "500", message: err, @@ -82,7 +90,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) res.json({ success: true, data: data }); }, (errorReason) => { - console.log(errorReason) + console.log("reason", errorReason) if (errorReason.code === "P2002") { res.json({ target: errorReason.meta.target[0], error: "Already exists" }); } diff --git a/pages/api/articles/name/[articleName].ts b/pages/api/articles/name/[articleName].ts index 1b1b129..0931de1 100644 --- a/pages/api/articles/name/[articleName].ts +++ b/pages/api/articles/name/[articleName].ts @@ -6,28 +6,30 @@ import type { NextApiRequest, NextApiResponse } from 'next' type ArticleWithIncludes = Prisma.ArticleGetPayload<{ include: { category: true, image: true } }> - - export default async function handler(req: NextApiRequest, res: NextApiResponse) { - - const articleName: string = formatTextToUrlName(req.query.articleName.toString()) + console.log(`API: articleName: ${articleName}`) await prisma.article .findUnique({ where: { name: articleName }, include: { category: true, image: true } }) .then((result: ArticleWithIncludes) => { - + console.log("result", result) if (result !== null) { + console.log("send") res.json(result); } else { + console.log("response no article found") const error: ResponseError = { code: "404", message: "No article with this name found!", }; res.status(404).json(error); } + }, (err) => { + + console.log("reason", err) }) .catch((err) => { - + console.log("catch", err) const error: ResponseError = { code: "500", message: err,