♻️ (builder) Change to features-centric folder structure
This commit is contained in:
committed by
Baptiste Arnaud
parent
3686465a85
commit
643571fe7d
19
apps/builder/src/pages/api/publicIdAvailable.ts
Normal file
19
apps/builder/src/pages/api/publicIdAvailable.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
|
||||
import { getAuthenticatedUser } from '@/features/auth'
|
||||
|
||||
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)
|
Reference in New Issue
Block a user