feat(engine): ✨ Link typebot step
This commit is contained in:
@ -3,7 +3,6 @@ import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { methodNotAllowed } from 'utils'
|
||||
|
||||
const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
||||
console.log(req.method)
|
||||
if (req.method === 'POST') {
|
||||
return res.status(200).send(req.body)
|
||||
}
|
||||
|
@ -11,7 +11,35 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (!user) return notAuthenticated(res)
|
||||
try {
|
||||
if (req.method === 'GET') {
|
||||
const folderId = req.query.folderId ? req.query.folderId.toString() : null
|
||||
const folderId = req.query.allFolders
|
||||
? undefined
|
||||
: req.query.folderId
|
||||
? req.query.folderId.toString()
|
||||
: null
|
||||
const typebotIds = req.query.typebotIds as string[] | undefined
|
||||
if (typebotIds) {
|
||||
const typebots = await prisma.typebot.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
ownerId: user.id,
|
||||
id: { in: typebotIds },
|
||||
},
|
||||
{
|
||||
id: { in: typebotIds },
|
||||
collaborators: {
|
||||
some: {
|
||||
userId: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: { name: true, id: true, blocks: true },
|
||||
})
|
||||
return res.send({ typebots })
|
||||
}
|
||||
const typebots = await prisma.typebot.findMany({
|
||||
where: {
|
||||
ownerId: user.id,
|
||||
|
21
apps/builder/pages/api/typebots/[typebotId]/blocks.ts
Normal file
21
apps/builder/pages/api/typebots/[typebotId]/blocks.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import prisma from 'libs/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getAuthenticatedUser } from 'services/api/utils'
|
||||
import { methodNotAllowed, notAuthenticated, notFound } from 'utils'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const user = await getAuthenticatedUser(req)
|
||||
if (!user) return notAuthenticated(res)
|
||||
if (req.method === 'GET') {
|
||||
const typebotId = req.query.typebotId as string
|
||||
const typebot = await prisma.typebot.findUnique({
|
||||
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
|
||||
})
|
||||
if (!typebot) return notFound(res)
|
||||
return res.send({ blocks: typebot.blocks })
|
||||
}
|
||||
methodNotAllowed(res)
|
||||
}
|
||||
|
||||
export default withSentry(handler)
|
Reference in New Issue
Block a user