Repository navigation
Split questions.ts up #1678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Split questions.ts up #1678
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
520e421
Split questions.ts
stefan-burke 78552c9
Refactor
stefan-burke 0df8601
Save WIP
stefan-burke 63b4cb9
Address CodeRabbit review: hoist type import, fix stale comment, docu…
stefan-burke 2acbadf
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] fd63e8d
Merge branch 'main' into split-questions
stefan-burke c347ac4
Biome
stefan-burke 2735cb4
Merge branch 'main' into split-questions
stefan-burke d920a77
Split attendee-answers into save.ts + reads.ts (under 400 lines)
stefan-burke 925d491
Remove stale duplicate getQuestionsWithListingIds import in attendees…
stefan-burke 455dc0e
Merge branch 'main' into split-questions
stefan-burke e34e53f
Trigger PR mergeability recompute (no code change)
stefan-burke 107fc04
Make saveAttendeeAnswers truly atomic via withTransaction (#1686)
stefan-burke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,75 @@ | ||
| /** | ||
| * Shared types and validation for the custom questions tables. | ||
| * | ||
| * Questions and answers are encrypted at rest using symmetric encryption | ||
| * (DB_ENCRYPTION_KEY). Listing-question and attendee-answer mappings use | ||
| * integer foreign keys. | ||
| */ | ||
|
|
||
| import * as v from "valibot"; | ||
| import { guardFor } from "#shared/validation/guard.ts"; | ||
|
|
||
| /** A custom multiple-choice question */ | ||
| export const QUESTION_DISPLAY_TYPES = ["radio", "select", "free_text"] as const; | ||
| export const QuestionDisplayTypeSchema = v.picklist(QUESTION_DISPLAY_TYPES); | ||
| export type QuestionDisplayType = v.InferOutput< | ||
| typeof QuestionDisplayTypeSchema | ||
| >; | ||
|
|
||
| export const isQuestionDisplayType = guardFor(QuestionDisplayTypeSchema); | ||
|
|
||
| export const questionDisplayTypeError = | ||
| "Display as must be radio buttons, a select box, or free text"; | ||
|
|
||
| export const requireQuestionDisplayType = ( | ||
| value: string, | ||
| ): QuestionDisplayType => { | ||
| if (isQuestionDisplayType(value)) return value; | ||
| throw new Error(questionDisplayTypeError); | ||
| }; | ||
|
|
||
| export interface Question { | ||
| assign_all: boolean; | ||
| display_type: QuestionDisplayType; | ||
| id: number; | ||
| text: string; // encrypted | ||
| } | ||
|
|
||
| /** An answer option for a question */ | ||
| export interface Answer { | ||
| id: number; | ||
| question_id: number; | ||
| sort_order: number; | ||
| text: string; // encrypted | ||
| /** Deactivated answers are hidden on the public booking form; the admin edit | ||
| * form still shows one an attendee already selected so it isn't silently | ||
| * dropped on the next save. */ | ||
| active: boolean; | ||
| } | ||
|
|
||
| /** Link between listing and question. Membership only — display order comes | ||
| * from the question's own `sort_order`, not from this row. The `sort_order` | ||
| * column is retained but unused (legacy per-listing ordering). */ | ||
| export interface ListingQuestion { | ||
| listing_id: number; | ||
| id: number; | ||
| question_id: number; | ||
| sort_order: number; | ||
| } | ||
|
|
||
| /** Question with its answer options (decrypted) */ | ||
| export type QuestionWithAnswers = Omit<Question, "assign_all"> & { | ||
| answers: Answer[]; | ||
| assign_all?: boolean; | ||
| }; | ||
|
|
||
| /** A free-text answer submitted for a question (plaintext, pre-string-interning). */ | ||
| export type TextAnswer = { questionId: number; text: string }; | ||
|
|
||
| /** A free-text answer resolved to its interned string id. */ | ||
| export type TextAnswerId = { questionId: number; stringId: number }; | ||
|
|
||
| /** Outcome of parsing a form's submitted answers. */ | ||
| export type ParsedQuestionAnswers = | ||
| | { ok: true; answerIds: number[]; textAnswers: TextAnswer[] } | ||
| | { ok: false; error: string }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.