2
0

🧰 Aggregate utils & set up results collection in viewer

This commit is contained in:
Baptiste Arnaud
2021-12-29 10:22:26 +01:00
parent 447172d0cb
commit f088f694b9
42 changed files with 404 additions and 141 deletions

View File

@ -11,7 +11,7 @@ export const getServerSideProps: GetServerSideProps = async (
const pathname = context.resolvedUrl.split('?')[0]
try {
if (!context.req.headers.host) return { props: {} }
typebot = await getTypebotFromPublicId(context.query.publicId.toString())
typebot = await getTypebotFromPublicId(context.query.publicId?.toString())
if (!typebot) return { props: {} }
return {
props: {
@ -32,8 +32,9 @@ export const getServerSideProps: GetServerSideProps = async (
}
const getTypebotFromPublicId = async (
publicId: string
publicId?: string
): Promise<PublicTypebot | undefined> => {
if (!publicId) return
const typebot = await prisma.publicTypebot.findUnique({
where: { publicId },
})

View File

@ -0,0 +1,16 @@
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
const { typebotId } = JSON.parse(req.body)
const result = await prisma.result.create({
data: { typebotId },
})
return res.send(result)
}
return methodNotAllowed(res)
}
export default handler

View File

@ -0,0 +1,18 @@
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'PATCH') {
const data = JSON.parse(req.body)
const id = req.query.id.toString()
const result = await prisma.result.update({
where: { id },
data: { ...data, updatedAt: new Date() },
})
return res.send(result)
}
return methodNotAllowed(res)
}
export default handler