Skip to content

Commit

Permalink
🗃️ (webhook) Improve webhook creation query
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 13, 2023
1 parent 1d4d39c commit e39cd94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const deleteResultsProcedure = authenticatedProcedure
typebot,
resultsFilter: {
id: (idsArray?.length ?? 0) > 0 ? { in: idsArray } : undefined,
typebotId,
},
})

Expand Down
23 changes: 5 additions & 18 deletions apps/builder/src/pages/api/webhooks/[webhookId].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CollaborationType } from 'db'
import prisma from '@/lib/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from '@/features/auth/api'
Expand All @@ -8,6 +7,7 @@ import {
methodNotAllowed,
notAuthenticated,
} from 'utils/api'
import { getTypebot } from '@/features/typebot/api/utils/getTypebot'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down Expand Up @@ -36,23 +36,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'PUT') {
const data = req.body
if (!('typebotId' in data)) return badRequest(res)
const typebot = await prisma.typebot.findFirst({
where: {
OR: [
{
id: data.typebotId,
workspace: { members: { some: { userId: user.id } } },
},
{
collaborators: {
some: {
userId: user.id,
type: CollaborationType.WRITE,
},
},
},
],
},
const typebot = await getTypebot({
accessLevel: 'write',
typebotId: data.typebotId,
user,
})
if (!typebot) return forbidden(res)
const webhook = await prisma.webhook.upsert({
Expand Down

2 comments on commit e39cd94

@vercel
Copy link

@vercel vercel bot commented on e39cd94 Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on e39cd94 Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.