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
This commit is contained in:
2026-07-30 23:33:34 +02:00
parent aa4632cab8
commit 77becc453e
11 changed files with 320 additions and 16 deletions
+29 -7
View File
@@ -36,11 +36,11 @@
}, },
"enums": { "enums": {
"text_type": { "text_type": {
"CHAR": "Ein Zeichen",
"INTEGER": "Ganzzahl", "INTEGER": "Ganzzahl",
"NUMBER": "Zahl", "NUMBER": "Zahl",
"TEXT": "Freitext", "TEXT": "Freitext",
"WORD": "Ein Wort", "WORD": "Ein Wort"
"CHAR": "Ein Zeichen"
}, },
"user_role": { "user_role": {
"ADMIN": "Admin", "ADMIN": "Admin",
@@ -80,6 +80,28 @@
"refresh": "Aktualisieren", "refresh": "Aktualisieren",
"update_btn": "Updaten" "update_btn": "Updaten"
}, },
"create_hunt": {
"allow_join": "Beitreten erlauben",
"create_btn": "Hunt erstellen",
"de": "Deutsch",
"description_de": "Beschreibung (Deutsch)",
"description_en": "Beschreibung (Englisch)",
"en": "Englisch",
"end": "Ende",
"has_end": "Hat ein Enddatum?",
"has_start": "Hat ein Startdatum?",
"name_de": "Name (Deutsch)",
"name_en": "Name (Englisch)",
"not_allowed": "Du benötigst die Creator- oder Admin-Rolle, um Hunts zu erstellen.",
"public": "Öffentlich (auf der Startseite sichtbar)",
"reveal_answers": "Antworten aufdecken",
"reveal_quests": "Quests aufdecken",
"sidebar": "Hunt erstellen",
"start": "Start",
"success": "Hunt erfolgreich erstellt!",
"title": "Neuen Hunt erstellen",
"virtual": "Virtueller Hunt"
},
"diashow": { "diashow": {
"head": "Diashow" "head": "Diashow"
}, },
@@ -129,11 +151,11 @@
"title": "Impressum" "title": "Impressum"
}, },
"pictures": { "pictures": {
"head": "Bilderwand", "filter_quest": "Filtere Bilder nach Quests",
"select_team": "Wähle ein Team",
"filter_team": "Filtere Bilder nach Teams", "filter_team": "Filtere Bilder nach Teams",
"head": "Bilderwand",
"select_quest": "Wähle eine Quest", "select_quest": "Wähle eine Quest",
"filter_quest": "Filtere Bilder nach Quests" "select_team": "Wähle ein Team"
}, },
"profile": { "profile": {
"admins_and_creators": "Admins & Ersteller", "admins_and_creators": "Admins & Ersteller",
@@ -144,8 +166,8 @@
"promote": "Befördern", "promote": "Befördern",
"promote_user": "Benutzer befördern", "promote_user": "Benutzer befördern",
"role": "Rolle", "role": "Rolle",
"role_changed": "Rolle aktualisiert!",
"role_change_error": "Rolle konnte nicht geändert werden!", "role_change_error": "Rolle konnte nicht geändert werden!",
"role_changed": "Rolle aktualisiert!",
"role_confirm": "Möchtest du die Rolle von {name} zu {role} ändern?", "role_confirm": "Möchtest du die Rolle von {name} zu {role} ändern?",
"search_user": "Benutzer per E-Mail suchen...", "search_user": "Benutzer per E-Mail suchen...",
"uploaded_pictures": "Hochgeladene Bilder", "uploaded_pictures": "Hochgeladene Bilder",
@@ -273,4 +295,4 @@
"uploadFile": "Datei hochladen", "uploadFile": "Datei hochladen",
"voteRating": "vote rating {value} of {max}" "voteRating": "vote rating {value} of {max}"
} }
} }
+29 -7
View File
@@ -36,11 +36,11 @@
}, },
"enums": { "enums": {
"text_type": { "text_type": {
"CHAR": "One character",
"INTEGER": "Whole number", "INTEGER": "Whole number",
"NUMBER": "Number", "NUMBER": "Number",
"TEXT": "Free text", "TEXT": "Free text",
"WORD": "One word", "WORD": "One word"
"CHAR": "One character"
}, },
"user_role": { "user_role": {
"ADMIN": "Admin", "ADMIN": "Admin",
@@ -80,6 +80,28 @@
"refresh": "Refresh", "refresh": "Refresh",
"update_btn": "Update" "update_btn": "Update"
}, },
"create_hunt": {
"allow_join": "Allow joining",
"create_btn": "Create Hunt",
"de": "German",
"description_de": "Description (German)",
"description_en": "Description (English)",
"en": "English",
"end": "End",
"has_end": "Has end date?",
"has_start": "Has start date?",
"name_de": "Name (German)",
"name_en": "Name (English)",
"not_allowed": "You need the Creator or Admin role to create hunts.",
"public": "Public (visible on home page)",
"reveal_answers": "Reveal answers",
"reveal_quests": "Reveal quests",
"sidebar": "Create Hunt",
"start": "Start",
"success": "Hunt created successfully!",
"title": "Create a new Hunt",
"virtual": "Virtual hunt"
},
"diashow": { "diashow": {
"head": "Diashow" "head": "Diashow"
}, },
@@ -129,11 +151,11 @@
"title": "Imprint" "title": "Imprint"
}, },
"pictures": { "pictures": {
"head": "Picture wall", "filter_quest": "Filter pictures by quests",
"select_team": "Select a team",
"filter_team": "Filter pictures by teams", "filter_team": "Filter pictures by teams",
"head": "Picture wall",
"select_quest": "Select a quest", "select_quest": "Select a quest",
"filter_quest": "Filter pictures by quests" "select_team": "Select a team"
}, },
"profile": { "profile": {
"admins_and_creators": "Admins & Creators", "admins_and_creators": "Admins & Creators",
@@ -144,8 +166,8 @@
"promote": "Promote", "promote": "Promote",
"promote_user": "Promote a user", "promote_user": "Promote a user",
"role": "Role", "role": "Role",
"role_changed": "Role updated!",
"role_change_error": "Could not change role!", "role_change_error": "Could not change role!",
"role_changed": "Role updated!",
"role_confirm": "Do you want to change the role of {name} to {role}?", "role_confirm": "Do you want to change the role of {name} to {role}?",
"search_user": "Search user by email...", "search_user": "Search user by email...",
"uploaded_pictures": "Uploaded pictures", "uploaded_pictures": "Uploaded pictures",
@@ -273,4 +295,4 @@
"uploadFile": "Upload file", "uploadFile": "Upload file",
"voteRating": "vote rating {value} of {max}" "voteRating": "vote rating {value} of {max}"
} }
} }
+12
View File
@@ -60,6 +60,18 @@ const isHuntAdmin = computed(
<VaSidebarItemTitle>Home</VaSidebarItemTitle> <VaSidebarItemTitle>Home</VaSidebarItemTitle>
</VaSidebarItemContent> </VaSidebarItemContent>
</VaSidebarItem> </VaSidebarItem>
<VaSidebarItem
v-if="user?.role === 'CREATOR' || user?.role === 'ADMIN'"
:to="localePath('/admin/hunt/create')"
:active="localePath('/admin/hunt/create') === route.path"
>
<VaSidebarItemContent>
<VaIcon name="add_circle" />
<VaSidebarItemTitle>{{
t('page.create_hunt.sidebar')
}}</VaSidebarItemTitle>
</VaSidebarItemContent>
</VaSidebarItem>
<VaSidebarItem <VaSidebarItem
:to="localePath('/impressum')" :to="localePath('/impressum')"
:active="localePath('/impressum') === route.path" :active="localePath('/impressum') === route.path"
+194
View File
@@ -0,0 +1,194 @@
<script setup lang="ts">
import { sluggy } from '#imports';
definePageMeta({
middleware: ['auth']
});
const { t } = useI18n();
const { user } = useUserSession();
const localePath = useLocalePath();
const router = useRouter();
const { init } = useToast();
const validation = useValidation();
const canCreate = computed(
() => user.value?.role === 'CREATOR' || user.value?.role === 'ADMIN'
);
const form = reactive({
name_de: '',
name_en: '',
description_de: '',
description_en: '',
virtual: false,
start: null as Date | null,
end: null as Date | null,
allowJoin: false,
revealQuests: false,
revealAnswers: false,
public: true
});
const loading = ref(false);
const formError = ref('');
async function submit() {
loading.value = true;
formError.value = '';
try {
const hunt = await $fetch('/api/admin/hunt', {
method: 'POST',
body: {
...form,
start: form.start?.toISOString() ?? null,
end: form.end?.toISOString() ?? null
}
});
init({
message: t('page.create_hunt.success'),
color: 'success'
});
await router.push(
localePath(`/hunt/${sluggy({ id: hunt.id, name: hunt.name_de })}/admin`)
);
} catch (e) {
formError.value = parseError(e);
}
loading.value = false;
}
</script>
<template>
<div class="mx-auto max-w-2xl">
<VaAlert v-if="!canCreate" color="warning" class="mb-4">
{{ t('page.create_hunt.not_allowed') }}
</VaAlert>
<VaCard v-else stripe stripe-color="success">
<VaCardTitle>{{ t('page.create_hunt.title') }}</VaCardTitle>
<VaCardContent>
<VaForm class="flex flex-col gap-4">
<div class="grid grid-cols-1 gap-2 md:grid-cols-2">
<h3 class="text-center">{{ t('page.create_hunt.de') }}</h3>
<h3 class="text-center">{{ t('page.create_hunt.en') }}</h3>
<VaInput
v-model="form.name_de"
:label="t('page.create_hunt.name_de')"
:rules="[
validation.required(t('page.create_hunt.name_de')),
validation.max(t('page.create_hunt.name_de'), 256)
]"
counter
max-length="256"
/>
<VaInput
v-model="form.name_en"
:label="t('page.create_hunt.name_en')"
:rules="[
validation.required(t('page.create_hunt.name_en')),
validation.max(t('page.create_hunt.name_en'), 256)
]"
counter
max-length="256"
/>
<VaTextarea
v-model="form.description_de"
:label="t('page.create_hunt.description_de')"
max-length="1000"
/>
<VaTextarea
v-model="form.description_en"
:label="t('page.create_hunt.description_en')"
max-length="1000"
/>
</div>
<VaCheckbox
v-model="form.virtual"
:label="t('page.create_hunt.virtual')"
/>
<VaCheckbox
v-model="form.public"
:label="t('page.create_hunt.public')"
/>
<VaCheckbox
v-model="form.allowJoin"
:label="t('page.create_hunt.allow_join')"
/>
<VaCheckbox
v-model="form.revealQuests"
:label="t('page.create_hunt.reveal_quests')"
/>
<VaCheckbox
v-model="form.revealAnswers"
:label="t('page.create_hunt.reveal_answers')"
/>
<hr />
<div class="flex flex-row gap-2">
<VaCheckbox
:label="t('page.create_hunt.has_start')"
:model-value="!!form.start"
@update:model-value="
(newVal: boolean) => (form.start = newVal ? new Date() : null)
"
/>
<VaDateInput
v-if="form.start"
v-model="form.start"
:label="t('page.create_hunt.start')"
manual-input
/>
<VaTimeInput
v-if="form.start"
v-model="form.start"
:label="t('page.create_hunt.start')"
view="seconds"
manual-input
/>
</div>
<div class="flex flex-row gap-2">
<VaCheckbox
:label="t('page.create_hunt.has_end')"
:model-value="!!form.end"
@update:model-value="
(newVal: boolean) => (form.end = newVal ? new Date() : null)
"
/>
<VaDateInput
v-if="form.end"
v-model="form.end"
:label="t('page.create_hunt.end')"
manual-input
/>
<VaTimeInput
v-if="form.end"
v-model="form.end"
:label="t('page.create_hunt.end')"
view="seconds"
manual-input
/>
</div>
<VaAlert
v-if="formError.length > 0"
color="danger"
class="w-full text-center"
>{{ t(formError) }}</VaAlert
>
<VaButton
:loading="loading"
:disabled="
loading || form.name_de.length < 1 || form.name_en.length < 1
"
color="success"
icon="add"
@click="submit"
>{{ t('page.create_hunt.create_btn') }}</VaButton
>
</VaForm>
</VaCardContent>
</VaCard>
</div>
</template>
+1
View File
@@ -253,6 +253,7 @@ async function deleteImage() {
clearable-icon="replay" clearable-icon="replay"
/> />
<VaCheckbox v-model="formData.cloned.value.virtual" label="Virtual" /> <VaCheckbox v-model="formData.cloned.value.virtual" label="Virtual" />
<VaCheckbox v-model="formData.cloned.value.public" label="Public" />
<VaCheckbox <VaCheckbox
v-model="formData.cloned.value.allowJoin" v-model="formData.cloned.value.allowJoin"
label="Allow Join" label="Allow Join"
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "public"."Hunt" ADD COLUMN "public" BOOLEAN NOT NULL DEFAULT true;
+1
View File
@@ -78,6 +78,7 @@ model Hunt {
allowJoin Boolean @default(false) allowJoin Boolean @default(false)
revealQuests Boolean @default(false) revealQuests Boolean @default(false)
revealAnswers Boolean @default(false) revealAnswers Boolean @default(false)
public Boolean @default(true)
creator User @relation(fields: [creatorId], references: [id], onUpdate: Cascade, onDelete: Cascade) creator User @relation(fields: [creatorId], references: [id], onUpdate: Cascade, onDelete: Cascade)
creatorId Int creatorId Int
@@ -29,6 +29,7 @@ export default defineEventHandler(async (event) => {
description_de: true, description_de: true,
description_en: true, description_en: true,
virtual: true, virtual: true,
public: true,
start: true, start: true,
end: true, end: true,
allowJoin: true, allowJoin: true,
+3 -2
View File
@@ -21,8 +21,9 @@ export default defineEventHandler(async (event) => {
description_de: z.string().min(1).max(1000).trim(), description_de: z.string().min(1).max(1000).trim(),
description_en: z.string().min(1).max(1000).trim(), description_en: z.string().min(1).max(1000).trim(),
virtual: z.boolean(), virtual: z.boolean(),
start: z.iso.datetime(), public: z.boolean(),
end: z.iso.datetime(), start: z.iso.datetime().nullable(),
end: z.iso.datetime().nullable(),
allowJoin: z.boolean(), allowJoin: z.boolean(),
revealQuests: z.boolean(), revealQuests: z.boolean(),
revealAnswers: z.boolean() revealAnswers: z.boolean()
+47
View File
@@ -0,0 +1,47 @@
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
}
});
});
+1
View File
@@ -103,6 +103,7 @@ export default defineEventHandler(async (event) => {
}, },
where: { where: {
deletedAt: null, deletedAt: null,
public: true,
OR: [ OR: [
{ {
start: { start: {