2
0

feat(editor): Team workspaces

This commit is contained in:
Baptiste Arnaud
2022-05-13 15:22:44 -07:00
parent 6c2986590b
commit f0fdf08b00
132 changed files with 3354 additions and 1228 deletions

View File

@ -9,7 +9,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebots = await prisma.typebot.findMany({
where: { ownerId: user.id },
where: { workspace: { members: { some: { userId: user.id } } } },
select: { name: true, publishedTypebotId: true, id: true },
})
return res.send({ typebots })

View File

@ -6,13 +6,16 @@ import { parseSampleResult } from 'services/api/webhooks'
import { methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
if (req.method === 'GET') {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebotId = req.query.typebotId.toString()
const stepId = req.query.blockId.toString()
const typebot = (await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = (await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
})) as unknown as Typebot | undefined
if (!typebot) return res.status(400).send({ message: 'Typebot not found' })
const step = typebot.blocks

View File

@ -6,13 +6,16 @@ import { parseSampleResult } from 'services/api/webhooks'
import { methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
if (req.method === 'GET') {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebotId = req.query.typebotId.toString()
const blockId = req.query.blockId.toString()
const typebot = (await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = (await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
})) as unknown as Typebot | undefined
if (!typebot) return res.status(400).send({ message: 'Typebot not found' })
const linkedTypebots = await getLinkedTypebots(typebot, user)

View File

@ -6,9 +6,9 @@ import { authenticateUser } from 'services/api/utils'
import { byId, methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
if (req.method === 'POST') {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const body = req.body as Record<string, string>
if (!('url' in body))
return res.status(403).send({ message: 'url is missing in body' })
@ -16,8 +16,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const typebotId = req.query.typebotId.toString()
const blockId = req.query.blockId.toString()
const stepId = req.query.stepId.toString()
const typebot = (await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = (await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
})) as unknown as Typebot | undefined
if (!typebot) return res.status(400).send({ message: 'Typebot not found' })
try {

View File

@ -6,14 +6,17 @@ import { authenticateUser } from 'services/api/utils'
import { byId, methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
if (req.method === 'POST') {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebotId = req.query.typebotId.toString()
const blockId = req.query.blockId.toString()
const stepId = req.query.stepId.toString()
const typebot = (await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = (await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
})) as unknown as Typebot | undefined
if (!typebot) return res.status(400).send({ message: 'Typebot not found' })
try {

View File

@ -6,17 +6,20 @@ import { authenticateUser } from 'services/api/utils'
import { byId, methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
if (req.method === 'POST') {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const body = req.body as Record<string, string>
if (!('url' in body))
return res.status(403).send({ message: 'url is missing in body' })
const { url } = body
const typebotId = req.query.typebotId.toString()
const stepId = req.query.blockId.toString()
const typebot = (await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = (await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
})) as unknown as Typebot | undefined
if (!typebot) return res.status(400).send({ message: 'Typebot not found' })
try {

View File

@ -6,13 +6,16 @@ import { authenticateUser } from 'services/api/utils'
import { byId, methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
if (req.method === 'POST') {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebotId = req.query.typebotId.toString()
const stepId = req.query.blockId.toString()
const typebot = (await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = (await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
})) as unknown as Typebot | undefined
if (!typebot) return res.status(400).send({ message: 'Typebot not found' })
try {

View File

@ -9,13 +9,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebotId = req.query.typebotId.toString()
const typebot = await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
})
if (!typebot) return res.status(400).send({ message: 'Typebot not found' })
const limit = Number(req.query.limit)
const results = (await prisma.result.findMany({
where: { typebotId: typebot.id },
where: {
typebot: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
},
orderBy: { createdAt: 'desc' },
take: limit,
include: { answers: true },

View File

@ -10,8 +10,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebotId = req.query.typebotId.toString()
const typebot = await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
select: { blocks: true, webhooks: true },
})
const emptyWebhookSteps = (typebot?.blocks as Block[]).reduce<

View File

@ -10,8 +10,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await authenticateUser(req)
if (!user) return res.status(401).json({ message: 'Not authenticated' })
const typebotId = req.query.typebotId.toString()
const typebot = await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = await prisma.typebot.findFirst({
where: {
id: typebotId,
workspace: { members: { some: { userId: user.id } } },
},
select: { blocks: true, webhooks: true },
})
const emptyWebhookSteps = (typebot?.blocks as Block[]).reduce<