2
0
Files
bot/packages/models/features/result.ts

66 lines
1.6 KiB
TypeScript
Raw Normal View History

import { z } from 'zod'
2022-11-21 11:12:43 +01:00
import { answerInputSchema, answerSchema } from './answer'
import { InputBlockType } from './blocks'
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'
2022-11-29 10:02:40 +01:00
export const resultSchema = schemaForType<ResultPrisma>()(
z.object({
id: z.string(),
createdAt: z.date(),
updatedAt: z.date(),
typebotId: z.string(),
variables: z.array(variableWithValueSchema),
isCompleted: z.boolean(),
hasStarted: z.boolean().nullable(),
isArchived: z.boolean().nullable(),
})
)
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(),
})
)
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
>
export type Log = z.infer<typeof logSchema>
export type ResultValues = Pick<
2022-11-21 11:12:43 +01:00
ResultWithAnswersInput,
'answers' | 'createdAt' | 'variables'
>
export type ResultHeaderCell = {
id: string
label: string
blocks?: {
id: string
groupId: string
}[]
2022-06-11 07:27:38 +02:00
blockType?: InputBlockType
variableIds?: string[]
}