2023-12-22 09:13:53 +01:00
|
|
|
import { z } from '../zod'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { Answer as AnswerPrisma, Prisma } from '@typebot.io/prisma'
|
2021-12-30 10:24:16 +01:00
|
|
|
|
2023-03-09 08:46:36 +01:00
|
|
|
export const answerSchema = z.object({
|
|
|
|
|
createdAt: z.date(),
|
|
|
|
|
resultId: z.string(),
|
|
|
|
|
blockId: z.string(),
|
|
|
|
|
groupId: z.string(),
|
|
|
|
|
variableId: z.string().nullable(),
|
|
|
|
|
content: z.string(),
|
|
|
|
|
storageUsed: z.number().nullable(),
|
2023-11-08 15:34:16 +01:00
|
|
|
// TO-DO: remove once itemId is removed from database schema
|
|
|
|
|
}) satisfies z.ZodType<Omit<AnswerPrisma, 'itemId'>>
|
2022-11-29 10:02:40 +01:00
|
|
|
|
2023-03-09 08:46:36 +01:00
|
|
|
export const answerInputSchema = answerSchema
|
|
|
|
|
.omit({
|
|
|
|
|
createdAt: true,
|
|
|
|
|
resultId: true,
|
|
|
|
|
variableId: true,
|
|
|
|
|
storageUsed: true,
|
|
|
|
|
})
|
2023-11-08 15:34:16 +01:00
|
|
|
.extend({
|
|
|
|
|
variableId: z.string().nullish(),
|
|
|
|
|
storageUsed: z.number().nullish(),
|
|
|
|
|
}) satisfies z.ZodType<Prisma.AnswerUncheckedUpdateInput>
|
2022-11-21 11:12:43 +01:00
|
|
|
|
2024-02-06 17:48:31 +01:00
|
|
|
export const statsSchema = z.object({
|
|
|
|
|
totalViews: z.number(),
|
|
|
|
|
totalStarts: z.number(),
|
|
|
|
|
totalCompleted: z.number(),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export type Stats = z.infer<typeof statsSchema>
|
2022-11-18 18:21:40 +01:00
|
|
|
|
|
|
|
|
export type Answer = z.infer<typeof answerSchema>
|
2022-11-21 11:12:43 +01:00
|
|
|
|
|
|
|
|
export type AnswerInput = z.infer<typeof answerInputSchema>
|