- 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
53 lines
1.2 KiB
TypeScript
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 {};
|
|
});
|