@@ -0,0 +1,46 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
import { authenticatedProcedure } from '@/helpers/server/trpc'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { z } from 'zod'
|
||||
import { collaboratorSchema } from '@typebot.io/schemas/features/collaborators'
|
||||
import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebotForbidden'
|
||||
|
||||
export const getCollaborators = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/typebots/{typebotId}/collaborators',
|
||||
protect: true,
|
||||
summary: 'Get collaborators',
|
||||
tags: ['Collaborators'],
|
||||
},
|
||||
})
|
||||
.input(
|
||||
z.object({
|
||||
typebotId: z.string(),
|
||||
})
|
||||
)
|
||||
.output(
|
||||
z.object({
|
||||
collaborators: z.array(collaboratorSchema),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { typebotId }, ctx: { user } }) => {
|
||||
const existingTypebot = await prisma.typebot.findFirst({
|
||||
where: {
|
||||
id: typebotId,
|
||||
},
|
||||
include: {
|
||||
collaborators: true,
|
||||
},
|
||||
})
|
||||
if (
|
||||
!existingTypebot?.id ||
|
||||
(await isReadTypebotForbidden(existingTypebot, user))
|
||||
)
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' })
|
||||
|
||||
return {
|
||||
collaborators: existingTypebot.collaborators,
|
||||
}
|
||||
})
|
||||
6
apps/builder/src/features/collaboration/api/router.ts
Normal file
6
apps/builder/src/features/collaboration/api/router.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { router } from '@/helpers/server/trpc'
|
||||
import { getCollaborators } from './getCollaborators'
|
||||
|
||||
export const collaboratorsRouter = router({
|
||||
getCollaborators: getCollaborators,
|
||||
})
|
||||
Reference in New Issue
Block a user