Create Preferences Survey Route/API #37
Labels
No labels
backend
beginner friendly
bug
chore
documentation
enhancement
frontend
priority/high
priority/low
priority/medium
size/L
size/M
size/S
size/XL
size/XS
stage/backlog
stage/done
stage/in progress
stage/ready
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ScottyLabs/housing#37
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overall Objective
When users log in for the first time they fill out a housing preferences survey. This issue makes the two routes to save and retrieve those answers. The frontend uses null from the GET to know whether to show the survey gate.
Once this issue is written, you should add it to the backend api docs in the docs folder in the root of the project for others and specifically frontend users to see.
Suggested Approach
Create apps/backend/src/preferences/routes.ts with two routes, both using .use(requireAuth) <- this is if Auth is setup which it should be before this. The two routes are named and described below:
GET /api/me/preferences: return the row, or null (not a 404) if it doesn't exist yetPUT /api/me/preferences: upsert using Drizzle's .insert().onConflictDoUpdate(). Word of caution you should always use ctx.user.id as user_id, never the request body.Validate the body with Elysia's TypeBox: integers must be 1-5, arrays must only contain the values listed in the Database Docs and Enum Values also listed in the docs.
Return the saved preferences object from PUT
Add the routes to apps/backend/src/index.ts
Help & Resources