Add diashow and styling
This commit is contained in:
@@ -28,22 +28,22 @@
|
|||||||
- [ ] Create hunt
|
- [ ] Create hunt
|
||||||
- [ ] Add Questions
|
- [ ] Add Questions
|
||||||
- [ ] View Answers on Map
|
- [ ] View Answers on Map
|
||||||
- [ ] Image Diashow
|
- [x] Image Diashow
|
||||||
- **Hunt User**
|
- **Hunt User**
|
||||||
|
- [x] View all images on one page
|
||||||
|
- [ ] i18n data
|
||||||
|
- [ ] Mark image as private
|
||||||
- [ ] How-to/Guide/Good explanation
|
- [ ] How-to/Guide/Good explanation
|
||||||
|
- [ ] Leave/Remove/Edit team
|
||||||
|
- [ ] Support chat
|
||||||
|
- [ ] Copy team from different hunt
|
||||||
- [ ] Get Geo-Location
|
- [ ] Get Geo-Location
|
||||||
- [ ] Track walking distance
|
|
||||||
- [ ] View other answers
|
- [ ] View other answers
|
||||||
- [ ] View other reviews and scores
|
- [ ] View other reviews and scores
|
||||||
- [ ] Review other answers (Fan-Favorite)
|
|
||||||
- [ ] View all images on one page
|
|
||||||
- [ ] Notifications
|
|
||||||
- [ ] i18n data
|
|
||||||
- [ ] Process image uploads (resize, remove EXIF, etc.)
|
- [ ] Process image uploads (resize, remove EXIF, etc.)
|
||||||
- [ ] Mark image as private
|
- [ ] Review other answers (Fan-Favorite)
|
||||||
- [ ] Support chat
|
- [ ] Track walking distance
|
||||||
- [ ] Leave/Remove team
|
- [ ] Notifications
|
||||||
- [ ] Copy team from different hunt
|
|
||||||
- **General**
|
- **General**
|
||||||
- [x] Pretty slugified urls
|
- [x] Pretty slugified urls
|
||||||
- [ ] All static texts translated
|
- [ ] All static texts translated
|
||||||
|
|||||||
+2
-1
@@ -34,7 +34,8 @@
|
|||||||
"default_tile": "PicHunt",
|
"default_tile": "PicHunt",
|
||||||
"refresh": "Aktualisieren",
|
"refresh": "Aktualisieren",
|
||||||
"switch_lang": "Sprache ändern zu {locale}",
|
"switch_lang": "Sprache ändern zu {locale}",
|
||||||
"title": "{title} {'|'} PicHunt"
|
"title": "{title} {'|'} PicHunt",
|
||||||
|
"two_title": "{subtitle} {'|'} {title} {'|'} PicHunt"
|
||||||
},
|
},
|
||||||
"locales": {
|
"locales": {
|
||||||
"de": "Deutsch",
|
"de": "Deutsch",
|
||||||
|
|||||||
+2
-1
@@ -34,7 +34,8 @@
|
|||||||
"default_tile": "PicHunt",
|
"default_tile": "PicHunt",
|
||||||
"refresh": "Refresh",
|
"refresh": "Refresh",
|
||||||
"switch_lang": "Switch locale to {locale}",
|
"switch_lang": "Switch locale to {locale}",
|
||||||
"title": "{title} {'|'} PicHunt"
|
"title": "{title} {'|'} PicHunt",
|
||||||
|
"two_title": "{subtitle} {'|'} {title} {'|'} PicHunt"
|
||||||
},
|
},
|
||||||
"locales": {
|
"locales": {
|
||||||
"de": "German",
|
"de": "German",
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useTitleStore } from '~/stores/title';
|
||||||
|
|
||||||
|
definePageMeta({
|
||||||
|
layout: 'full'
|
||||||
|
});
|
||||||
|
const app = useNuxtApp();
|
||||||
|
const { loggedIn } = useUserSession();
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const { name, id } = app.$slugData.huntSlug!;
|
||||||
|
|
||||||
|
const titleStore = useTitleStore();
|
||||||
|
|
||||||
|
type Picture = {
|
||||||
|
quest: { id: number; title: string };
|
||||||
|
team: {
|
||||||
|
name: string;
|
||||||
|
id: number;
|
||||||
|
};
|
||||||
|
picture: {
|
||||||
|
creator: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const { data, refresh, error } = await useFetch(`/api/hunt/${id}/diashow`, {
|
||||||
|
transform: (input) => {
|
||||||
|
if (!input || input.quests.length <= 0)
|
||||||
|
return { id: 0, name: '', pictures: [] as Picture[] };
|
||||||
|
const { quests, ...rest } = input;
|
||||||
|
const pictures: Picture[] = [];
|
||||||
|
|
||||||
|
quests.forEach(({ answers, ...quest }) => {
|
||||||
|
answers.forEach(({ team, picture }) => {
|
||||||
|
if (!picture) return;
|
||||||
|
pictures.push({
|
||||||
|
team,
|
||||||
|
picture,
|
||||||
|
quest
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
pictures.sort(() => Math.random() - 0.5);
|
||||||
|
console.log(pictures);
|
||||||
|
|
||||||
|
return { ...rest, pictures };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
title: t('layouts.two_title', {
|
||||||
|
title: data.value?.name || name,
|
||||||
|
subtitle: 'Diashow'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(loggedIn, () => refresh());
|
||||||
|
|
||||||
|
titleStore.title = data.value?.name;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<article class="h-dvh w-full">
|
||||||
|
<ClientOnly v-if="data"
|
||||||
|
><VaCarousel
|
||||||
|
stateful
|
||||||
|
height="100dvh"
|
||||||
|
autoscroll
|
||||||
|
:indicators="false"
|
||||||
|
fallbackIcon="broken_image"
|
||||||
|
infinite
|
||||||
|
color="secondary"
|
||||||
|
:items="data.pictures"
|
||||||
|
style="--va-carousel-background: black"
|
||||||
|
>
|
||||||
|
<template #default="{ item }: { item: Picture }"
|
||||||
|
><VaImage :src="item.picture.url" fit="contain" lazy />
|
||||||
|
<p
|
||||||
|
class="absolute top-2 mx-auto rounded bg-gray-200/75 px-2 py-1 text-center text-xl font-bold"
|
||||||
|
>
|
||||||
|
{{ item.quest.title }} — {{ item.team.name }} —
|
||||||
|
{{ item.picture.creator.name }}
|
||||||
|
</p></template
|
||||||
|
></VaCarousel
|
||||||
|
></ClientOnly
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-else-if="error"
|
||||||
|
class="flex h-full w-full flex-col items-center justify-center text-center text-2xl"
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]"
|
||||||
|
>Answers are not revealed yet, please wait until the end!</VaAlert
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]" v-if="error.statusCode !== 403">{{
|
||||||
|
error
|
||||||
|
}}</VaAlert
|
||||||
|
><VaButton
|
||||||
|
icon="arrow_back"
|
||||||
|
:to="$localePath(`/hunt/${sluggy($nuxt.$slugData.huntSlug!)}`)"
|
||||||
|
>Back to Hunt</VaButton
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex h-full w-full flex-col items-center justify-center text-center text-2xl"
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]"
|
||||||
|
>Answers are not revealed yet, please wait until the end!</VaAlert
|
||||||
|
><VaButton
|
||||||
|
icon="arrow_back"
|
||||||
|
:to="$localePath(`/hunt/${sluggy($nuxt.$slugData.huntSlug!)}`)"
|
||||||
|
>Back to Hunt</VaButton
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -44,38 +44,57 @@ async function invite() {
|
|||||||
<template>
|
<template>
|
||||||
<h1 class="text-2xl">
|
<h1 class="text-2xl">
|
||||||
{{ data?.name || name }}
|
{{ data?.name || name }}
|
||||||
<VaButton
|
|
||||||
icon="replay"
|
|
||||||
@click="refresh"
|
|
||||||
:disabled="pending"
|
|
||||||
title="Refresh"
|
|
||||||
/>
|
|
||||||
<VaButtonGroup v-if="data?.isMember">
|
|
||||||
<VaButton
|
|
||||||
color="danger"
|
|
||||||
icon="edit"
|
|
||||||
:to="$localePath(`/hunt/${sluggy(data)}/admin`)"
|
|
||||||
>Admin</VaButton
|
|
||||||
><VaButton
|
|
||||||
color="danger"
|
|
||||||
icon="groups"
|
|
||||||
:to="$localePath(`/hunt/${sluggy(data)}/teams`)"
|
|
||||||
>Teams</VaButton
|
|
||||||
>
|
|
||||||
<VaButton
|
|
||||||
color="success"
|
|
||||||
icon="leaderboard"
|
|
||||||
:to="$localePath(`/hunt/${sluggy(data)}/showcase`)"
|
|
||||||
>Showcase</VaButton
|
|
||||||
>
|
|
||||||
</VaButtonGroup>
|
|
||||||
|
|
||||||
<VaChip v-if="data?.totalScore" class="float-right" color="success"
|
<VaChip v-if="data?.totalScore" class="float-right" color="success"
|
||||||
>Total points: {{ data!!.totalScore }}</VaChip
|
>Total points: {{ data!!.totalScore }}</VaChip
|
||||||
>
|
>
|
||||||
</h1>
|
</h1>
|
||||||
|
<div class="grid w-full grid-cols-2 gap-2 sm:grid-cols-3 md:grid-cols-6">
|
||||||
|
<VaButton icon="replay" @click="refresh" :disabled="pending" title="Refresh"
|
||||||
|
>Refresh</VaButton
|
||||||
|
>
|
||||||
|
|
||||||
|
<VaButton
|
||||||
|
v-if="(data?.revealAnswers && data?.revealQuests) || data?.isMember"
|
||||||
|
color="success"
|
||||||
|
icon="leaderboard"
|
||||||
|
:to="$localePath(`/hunt/${sluggy(data)}/showcase`)"
|
||||||
|
>Showcase</VaButton
|
||||||
|
>
|
||||||
|
<VaButton
|
||||||
|
v-if="(data?.revealAnswers && data?.revealQuests) || data?.isMember"
|
||||||
|
color="success"
|
||||||
|
icon="collections"
|
||||||
|
:to="$localePath(`/hunt/${sluggy(data)}/diashow`)"
|
||||||
|
>Diashow</VaButton
|
||||||
|
>
|
||||||
|
<VaButton
|
||||||
|
v-if="(data?.revealAnswers && data?.revealQuests) || data?.isMember"
|
||||||
|
color="success"
|
||||||
|
icon="auto_awesome_mosaic"
|
||||||
|
:to="$localePath(`/hunt/${sluggy(data)}/pictures`)"
|
||||||
|
>All pictures</VaButton
|
||||||
|
>
|
||||||
|
<VaButton
|
||||||
|
v-if="data?.isMember"
|
||||||
|
color="danger"
|
||||||
|
icon="edit"
|
||||||
|
:to="$localePath(`/hunt/${sluggy(data)}/admin`)"
|
||||||
|
>Admin</VaButton
|
||||||
|
><VaButton
|
||||||
|
v-if="data?.isMember"
|
||||||
|
color="danger"
|
||||||
|
icon="groups"
|
||||||
|
:to="$localePath(`/hunt/${sluggy(data)}/teams`)"
|
||||||
|
>Teams</VaButton
|
||||||
|
>
|
||||||
|
</div>
|
||||||
<div v-if="data">
|
<div v-if="data">
|
||||||
<p>{{ data.description }}</p>
|
<div class="flex flex-col gap-2">
|
||||||
|
<p v-for="(line, i) in data.description.split('\n')" :key="i">
|
||||||
|
{{ line }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<ClickableImage
|
<ClickableImage
|
||||||
v-if="data?.picture"
|
v-if="data?.picture"
|
||||||
:src="data?.picture?.url"
|
:src="data?.picture?.url"
|
||||||
@@ -139,7 +158,6 @@ async function invite() {
|
|||||||
<VaCard
|
<VaCard
|
||||||
v-for="quest in data.quests"
|
v-for="quest in data.quests"
|
||||||
:key="`q-${quest.id}`"
|
:key="`q-${quest.id}`"
|
||||||
:to="$localePath(`/hunt/${sluggy(data)}/${sluggy(quest)}`)"
|
|
||||||
stripe
|
stripe
|
||||||
:stripe-color="
|
:stripe-color="
|
||||||
(quest.answer?.review?.score && quest.answer?.review?.score > 0) ||
|
(quest.answer?.review?.score && quest.answer?.review?.score > 0) ||
|
||||||
@@ -152,8 +170,9 @@ async function invite() {
|
|||||||
>
|
>
|
||||||
<VaCardTitle><QuestTags :quest="quest" /></VaCardTitle>
|
<VaCardTitle><QuestTags :quest="quest" /></VaCardTitle>
|
||||||
<VaImage
|
<VaImage
|
||||||
v-if="!hideAnswers && quest?.answer?.picture"
|
v-if="!hideAnswers"
|
||||||
:src="quest?.answer?.picture?.url"
|
:src="quest?.answer?.picture?.url ?? ''"
|
||||||
|
fallback-text="No picture uploaded"
|
||||||
class="h-32"
|
class="h-32"
|
||||||
fit="cover"
|
fit="cover"
|
||||||
lazy
|
lazy
|
||||||
@@ -161,17 +180,23 @@ async function invite() {
|
|||||||
<template #loader> <VaProgressCircle indeterminate /> </template
|
<template #loader> <VaProgressCircle indeterminate /> </template
|
||||||
></VaImage>
|
></VaImage>
|
||||||
<VaCardContent>
|
<VaCardContent>
|
||||||
<p class="line-clamp-1">{{ quest.description }}</p>
|
<p class="line-clamp-2 h-12">{{ quest.description }}</p>
|
||||||
|
|
||||||
<div v-if="!hideAnswers && quest.answer?.text">
|
<div v-if="!hideAnswers && quest.answer?.text">
|
||||||
<VaDivider />
|
<VaDivider />
|
||||||
<p class="line-clamp-1">
|
<p class="line-clamp-1">{{ quest.answer?.text }}</p>
|
||||||
{{ quest.answer?.text }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</VaCardContent>
|
</VaCardContent>
|
||||||
<VaCardActions v-if="data.isMember">
|
<VaCardActions>
|
||||||
<VaButton
|
<VaButton
|
||||||
|
:to="$localePath(`/hunt/${sluggy(data)}/${sluggy(quest)}`)"
|
||||||
|
color="primary"
|
||||||
|
icon="rate_review"
|
||||||
|
class="flex-grow"
|
||||||
|
>Open</VaButton
|
||||||
|
>
|
||||||
|
<VaButton
|
||||||
|
v-if="data.isMember"
|
||||||
color="danger"
|
color="danger"
|
||||||
:icon="(quest.unreviewed || 0) > 0 ? 'priority_high' : undefined"
|
:icon="(quest.unreviewed || 0) > 0 ? 'priority_high' : undefined"
|
||||||
:to="$localePath(`/hunt/${sluggy(data)}/${sluggy(quest)}/admin`)"
|
:to="$localePath(`/hunt/${sluggy(data)}/${sluggy(quest)}/admin`)"
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useTitleStore } from '~/stores/title';
|
||||||
|
|
||||||
|
definePageMeta({
|
||||||
|
layout: 'full'
|
||||||
|
});
|
||||||
|
const app = useNuxtApp();
|
||||||
|
const { loggedIn } = useUserSession();
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const { name, id } = app.$slugData.huntSlug!;
|
||||||
|
|
||||||
|
const titleStore = useTitleStore();
|
||||||
|
|
||||||
|
type Picture = {
|
||||||
|
quest: { id: number; title: string };
|
||||||
|
team: {
|
||||||
|
name: string;
|
||||||
|
id: number;
|
||||||
|
};
|
||||||
|
picture: {
|
||||||
|
creator: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const { data, refresh, error } = await useFetch(`/api/hunt/${id}/diashow`, {
|
||||||
|
transform: (input) => {
|
||||||
|
if (!input || input.quests.length <= 0)
|
||||||
|
return { id: 0, name: '', cols: [] as Picture[][], count: 0 };
|
||||||
|
const { quests, ...rest } = input;
|
||||||
|
const pictures: Picture[] = [];
|
||||||
|
|
||||||
|
quests.forEach(({ answers, ...quest }) => {
|
||||||
|
answers.forEach(({ team, picture }) => {
|
||||||
|
if (!picture) return;
|
||||||
|
pictures.push({
|
||||||
|
team,
|
||||||
|
picture,
|
||||||
|
quest
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
pictures.sort(() => Math.random() - 0.5);
|
||||||
|
|
||||||
|
const cols = pictures.reduce(
|
||||||
|
(c, p, i) => {
|
||||||
|
c[i % 4].push(p);
|
||||||
|
return c;
|
||||||
|
},
|
||||||
|
new Array(4).fill(0).map(() => [] as Picture[])
|
||||||
|
);
|
||||||
|
|
||||||
|
return { ...rest, cols, count: pictures.length };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
title: t('layouts.two_title', {
|
||||||
|
title: data.value?.name || name,
|
||||||
|
subtitle: 'Diashow'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(loggedIn, () => refresh());
|
||||||
|
|
||||||
|
titleStore.title = data.value?.name;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<article class="h-dvh w-full">
|
||||||
|
<div
|
||||||
|
v-if="data"
|
||||||
|
class="m-4 grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4"
|
||||||
|
>
|
||||||
|
<div v-for="(col, i) in data.cols" :key="i" class="grid gap-4">
|
||||||
|
<ClickableImage
|
||||||
|
v-for="pic in col"
|
||||||
|
:key="pic.picture.url"
|
||||||
|
:src="pic.picture.url"
|
||||||
|
class="h-auto max-w-full rounded-lg"
|
||||||
|
:title="`${pic.quest.title} — ${pic.team.name} — ${pic.picture.creator.name}`"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<VaAlert
|
||||||
|
color="warning"
|
||||||
|
v-if="data.count <= 0"
|
||||||
|
class="sm:col-span-2 md:col-span-3 lg:col-span-4"
|
||||||
|
>No pictures has been submitted yet :(</VaAlert
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else-if="error"
|
||||||
|
class="flex h-full w-full flex-col items-center justify-center text-center text-2xl"
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]"
|
||||||
|
>Answers are not revealed yet, please wait until the end!</VaAlert
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]" v-if="error.statusCode !== 403">{{
|
||||||
|
error
|
||||||
|
}}</VaAlert
|
||||||
|
><VaButton
|
||||||
|
icon="arrow_back"
|
||||||
|
:to="$localePath(`/hunt/${sluggy($nuxt.$slugData.huntSlug!)}`)"
|
||||||
|
>Back to Hunt</VaButton
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex h-full w-full flex-col items-center justify-center text-center text-2xl"
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]"
|
||||||
|
>Answers are not revealed yet, please wait until the end!</VaAlert
|
||||||
|
><VaButton
|
||||||
|
icon="arrow_back"
|
||||||
|
:to="$localePath(`/hunt/${sluggy($nuxt.$slugData.huntSlug!)}`)"
|
||||||
|
>Back to Hunt</VaButton
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -4,15 +4,13 @@ import NumberCard from '~/components/showcase/NumberCard.vue';
|
|||||||
import { fullDate } from '~~/server/utils/date';
|
import { fullDate } from '~~/server/utils/date';
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
// TODO: re-enable perms
|
|
||||||
// middleware: ['admin'],
|
|
||||||
layout: 'full'
|
layout: 'full'
|
||||||
});
|
});
|
||||||
const { t, d } = useI18n();
|
const { t, d } = useI18n();
|
||||||
|
|
||||||
const app = useNuxtApp();
|
const app = useNuxtApp();
|
||||||
const { name, id } = app.$slugData.huntSlug!;
|
const { name, id } = app.$slugData.huntSlug!;
|
||||||
const { data } = await useFetch(`/api/admin/hunt/${id}/showcase`);
|
const { data, error } = await useFetch(`/api/hunt/${id}/showcase`);
|
||||||
|
|
||||||
const { toggle, isFullscreen, isSupported } = useFullscreen();
|
const { toggle, isFullscreen, isSupported } = useFullscreen();
|
||||||
|
|
||||||
@@ -243,7 +241,23 @@ const columns = leaderboardColumns.map((c) =>
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
<article v-else>pending...</article>
|
|
||||||
|
<article
|
||||||
|
v-else-if="error"
|
||||||
|
class="flex h-dvh w-full flex-col items-center justify-center text-center text-2xl"
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]"
|
||||||
|
>Answers are not revealed yet, please wait until the end!</VaAlert
|
||||||
|
>
|
||||||
|
<VaAlert color="danger" class="w-[90%]" v-if="error.statusCode !== 403">{{
|
||||||
|
error
|
||||||
|
}}</VaAlert
|
||||||
|
><VaButton
|
||||||
|
icon="arrow_back"
|
||||||
|
:to="$localePath(`/hunt/${sluggy($nuxt.$slugData.huntSlug!)}`)"
|
||||||
|
>Back to Hunt</VaButton
|
||||||
|
>
|
||||||
|
</article>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { useValidatedParams, z, zh } from 'h3-zod';
|
||||||
|
import prisma from '~~/lib/prisma';
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { huntId } = await useValidatedParams(
|
||||||
|
event,
|
||||||
|
z.object({
|
||||||
|
huntId: zh.numAsString
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const user = await getUserSession(event);
|
||||||
|
const userId = user.user?.id || 0;
|
||||||
|
|
||||||
|
// TODO: use one request for this logic
|
||||||
|
const exists = await prisma.hunt.findUnique({
|
||||||
|
where: {
|
||||||
|
id: huntId,
|
||||||
|
deletedAt: null
|
||||||
|
},
|
||||||
|
select: { id: true }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
|
throw createError({ status: 404, statusText: 'Not found!' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const hunt = await prisma.hunt.findUnique({
|
||||||
|
where: {
|
||||||
|
id: huntId,
|
||||||
|
deletedAt: null,
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
revealAnswers: true,
|
||||||
|
revealQuests: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
creatorId: userId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
members: {
|
||||||
|
some: {
|
||||||
|
memberId: userId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
quests: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
answers: {
|
||||||
|
select: {
|
||||||
|
team: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
picture: {
|
||||||
|
select: {
|
||||||
|
url: true,
|
||||||
|
creator: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
final: true,
|
||||||
|
picture: {
|
||||||
|
isNot: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
answers: {
|
||||||
|
some: {
|
||||||
|
final: true,
|
||||||
|
picture: {
|
||||||
|
isNot: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hunt) {
|
||||||
|
throw createError({
|
||||||
|
status: 403,
|
||||||
|
statusText: 'Answers are not revealed yet!'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return hunt;
|
||||||
|
});
|
||||||
+38
-24
@@ -2,16 +2,6 @@ import { useValidatedParams, z, zh } from 'h3-zod';
|
|||||||
import prisma from '~~/lib/prisma';
|
import prisma from '~~/lib/prisma';
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
// TODO: re-enable perms
|
|
||||||
// const user = await requireUserSession(event);
|
|
||||||
//
|
|
||||||
// if (user.user.role !== 'ADMIN') {
|
|
||||||
// throw createError({
|
|
||||||
// status: 403,
|
|
||||||
// statusText: 'Not allowed!'
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// const userId = user.user.id;
|
|
||||||
const { huntId } = await useValidatedParams(
|
const { huntId } = await useValidatedParams(
|
||||||
event,
|
event,
|
||||||
z.object({
|
z.object({
|
||||||
@@ -19,21 +9,42 @@ export default defineEventHandler(async (event) => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const user = await getUserSession(event);
|
||||||
|
const userId = user.user?.id || 0;
|
||||||
|
|
||||||
|
// TODO: use one request for this logic
|
||||||
|
const exists = await prisma.hunt.findUnique({
|
||||||
|
where: {
|
||||||
|
id: huntId,
|
||||||
|
deletedAt: null
|
||||||
|
},
|
||||||
|
select: { id: true }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
|
throw createError({ status: 404, statusText: 'Not found!' });
|
||||||
|
}
|
||||||
|
|
||||||
const _hunt = await prisma.hunt.findUnique({
|
const _hunt = await prisma.hunt.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: huntId
|
id: huntId,
|
||||||
// OR: [
|
deletedAt: null,
|
||||||
// {
|
OR: [
|
||||||
// creatorId: userId
|
{
|
||||||
// },
|
revealAnswers: true,
|
||||||
// {
|
revealQuests: true
|
||||||
// members: {
|
},
|
||||||
// some: {
|
{
|
||||||
// memberId: userId
|
creatorId: userId
|
||||||
// }
|
},
|
||||||
// }
|
{
|
||||||
// }
|
members: {
|
||||||
// ]
|
some: {
|
||||||
|
memberId: userId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -163,7 +174,10 @@ export default defineEventHandler(async (event) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!_hunt) {
|
if (!_hunt) {
|
||||||
throw createError({ status: 404, statusText: 'Not found!' });
|
throw createError({
|
||||||
|
status: 403,
|
||||||
|
statusText: 'Answers are not revealed yet!'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { teams, ...hunt } = _hunt;
|
const { teams, ...hunt } = _hunt;
|
||||||
Reference in New Issue
Block a user