From 27a2a421a3d6ac1b5207507ea8ba3e6e568cb5a2 Mon Sep 17 00:00:00 2001 From: Anand Suthar Date: Sun, 16 Jun 2024 00:00:17 +0530 Subject: [PATCH] Added api route handler for update-profile --- .../patient/update-profile/profile/route.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/api/patient/update-profile/profile/route.ts diff --git a/app/api/patient/update-profile/profile/route.ts b/app/api/patient/update-profile/profile/route.ts new file mode 100644 index 00000000..4be70318 --- /dev/null +++ b/app/api/patient/update-profile/profile/route.ts @@ -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 = "anandsuthar956@gmail.com"; //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 }); + } +}