-
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.
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
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
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,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 }); | ||
} | ||
} |