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; 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 }); + } +}