mirror of
				https://github.com/DerTyp7/explainegy-nextjs.git
				synced 2025-10-30 21:27:12 +01:00 
			
		
		
		
	start refactor
This commit is contained in:
		| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Janis
					Janis