2
0

♻️ (results) Introduce tRPC and use it for the results

This commit is contained in:
Baptiste Arnaud
2022-11-18 18:21:40 +01:00
parent c9cc82cc08
commit d58f9bd3a1
58 changed files with 750 additions and 421 deletions

View File

@ -1,14 +1,39 @@
import { Result as ResultFromPrisma } from 'db'
import { Answer } from './answer'
import { z } from 'zod'
import { answerSchema } from './answer'
import { InputBlockType } from './blocks'
import { VariableWithValue } from './typebot/variable'
import { variableWithValueSchema } from './typebot/variable'
export type Result = Omit<ResultFromPrisma, 'createdAt' | 'variables'> & {
createdAt: string
variables: VariableWithValue[]
}
export const resultSchema = 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 type ResultWithAnswers = Result & { answers: Answer[] }
export const resultWithAnswersSchema = resultSchema.and(
z.object({
answers: z.array(answerSchema),
})
)
export const logSchema = 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>
export type Log = z.infer<typeof logSchema>
export type ResultValues = Pick<
ResultWithAnswers,