2
0

Add Graph draft

This commit is contained in:
Baptiste Arnaud
2021-12-16 10:43:49 +01:00
parent 0f85d2cd94
commit da9459edf3
35 changed files with 1938 additions and 116 deletions

View File

@ -1,3 +1,4 @@
import { StartBlock, StepType } from 'bot-engine'
import { Typebot, User } from 'db'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
@ -23,8 +24,21 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}
if (req.method === 'POST') {
const data = JSON.parse(req.body) as Typebot
const startBlock: StartBlock = {
id: 'start-block',
title: 'Start',
graphCoordinates: { x: 0, y: 0 },
steps: [
{
id: 'start-step',
blockId: 'start-block',
label: 'Form starts here',
type: StepType.START,
},
],
}
const typebot = await prisma.typebot.create({
data: { ...data, ownerId: user.id },
data: { ...data, ownerId: user.id, startBlock },
})
return res.send(typebot)
}

View File

@ -1,4 +1,3 @@
import { Typebot } from '.prisma/client'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getSession } from 'next-auth/react'
@ -11,6 +10,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return res.status(401).json({ message: 'Not authenticated' })
const id = req.query.id.toString()
if (req.method === 'GET') {
const typebot = await prisma.typebot.findUnique({
where: { id },
})
return res.send({ typebot })
}
if (req.method === 'DELETE') {
const typebots = await prisma.typebot.delete({
where: { id },
@ -18,7 +23,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return res.send({ typebots })
}
if (req.method === 'PATCH') {
const data = JSON.parse(req.body) as Partial<Typebot>
const data = JSON.parse(req.body)
const typebots = await prisma.typebot.update({
where: { id },
data,