Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: user preferences backend #22

Merged
merged 6 commits into from
Jul 4, 2021
Merged

Conversation

joshmhanson
Copy link
Contributor

Description

This adds POST /api/users with optional queries timeZone, questionTypes, questionDifficulty, codingLanguage. It uses a new type UserPreferences which is equivalent to the User type minus id, email, name, and imageUrl. I'm not sure if there's a cleaner way to do this with Express and TypeScript.

Testing

As of yet this is untested.

Checklist

  • I provided a description of the contents of this pull request.
  • I've linked this pull request to an issue.
  • I've assigned myself as the Assignee and labelled the PR correctly.

Copy link
Contributor

@wilsonplau wilsonplau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is very clean and great. Just one comment on the response.

controllers/userController.ts Outdated Show resolved Hide resolved
controllers/userController.ts Outdated Show resolved Hide resolved
models/UserRepository.ts Outdated Show resolved Hide resolved
Switched to using POST body rather than URL queries
@joshmhanson
Copy link
Contributor Author

Made the following updates:

  • I switched to using a POST body rather than URL queries, as the latter would get awkward when a lot is being updated or when the values are arrays. Also greatly simplified the code.
  • I changed data: { ...preferences } to just data: preferences, hopefully this works. Didn't give me a type error.
  • updateUserById now returns Promise<User | null> so that the user controller can receive the updated user back from the function

@joshmhanson
Copy link
Contributor Author

updateUserById now returns Promise<User> (no null) and throws an error when user is not found.

Copy link
Contributor

@wilsonplau wilsonplau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@joshmhanson joshmhanson merged commit 14fe539 into develop Jul 4, 2021
@joshmhanson joshmhanson linked an issue Jul 4, 2021 that may be closed by this pull request
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.

[feat]: View and Update User Settings
2 participants