🗃️ (webhook) Improve webhook creation query
This commit is contained in:
@@ -44,6 +44,7 @@ export const deleteResultsProcedure = authenticatedProcedure
|
|||||||
typebot,
|
typebot,
|
||||||
resultsFilter: {
|
resultsFilter: {
|
||||||
id: (idsArray?.length ?? 0) > 0 ? { in: idsArray } : undefined,
|
id: (idsArray?.length ?? 0) > 0 ? { in: idsArray } : undefined,
|
||||||
|
typebotId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { CollaborationType } from 'db'
|
|
||||||
import prisma from '@/lib/prisma'
|
import prisma from '@/lib/prisma'
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { getAuthenticatedUser } from '@/features/auth/api'
|
import { getAuthenticatedUser } from '@/features/auth/api'
|
||||||
@@ -8,6 +7,7 @@ import {
|
|||||||
methodNotAllowed,
|
methodNotAllowed,
|
||||||
notAuthenticated,
|
notAuthenticated,
|
||||||
} from 'utils/api'
|
} from 'utils/api'
|
||||||
|
import { getTypebot } from '@/features/typebot/api/utils/getTypebot'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req)
|
||||||
@@ -36,23 +36,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
if (req.method === 'PUT') {
|
if (req.method === 'PUT') {
|
||||||
const data = req.body
|
const data = req.body
|
||||||
if (!('typebotId' in data)) return badRequest(res)
|
if (!('typebotId' in data)) return badRequest(res)
|
||||||
const typebot = await prisma.typebot.findFirst({
|
const typebot = await getTypebot({
|
||||||
where: {
|
accessLevel: 'write',
|
||||||
OR: [
|
typebotId: data.typebotId,
|
||||||
{
|
user,
|
||||||
id: data.typebotId,
|
|
||||||
workspace: { members: { some: { userId: user.id } } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
collaborators: {
|
|
||||||
some: {
|
|
||||||
userId: user.id,
|
|
||||||
type: CollaborationType.WRITE,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
if (!typebot) return forbidden(res)
|
if (!typebot) return forbidden(res)
|
||||||
const webhook = await prisma.webhook.upsert({
|
const webhook = await prisma.webhook.upsert({
|
||||||
|
|||||||
Reference in New Issue
Block a user