feat(api): survey endpoints with validated submissions#30
Open
kuyacarlo wants to merge 2 commits into
Open
Conversation
Surveys are the product's burnout signal but nothing served them and the fixtures could not enter a database (SURVEY-123 / EMP-001 / RESP-001-Q* placeholder ids). Repair the fixtures, tighten created_by and employee_id to z.uuid(), and add sql/003_surveys.sql plus seed support. Expose GET /surveys, GET /surveys/:id/questions, GET /surveys/responses and POST /surveys/:id/responses. Submissions are validated at the boundary with a new SurveySubmissionSchema in @worksight/common (the API has no direct zod dependency); avg_score is the mean of numeric answers, matching the existing fixture value. DB mode writes meta + answers in a transaction; fixture mode keeps submissions in memory so the offline demo can still submit. Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
3 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on #29 (which stacks on #28).
Summary
SURVEY-123→ the real survey UUID,EMP-001→ E001,RESP-001-Q*→ deterministic UUIDs.SurveySchema.created_by/SurveyResponseMetadataSchema.employee_idtightened toz.uuid().apps/api/sql/003_surveys.sql:surveys,survey_questions(dimensionasTEXT[],default_value/responseas JSONB),survey_response_meta,survey_responses— seeded on Neon (1 survey, 25 questions, 1 submission, 9 answers).GET /surveys,GET /surveys/:id/questions,GET /surveys/responses?employee_id=,POST /surveys/:id/responses. POST is validated with a newSurveySubmissionSchemaexported from@worksight/common;avg_score= mean of numeric answers (2 dp), consistent with the fixture. DB mode inserts meta + answers transactionally; fixture mode keeps submissions in memory so the offline demo can still submit.Test plan
pnpm --filter @worksight/api type-check/lint/test— 19 tests green (5 new)avg_score: 3.5for answers[5, 2, text]; invalid payload → 400; unknown survey → 404Made with Cursor