2022-11-10 02:11:36 -05:00
|
|
|
import { parseQueryParam } from "@lib/server/parse-query-param"
|
2022-11-11 22:17:44 -05:00
|
|
|
import { getPostsByUser } from "@lib/server/prisma"
|
2022-11-10 02:11:36 -05:00
|
|
|
import { NextApiRequest, NextApiResponse } from "next"
|
|
|
|
|
|
|
|
export default async function handle(
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse
|
|
|
|
) {
|
|
|
|
switch (req.method) {
|
|
|
|
case "GET":
|
|
|
|
const userId = parseQueryParam(req.query.userId)
|
|
|
|
if (!userId) {
|
|
|
|
return res.status(400).json({ error: "Missing userId" })
|
|
|
|
}
|
|
|
|
|
|
|
|
const posts = await getPostsByUser(userId)
|
|
|
|
return res.json(posts)
|
|
|
|
default:
|
|
|
|
return res.status(405).end()
|
|
|
|
}
|
|
|
|
}
|