From 9e36e26b7554bd0f85d69af03f56e0ca9b18cf5e Mon Sep 17 00:00:00 2001 From: Anand Suthar Date: Wed, 14 Aug 2024 23:00:30 +0530 Subject: [PATCH 1/2] refactor: Rename layout component --- app/(pages)/hospital/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/(pages)/hospital/layout.tsx b/app/(pages)/hospital/layout.tsx index f970b3de..ee77e78a 100644 --- a/app/(pages)/hospital/layout.tsx +++ b/app/(pages)/hospital/layout.tsx @@ -9,7 +9,7 @@ export const metadata: Metadata = { description: "The page is for hospital related applications.", }; -export default async function PatientLayout({ +export default async function HospitalLayout({ children, }: Readonly<{ children: React.ReactNode; From a79df97a36aa61540623133fe0b547c3f1dc9168 Mon Sep 17 00:00:00 2001 From: Anand Suthar Date: Wed, 14 Aug 2024 23:00:58 +0530 Subject: [PATCH 2/2] feat(auth/hospital): Add api to fetch hospital data --- app/api/hospital/route.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/api/hospital/route.ts diff --git a/app/api/hospital/route.ts b/app/api/hospital/route.ts new file mode 100644 index 00000000..81df0fb5 --- /dev/null +++ b/app/api/hospital/route.ts @@ -0,0 +1,31 @@ +import dbConfig from "@utils/db"; +import { decrypt } from "@sessions/sessionUtils"; +import Hospital from "@models/hospital"; + +export async function GET(request: Request) { + const session = request.headers.get("Authorization"); + if (!session) { + return Response.json({ error: "Unauthorized" }, { status: 401 }); + } + + try { + const token = session.split("Bearer ")[1]; + const decryptedUser = await decrypt(token); + const email = decryptedUser.user.email; + + await dbConfig(); + + // const projection = {}; { projection } + + const hospitalData = await Hospital.findOne({ email }); + + if (!hospitalData) { + return Response.json({ error: "Hospital not found" }, { status: 404 }); + } + + return Response.json(hospitalData); + } catch (error) { + console.error("Error fetching Hospital data:", error); + return Response.json({ error: "Internal Server Error" }, { status: 500 }); + } +}