2
0

🚸 (publish) Improve invalid public ID feedback

Also remove the 4 char min length rule for self-hosted versions

Closes #267
This commit is contained in:
Baptiste Arnaud
2023-01-20 11:20:11 +01:00
parent fe2952d407
commit 0febaf9760
9 changed files with 68 additions and 29 deletions

View File

@ -1,6 +1,6 @@
import prisma from '@/lib/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
import { methodNotAllowed, notAuthenticated } from 'utils/api'
import { getAuthenticatedUser } from '@/features/auth/api'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
@ -8,8 +8,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
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 } })
const exists = await prisma.typebot.count({
where: { publicId: publicId ?? '' },
})
return res.send({ isAvailable: Boolean(!exists) })
}
return methodNotAllowed(res)

View File

@ -51,7 +51,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
})
const typebots = await prisma.typebot.updateMany({
where: canWriteTypebots(typebotId, user),
data: { isArchived: true },
data: { isArchived: true, publicId: null },
})
return res.send({ typebots })
}