2023-09-20 15:26:52 +02:00
|
|
|
import prisma from '@typebot.io/lib/prisma'
|
2023-08-24 07:48:30 +02:00
|
|
|
import { Answer, Result } from '@typebot.io/schemas'
|
2023-07-18 14:31:20 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
id: string
|
|
|
|
}
|
2024-05-15 14:24:55 +02:00
|
|
|
export const findResult = async ({ id }: Props) => {
|
|
|
|
const { answers, answersV2, ...result } =
|
|
|
|
(await prisma.result.findFirst({
|
|
|
|
where: { id, isArchived: { not: true } },
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
variables: true,
|
|
|
|
hasStarted: true,
|
|
|
|
answers: {
|
|
|
|
select: {
|
|
|
|
content: true,
|
|
|
|
blockId: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
answersV2: {
|
|
|
|
select: {
|
|
|
|
content: true,
|
|
|
|
blockId: true,
|
|
|
|
},
|
2023-08-24 07:48:30 +02:00
|
|
|
},
|
|
|
|
},
|
2024-05-15 14:24:55 +02:00
|
|
|
})) ?? {}
|
|
|
|
if (!result) return null
|
|
|
|
return {
|
|
|
|
...result,
|
|
|
|
answers: (answersV2 ?? []).concat(answers ?? []),
|
|
|
|
} as Pick<Result, 'id' | 'variables' | 'hasStarted'> & {
|
|
|
|
answers: Pick<Answer, 'content' | 'blockId'>[]
|
|
|
|
}
|
|
|
|
}
|