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,12 +1,19 @@
import { Answer as AnswerFromPrisma } from 'db'
import { z } from 'zod'
export type Answer = Omit<
AnswerFromPrisma,
'resultId' | 'createdAt' | 'storageUsed'
> & { storageUsed?: number }
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(),
})
export type Stats = {
totalViews: number
totalStarts: number
totalCompleted: number
}
export type Answer = z.infer<typeof answerSchema>

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,

View File

@ -3,21 +3,29 @@ import { z } from 'zod'
export const variableSchema = z.object({
id: z.string(),
name: z.string(),
value: z.string().optional().nullable(),
value: z.string().nullish(),
})
/**
* Variable when retrieved from the database
*/
export type VariableWithValue = Omit<Variable, 'value'> & {
value: string
}
export const variableWithValueSchema = z.object({
id: z.string(),
name: z.string(),
value: z.string(),
})
/**
* Variable when computed or retrieved from a block
*/
export type VariableWithUnknowValue = Omit<VariableWithValue, 'value'> & {
value: unknown
}
const VariableWithUnknowValueSchema = z.object({
id: z.string(),
name: z.string(),
value: z.unknown(),
})
export type Variable = z.infer<typeof variableSchema>
export type VariableWithValue = z.infer<typeof variableWithValueSchema>
export type VariableWithUnknowValue = z.infer<
typeof VariableWithUnknowValueSchema
>