-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added api route handler for update-profile
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,34 @@ | ||
import dbConfig from "@lib/db"; | ||
import { decrypt } from "@sessions/sessionUtils"; | ||
|
||
export async function PUT(request: Request) { | ||
// const session = request.headers.get("Authorization"); | ||
// if (!session) { | ||
// return Response.json({ error: "Unauthorized" }, { status: 401 }); | ||
// } | ||
|
||
const profile_pic = await request.json(); | ||
|
||
try { | ||
// const token = session.split("Bearer ")[1]; | ||
// const decryptedUser = await decrypt(token); | ||
const patient_email = "[email protected]"; //decryptedUser.user.email; | ||
|
||
const db = await dbConfig(); | ||
const collection = db.collection("patient"); | ||
|
||
const result = await collection.updateOne( | ||
{ email: patient_email }, | ||
{ $set: { profile: profile_pic } } | ||
); | ||
|
||
if (!result) { | ||
return Response.json({ error: "Error updating profile picture" }); | ||
} | ||
|
||
return Response.json({ msg: "ok" }); | ||
} catch (error) { | ||
console.error("Error updating patient profile picture :", error); | ||
return Response.json({ error: "Internal Server Error" }, { status: 500 }); | ||
} | ||
} |