Create Preferences Survey Route/API #37

Closed
opened 2026-06-24 05:58:04 +00:00 by gostmeaper · 0 comments
gostmeaper commented 2026-06-24 05:58:04 +00:00 (Migrated from codeberg.org)

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

  1. 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 yet
    • PUT /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.
  2. 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.

  3. Return the saved preferences object from PUT

  4. Add the routes to apps/backend/src/index.ts

Help & Resources

### 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 1. 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 yet - `PUT /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. 2. 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. 3. Return the saved preferences object from PUT 4. Add the routes to apps/backend/src/index.ts ### Help & Resources - [DB Schema](https://lucid.app/lucidchart/cb169728-397a-4993-801b-1c5beeed62b9/edit?viewport_loc=-844%2C-172%2C1968%2C1183%2C0_0&invitationId=inv_0eebfa91-3957-4426-a47b-316f727e67d6) - [README](../../ScottyLabs/housing/src/branch/main/README.md) - [Contributing Guidelines](../../ScottyLabs/housing/src/branch/main/docs/CONTRIBUTING.md)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ScottyLabs/housing#37
No description provided.