diff --git a/src/app/api/management/request/route.ts b/src/app/api/management/request/route.ts index 784d42a..aa66c2f 100644 --- a/src/app/api/management/request/route.ts +++ b/src/app/api/management/request/route.ts @@ -2,20 +2,18 @@ import { NextResponse } from "next/server"; import { prisma } from "@utils/prisma"; export async function POST(req: Request) { - try { - const { requestType, requestingUserId, scientistId, comment } = await req.json(); - const request = await prisma.request.create({ - data: { - requestType, - requestingUser: { connect: { id: requestingUserId } }, - outcome: "IN_PROGRESS", - // Optionally you can connect to Scientist via an inline relation if you have a foreign key - // If the model has comment or details fields, add it! - }, - }); - return NextResponse.json({ request }, { status: 201 }); - } catch (error) { - console.error("Request create error:", error); - return NextResponse.json({ error: "Failed to create request" }, { status: 500 }); - } -} \ No newline at end of file + try { + const { requestType, requestingUserId, scientistId, comment } = await req.json(); + const request = await prisma.request.create({ + data: { + requestType, + requestingUser: { connect: { id: requestingUserId } }, + outcome: "IN_PROGRESS", + }, + }); + return NextResponse.json({ request }, { status: 201 }); + } catch (error) { + console.error("Request create error:", error); + return NextResponse.json({ error: "Failed to create request" }, { status: 500 }); + } +} diff --git a/src/app/api/update-user/route.ts b/src/app/api/update-user/route.ts index 81b9cfb..46b4059 100644 --- a/src/app/api/update-user/route.ts +++ b/src/app/api/update-user/route.ts @@ -13,8 +13,7 @@ export async function POST(req: Request) { if ("user" in authResult === false) return authResult; const { user } = authResult; - // todo handle requestedRole - const { userId, email, name, password } = await req.json(); + const { userId, email, name, password, requestedRole } = await req.json(); // Trying to update a different user than themselves // Only available to admins @@ -58,6 +57,12 @@ export async function POST(req: Request) { passwordHash = await bcryptjs.hash(password, 10); } + if (requestedRole && ["GUEST", "SCIENTIST", "ADMIN"].includes(requestedRole) && requestedRole !== user.role) { + await prisma.request.create({ + data: { requestType: requestedRole, requestingUserId: userId || user.id }, + }); + } + const updatedUser = await prisma.user.update({ where: { id: userId || user.id }, data: { diff --git a/src/app/earthquakes/page.tsx b/src/app/earthquakes/page.tsx index f4501e3..55a8c73 100644 --- a/src/app/earthquakes/page.tsx +++ b/src/app/earthquakes/page.tsx @@ -11,28 +11,6 @@ import EarthquakeSearchModal from "@components/EarthquakeSearchModal"; import EarthquakeLogModal from "@components/EarthquakeLogModal"; // If you use a separate log modal import { useStoreState } from "@hooks/store"; -// Optional: "No Access Modal" - as in your original -function NoAccessModal({ open, onClose }) { - if (!open) return null; - return ( -
- Sorry, you do not have access rights to Log an Earthquake. Please Log in here, or contact an Admin if you believe this - is a mistake -
- -+ Sorry, you do not have access rights to Log an Earthquake. Please Log in here, or contact an Admin if you believe this + is a mistake +
+ +