generated from sripwoud/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(client): send boolean feedback while supporting text feedback
schema
- Loading branch information
Showing
14 changed files
with
103 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { trpc } from 'client/l/trpc' | ||
import type { QuestionStatsDto } from 'server/questions/dto' | ||
|
||
export const useQuestionStats = ({ questionId }: QuestionStatsDto) => { | ||
// TODO: handle free text questions | ||
return trpc.questions.stats.useQuery({ questionId, type: 'boolean' }, { | ||
initialData: { no: 0, yes: 0 }, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import type { Database, Tables } from 'server/supabase/supabase.types' | ||
import { z } from 'zod' | ||
|
||
export type QuestionType = Database['public']['Enums']['question_type'] | ||
const questionTypes = ['boolean', 'number', 'option', 'text'] as const | ||
export const questionTypeSchema = z.enum(questionTypes, { | ||
message: 'Invalid question type, must be one of: boolean, number, option, text', | ||
}) | ||
|
||
export type OptionsType = Tables<'questions'>['options'] | ||
|
||
export const CreateQuestionDto = z.object({ | ||
author: z.string().email(), | ||
groupId: z.string().min(1, { message: 'Group ID cannot be empty' }), | ||
title: z.string().min(10, { message: 'Title must be at least 10 characters long' }).includes('?', { | ||
message: 'Title must include a question mark', | ||
}), | ||
type: questionTypeSchema, | ||
}) | ||
|
||
export type CreateQuestionDto = z.infer<typeof CreateQuestionDto> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './create-question.dto' | ||
export * from './find-all-questions.dto' | ||
export * from './find-question.dto' | ||
export * from './question-stats.dto' | ||
export * from './toggle-question.dto' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { z } from 'zod' | ||
import { questionTypeSchema } from './create-question.dto' | ||
|
||
export const QuestionStatsDto = z.object({ questionId: z.number().positive(), type: questionTypeSchema.optional() }) | ||
export type QuestionStatsDto = z.infer<typeof QuestionStatsDto> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters