-
Notifications
You must be signed in to change notification settings - Fork 0
feat: settings modal and personalization instructions for Witely #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e81f4e1
feat: settings modal and personalization instructions for Witely
Ericzhou-ez 82e7c00
Polarity Optimize PR request
Ericzhou-ez 7c50aa5
fix: gemini fixes + personalization table creation upon account creation
Ericzhou-ez 8d5d106
Merge branch 'settings' of https://github.com/Ericzhou-ez/Witely into…
Ericzhou-ez d3e15cb
fix: updateBio function; unqiue userId in Personalization table; Unif…
Ericzhou-ez 219aa6a
perf: use reducer to simplify state management in
Ericzhou-ez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { NextResponse } from "next/server"; | ||
| import z from "zod"; | ||
| import { auth } from "@/app/(auth)/auth"; | ||
| import { getUser, updateBioByUserId } from "@/lib/db/queries"; | ||
|
|
||
| const bioSchema = z.object({ | ||
| bio: z.string().max(500), | ||
| }); | ||
|
|
||
| export async function POST(req: Request) { | ||
| try { | ||
| const session = await auth(); | ||
|
|
||
| if (!session?.user?.email) { | ||
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
| } | ||
|
|
||
| const [user] = await getUser(session.user.email); | ||
|
|
||
| if (!user) { | ||
| return NextResponse.json({ error: "User not found" }, { status: 404 }); | ||
| } | ||
|
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| const { bio } = bioSchema.parse(await req.json()); | ||
|
|
||
| await updateBioByUserId({ userId: user.id, bio }); | ||
|
|
||
| return NextResponse.json({ success: true }); | ||
| } catch (error) { | ||
| if (error instanceof z.ZodError) { | ||
| return NextResponse.json( | ||
| { error: "Invalid input", issues: error.errors }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
| console.error("Error posting user bio", error); | ||
| return NextResponse.json( | ||
| { error: "Failed to post user bio" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other API routes in the application, it's better to use the custom
WitelyErrorclass for handling errors. This centralizes error responses and ensures a uniform API error structure. This suggestion also applies to other new API routes in this PR.