2022-11-18 18:21:40 +01:00
|
|
|
import { z } from 'zod'
|
2022-11-21 11:12:43 +01:00
|
|
|
import { answerInputSchema, answerSchema } from './answer'
|
2022-11-15 11:02:26 +01:00
|
|
|
import { InputBlockType } from './blocks'
|
2022-11-18 18:21:40 +01:00
|
|
|
import { variableWithValueSchema } from './typebot/variable'
|
2022-11-29 10:02:40 +01:00
|
|
|
import { Result as ResultPrisma, Log as LogPrisma } from 'db'
|
|
|
|
import { schemaForType } from './utils'
|
2021-12-22 14:59:07 +01:00
|
|
|
|
2022-11-29 10:02:40 +01:00
|
|
|
export const resultSchema = schemaForType<ResultPrisma>()(
|
|
|
|
z.object({
|
|
|
|
id: z.string(),
|
|
|
|
createdAt: z.date(),
|
|
|
|
typebotId: z.string(),
|
|
|
|
variables: z.array(variableWithValueSchema),
|
|
|
|
isCompleted: z.boolean(),
|
|
|
|
hasStarted: z.boolean().nullable(),
|
|
|
|
isArchived: z.boolean().nullable(),
|
|
|
|
})
|
|
|
|
)
|
2022-11-18 18:21:40 +01:00
|
|
|
|
|
|
|
export const resultWithAnswersSchema = resultSchema.and(
|
|
|
|
z.object({
|
|
|
|
answers: z.array(answerSchema),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2022-11-21 11:12:43 +01:00
|
|
|
export const resultWithAnswersInputSchema = resultSchema.and(
|
|
|
|
z.object({
|
|
|
|
answers: z.array(answerInputSchema),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2022-11-29 10:02:40 +01:00
|
|
|
export const logSchema = schemaForType<LogPrisma>()(
|
|
|
|
z.object({
|
|
|
|
id: z.string(),
|
|
|
|
createdAt: z.date(),
|
|
|
|
resultId: z.string(),
|
|
|
|
status: z.string(),
|
|
|
|
description: z.string(),
|
|
|
|
details: z.string().nullable(),
|
|
|
|
})
|
|
|
|
)
|
2022-11-18 18:21:40 +01:00
|
|
|
|
|
|
|
export type Result = z.infer<typeof resultSchema>
|
|
|
|
export type ResultWithAnswers = z.infer<typeof resultWithAnswersSchema>
|
2022-11-21 11:12:43 +01:00
|
|
|
export type ResultWithAnswersInput = z.infer<
|
|
|
|
typeof resultWithAnswersInputSchema
|
|
|
|
>
|
2022-11-18 18:21:40 +01:00
|
|
|
export type Log = z.infer<typeof logSchema>
|
2022-02-22 10:16:35 +01:00
|
|
|
|
2023-03-07 14:41:57 +01:00
|
|
|
export type ResultValuesInput = Pick<
|
2022-11-21 11:12:43 +01:00
|
|
|
ResultWithAnswersInput,
|
2022-03-28 17:07:47 +02:00
|
|
|
'answers' | 'createdAt' | 'variables'
|
2022-02-22 10:16:35 +01:00
|
|
|
>
|
2022-03-21 17:05:51 +01:00
|
|
|
|
2023-03-07 14:41:57 +01:00
|
|
|
export type ResultValues = Pick<
|
|
|
|
ResultWithAnswers,
|
|
|
|
'answers' | 'createdAt' | 'variables'
|
|
|
|
>
|
|
|
|
|
2022-03-21 17:05:51 +01:00
|
|
|
export type ResultHeaderCell = {
|
2022-07-01 17:08:35 +02:00
|
|
|
id: string
|
2022-03-21 17:05:51 +01:00
|
|
|
label: string
|
2022-11-06 09:57:08 +01:00
|
|
|
blocks?: {
|
|
|
|
id: string
|
|
|
|
groupId: string
|
|
|
|
}[]
|
2022-06-11 07:27:38 +02:00
|
|
|
blockType?: InputBlockType
|
2022-11-06 09:57:08 +01:00
|
|
|
variableIds?: string[]
|
2022-03-21 17:05:51 +01:00
|
|
|
}
|