2022-11-04 13:53:54 +01:00
|
|
|
import { withSentry } from '@sentry/nextjs'
|
2022-11-15 09:35:48 +01:00
|
|
|
import prisma from '@/lib/prisma'
|
2022-11-04 13:53:54 +01:00
|
|
|
import { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
|
2022-11-22 17:30:20 +01:00
|
|
|
import { getAuthenticatedUser } from '@/features/auth/api'
|
2022-11-04 13:53:54 +01:00
|
|
|
|
|
|
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
|
|
const user = await getAuthenticatedUser(req)
|
|
|
|
if (!user) return notAuthenticated(res)
|
|
|
|
if (req.method === 'GET') {
|
|
|
|
const publicId = req.query.publicId as string | undefined
|
|
|
|
if (!publicId) return badRequest(res, 'publicId is required')
|
|
|
|
const exists = await prisma.typebot.count({ where: { publicId } })
|
|
|
|
return res.send({ isAvailable: Boolean(!exists) })
|
|
|
|
}
|
|
|
|
return methodNotAllowed(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withSentry(handler)
|