Skip to content

Commit

Permalink
Merge branch 'feature/hospital'
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed Aug 14, 2024
2 parents 0cf7ce0 + a79df97 commit 28a97cb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/(pages)/hospital/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions app/api/hospital/route.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}

0 comments on commit 28a97cb

Please sign in to comment.