Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis update expands the user data schema and onboarding logic to extract and store specific survey responses as individual fields in the database. The changes include a database migration, Prisma schema updates, and logic in the onboarding answer-saving action to parse and persist these new survey fields. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant WebApp
participant DB
User->>WebApp: Submit onboarding survey answers
WebApp->>WebApp: extractSurveyAnswers(questions, answers)
WebApp->>DB: Update User record with onboardingAnswers + extracted survey fields
DB-->>WebApp: Confirmation
WebApp-->>User: Success response
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
apps/web/utils/actions/user.tsOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Bug: Schema vs Migration Mismatch Causes Errors
Schema mismatch for surveyFeatures: Defined as non-nullable String[] in the Prisma schema, but the migration creates a nullable TEXT[] database column. This causes runtime errors, especially when data extraction logic returns undefined which conflicts with the non-nullable schema definition during database updates. The schema field should be nullable (String[]?) or the extraction logic should always return [].
apps/web/prisma/schema.prisma#L62-L63
inbox-zero/apps/web/prisma/schema.prisma
Lines 62 to 63 in aa6baad
BugBot free trial expires on June 9, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/web/utils/actions/user.ts (2)
121-190: Consider improving robustness of the extraction logic.The extraction function handles the survey data parsing well, but there are some areas for improvement:
Hardcoded answer key format: The logic assumes specific key patterns (
$survey_response,$survey_response_${questionIndex}) which could break if the survey format changes.String literal filtering: The filtering for
"undefined"strings suggests data quality issues upstream that might be better addressed at the source.Consider these improvements:
+// Define constants for survey key patterns +const SURVEY_RESPONSE_KEYS = { + first: '$survey_response', + subsequent: (index: number) => `$survey_response_${index}` +} as const; function extractSurveyAnswers(questions: any[], answers: any) { // ... existing code ... const getAnswerByKey = (key: string) => { const questionIndex = questions.findIndex((q) => q.key === key); if (questionIndex === -1) return null; - const answerKey = - questionIndex === 0 - ? "$survey_response" - : `$survey_response_${questionIndex}`; + const answerKey = questionIndex === 0 + ? SURVEY_RESPONSE_KEYS.first + : SURVEY_RESPONSE_KEYS.subsequent(questionIndex); const answer = answers[answerKey]; - return answer && answer !== "" ? answer : null; + // Normalize undefined/empty values + return answer && answer !== "" && answer !== "undefined" ? answer : null; };
106-110: Consider stronger type validation for survey data.The current schema uses
z.any()for questions and answers, which provides no type safety. Consider defining more specific schemas if the survey structure is known.+const surveyQuestionSchema = z.object({ + key: z.string(), + // add other expected question properties +}); + +const surveyAnswersSchema = z.record(z.string(), z.any()); const saveOnboardingAnswersBody = z.object({ surveyId: z.string().optional(), - questions: z.any(), - answers: z.any(), + questions: z.array(surveyQuestionSchema), + answers: surveyAnswersSchema, });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/web/prisma/migrations/20250606102158_onboarding_answers/migration.sql(1 hunks)apps/web/prisma/schema.prisma(1 hunks)apps/web/utils/actions/user.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
apps/web/prisma/migrations/20250606102158_onboarding_answers/migration.sql (1)
1-6: LGTM! Migration correctly adds survey fields.The migration properly adds the new survey-related columns to the User table with appropriate data types.
apps/web/prisma/schema.prisma (1)
62-67: LGTM! Schema changes are well-structured and documented.The new survey fields are properly typed and the comments clearly explain their purpose for easier querying of onboarding responses.
apps/web/utils/actions/user.ts (1)
195-205: LGTM! Database update correctly uses extracted survey answers.The update operation properly saves both the original onboarding answers and the extracted individual survey fields for easier querying.
Summary by CodeRabbit