Files
pichunt/server/api/admin/hunt/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

48 lines
1.2 KiB
TypeScript

import { useValidatedBody, z } from 'h3-zod';
import prisma from '~~/lib/prisma';
export default defineEventHandler(async (event) => {
const user = await requireUserSession(event);
if (user.user.role !== 'CREATOR' && user.user.role !== 'ADMIN') {
throw createError({
statusCode: 403,
statusMessage: 'Not allowed!'
});
}
const body = 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().max(1000).trim().default(''),
description_en: z.string().max(1000).trim().default(''),
virtual: z.boolean().default(false),
start: z.iso.datetime().nullish(),
end: z.iso.datetime().nullish(),
allowJoin: z.boolean().default(false),
revealQuests: z.boolean().default(false),
revealAnswers: z.boolean().default(false),
public: z.boolean().default(true)
})
);
return await prisma.hunt.create({
data: {
...body,
creatorId: user.user.id,
members: {
create: {
memberId: user.user.id
}
}
},
select: {
id: true,
name_de: true,
name_en: true
}
});
});