await Prisma create never resolves using PlanetScale

I'm using Next API routes as my backend, and there is the logic inside:
if (req.method === "POST") {
try {
const session = await getServerSession(req, res, authOptions)
if (!session || !session.user || !session.user.sub) {
return res.status(401).send("Usuário não autenticado.")
}

const { announcement_date, medias_url, price, text, title } = newPostSchema.parse(req.body)

const random = () => parseInt(String(Math.random() * 10 ** 10))
const slug = `${slugify(title)}-${random()}`

await prisma.post.create({
data: {
announcement_date,
price,
text,
slug,
title,
author_id: session.user.sub,
// author_id: "clg7ycfq00000ve146tnoayuc",
post_media: {
create: medias_url.map(media => ({
media,
})),
},
},
})

return res.status(201)
} catch (error) {
return res.json(error)
}
}
if (req.method === "POST") {
try {
const session = await getServerSession(req, res, authOptions)
if (!session || !session.user || !session.user.sub) {
return res.status(401).send("Usuário não autenticado.")
}

const { announcement_date, medias_url, price, text, title } = newPostSchema.parse(req.body)

const random = () => parseInt(String(Math.random() * 10 ** 10))
const slug = `${slugify(title)}-${random()}`

await prisma.post.create({
data: {
announcement_date,
price,
text,
slug,
title,
author_id: session.user.sub,
// author_id: "clg7ycfq00000ve146tnoayuc",
post_media: {
create: medias_url.map(media => ({
media,
})),
},
},
})

return res.status(201)
} catch (error) {
return res.json(error)
}
}
issue: the prisma promise never resolves
await prisma.post.create({
await prisma.post.create({
and there is no successful response in my front-end - this issue started when i started using planetscale database in development mode - all my get requests are being fetch successfully - i'm using the pscale connection proxy, on port 3309 - the issue is occurring both in chrome and insomnia here is the front-end fetch in case it comes handy
mutationFn: async (newPostData: TNewPostBody) => {
const headers = new Headers()
headers.append("Content-Type", "application/json")

const res = await fetch(`http://localhost:3000/api/posts`, {
headers,
method: "POST",
body: JSON.stringify(newPostData),
})
return res
}
mutationFn: async (newPostData: TNewPostBody) => {
const headers = new Headers()
headers.append("Content-Type", "application/json")

const res = await fetch(`http://localhost:3000/api/posts`, {
headers,
method: "POST",
body: JSON.stringify(newPostData),
})
return res
}
2 Replies
killer_z3
killer_z32y ago
Does it show any error when you prisma generate?
vitor markis 🎈
was a silly mistake, i needed to end the response method, using .end() or .json()
Want results from more Discord servers?
Add your server