20 lines
783 B
TypeScript
20 lines
783 B
TypeScript
![]() |
import { withSentry } from '@sentry/nextjs'
|
||
|
import prisma from 'libs/prisma'
|
||
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||
|
import { getAuthenticatedUser } from 'services/api/utils'
|
||
|
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
|
||
|
|
||
|
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)
|