Files
pichunt/server/api/admin/hunt/[huntId]/index.post.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

52 lines
1.2 KiB
TypeScript

import { useValidatedBody, useValidatedParams, z, zh } from 'h3-zod';
import prisma from '~~/lib/prisma';
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 { updatedAt, ...data } = await useValidatedBody(
event,
z
.object({
name_de: z.string().min(1).max(256).trim(),
name_en: z.string().min(1).max(256).trim(),
description_de: z.string().min(1).max(1000).trim(),
description_en: z.string().min(1).max(1000).trim(),
virtual: z.boolean(),
start: z.iso.datetime(),
end: z.iso.datetime(),
allowJoin: z.boolean(),
revealQuests: z.boolean(),
revealAnswers: z.boolean()
})
.partial()
.and(
z.object({
updatedAt: z.iso.datetime()
})
)
);
await prisma.hunt.update({
where: {
id: huntId,
updatedAt,
members: {
some: {
memberId: userId
}
}
},
data
});
return {};
});