2
0

feat(engine): Link typebot step

This commit is contained in:
Baptiste Arnaud
2022-03-09 15:12:00 +01:00
parent 1bcc8aee10
commit 7e61ab19eb
61 changed files with 1272 additions and 245 deletions

View File

@ -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)
}

View File

@ -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,

View 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)