Files
pichunt/server/api/admin/hunt/[huntId]/index.get.ts
T
Pascal cfda014760 refactor(auth): simplify authorization checks to use membership only
- Remove explicit ADMIN role checks in API handlers
- Replace combined creator/member role checks with membership-only filters
- Update seed data roles to reflect changed authorization logic
- Add migration to insert hunt creators as members for consistent checks
- Prevent removal of hunt creator as a member with new explicit check
- Adjust related user role updates and queries accordingly
- Upgrade dependencies including nuxt and zod for compatibility
2026-07-30 21:59:36 +02:00

73 lines
1.4 KiB
TypeScript

import { useValidatedParams, z, zh } from 'h3-zod';
import prisma from '~~/lib/prisma';
import { sendJson } from '~~/server/utils/json';
export default defineEventHandler(async (event) => {
const user = await requireUserSession(event);
const userId = user.user.id;
const { huntId } = await useValidatedParams(
event,
z.object({
huntId: zh.numAsString
})
);
const hunt = await prisma.hunt.findUnique({
where: {
id: huntId,
members: {
some: {
memberId: userId
}
}
},
select: {
id: true,
name_de: true,
name_en: true,
description_de: true,
description_en: true,
virtual: true,
start: true,
end: true,
allowJoin: true,
revealQuests: true,
revealAnswers: true,
updatedAt: true,
picture: {
select: {
id: true,
url: true
}
},
creator: {
select: {
name: true,
id: true,
email: true
}
},
members: {
select: {
member: {
select: {
id: true,
name: true,
email: true
}
}
}
}
}
});
if (!hunt) {
throw createError({ status: 404, statusText: 'Not found!' });
}
setHeader(event, 'Content-Type', 'application/json');
return sendJson(hunt);
});