2022-02-15 08:43:11 +01:00
|
|
|
import { withSentry } from '@sentry/nextjs'
|
2021-12-29 10:22:26 +01:00
|
|
|
import prisma from 'libs/prisma'
|
2022-02-17 16:08:01 +01:00
|
|
|
import { VariableWithValue } from 'models'
|
2021-12-29 10:22:26 +01:00
|
|
|
import { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
import { methodNotAllowed } from 'utils'
|
|
|
|
|
|
|
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
|
|
if (req.method === 'POST') {
|
2022-02-22 10:16:35 +01:00
|
|
|
const resultData = (
|
|
|
|
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
|
|
|
) as {
|
2022-02-17 16:08:01 +01:00
|
|
|
typebotId: string
|
|
|
|
prefilledVariables: VariableWithValue[]
|
|
|
|
}
|
2021-12-29 10:22:26 +01:00
|
|
|
const result = await prisma.result.create({
|
2022-02-17 16:08:01 +01:00
|
|
|
data: { ...resultData, isCompleted: false },
|
2021-12-29 10:22:26 +01:00
|
|
|
})
|
|
|
|
return res.send(result)
|
|
|
|
}
|
|
|
|
return methodNotAllowed(res)
|
|
|
|
}
|
|
|
|
|
2022-02-15 08:43:11 +01:00
|
|
|
export default withSentry(handler)
|