Skip to content

feat(api): survey endpoints with validated submissions#30

Open
kuyacarlo wants to merge 2 commits into
feat/api-attendancefrom
feat/api-surveys
Open

feat(api): survey endpoints with validated submissions#30
kuyacarlo wants to merge 2 commits into
feat/api-attendancefrom
feat/api-surveys

Conversation

@kuyacarlo

Copy link
Copy Markdown
Contributor

Stacked on #29 (which stacks on #28).

Summary

  • Repairs the last fixture dataset with placeholder ids: SURVEY-123 → the real survey UUID, EMP-001 → E001, RESP-001-Q* → deterministic UUIDs. SurveySchema.created_by / SurveyResponseMetadataSchema.employee_id tightened to z.uuid().
  • apps/api/sql/003_surveys.sql: surveys, survey_questions (dimension as TEXT[], default_value/response as JSONB), survey_response_meta, survey_responses — seeded on Neon (1 survey, 25 questions, 1 submission, 9 answers).
  • New endpoints: GET /surveys, GET /surveys/:id/questions, GET /surveys/responses?employee_id=, POST /surveys/:id/responses. POST is validated with a new SurveySubmissionSchema exported 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)
  • Reseeded Neon: 25 questions, 1 submission, 9 answers
  • Against the Neon pooler: GET endpoints return DB rows; POST returns 201 with avg_score: 3.5 for answers [5, 2, text]; invalid payload → 400; unknown survey → 404

Made with Cursor

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>
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worksight-docs Ready Ready Preview, Comment Jul 25, 2026 6:54pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
worksight Skipped Skipped Jul 25, 2026 6:54pm
worksight-api Skipped Skipped Jul 25, 2026 6:54pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant