2
0

feat(webhook): ️ Show linked typebots results in webhook sample

This commit is contained in:
Baptiste Arnaud
2022-04-21 09:18:35 -07:00
parent 937621ee07
commit 12f43cdb88
13 changed files with 249 additions and 88 deletions

View File

@ -1,13 +1,13 @@
import { CollaborationType, Prisma, User } from 'db'
const parseWhereFilter = (
typebotId: string,
typebotIds: string[] | string,
user: User,
type: 'read' | 'write'
): Prisma.TypebotWhereInput => ({
OR: [
{
id: typebotId,
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
ownerId:
(type === 'read' && user.email === process.env.ADMIN_EMAIL) ||
process.env.NEXT_PUBLIC_E2E_TEST
@ -15,7 +15,7 @@ const parseWhereFilter = (
: user.id,
},
{
id: typebotId,
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
collaborators: {
some: {
userId: user.id,
@ -31,3 +31,9 @@ export const canReadTypebot = (typebotId: string, user: User) =>
export const canWriteTypebot = (typebotId: string, user: User) =>
parseWhereFilter(typebotId, user, 'write')
export const canReadTypebots = (typebotIds: string[], user: User) =>
parseWhereFilter(typebotIds, user, 'read')
export const canWriteTypebots = (typebotIds: string[], user: User) =>
parseWhereFilter(typebotIds, user, 'write')