Files
pichunt/server/api/admin/hunt/[huntId]/index.post.ts
T
Pascal 77becc453e feat(hunt): add public flag to hunts and implement hunt creation page
- Add 'public' boolean column to Hunt model with default true
- Update hunt admin UI to toggle 'public' flag
- Implement new hunt creation page with form supporting all hunt properties
- Add sidebar navigation item for hunt creation for authorized users
- Adjust home API to filter hunts by public flag only
2026-07-30 23:33:34 +02:00

53 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(),
public: z.boolean(),
start: z.iso.datetime().nullable(),
end: z.iso.datetime().nullable(),
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 {};
});