From 4189c95d38885eaf6f59853056083c66151dab6e Mon Sep 17 00:00:00 2001 From: Pascal Syma Date: Sat, 9 Aug 2025 14:58:38 +0200 Subject: [PATCH] Start admin pages --- app/components/admin/Answer.vue | 137 ++++++++++++++++ app/layouts/default.vue | 42 ++++- app/middleware/admin.ts | 18 ++ .../hunt/[huntSlug]/[questSlug]/admin.vue | 72 ++++++++ .../hunt/[huntSlug]/[questSlug]/index.vue | 14 +- app/pages/hunt/[huntSlug]/admin.vue | 155 ++++++++++++++++++ app/pages/hunt/[huntSlug]/index.vue | 19 ++- bun.lock | 14 ++ nuxt.config.ts | 5 +- package.json | 2 + .../migration.sql | 4 + .../migration.sql | 5 + prisma/schema.prisma | 24 ++- prisma/seed/hunt.ts | 130 ++++++++++++++- .../admin/answer/[answerId]/review.post.ts | 67 ++++++++ server/api/admin/hunt/[huntId]/index.get.ts | 78 +++++++++ server/api/admin/hunt/[huntId]/index.post.ts | 59 +++++++ server/api/admin/quest/[questId]/index.get.ts | 101 ++++++++++++ server/utils/json.ts | 11 ++ {server => shared}/auth.d.ts | 0 20 files changed, 935 insertions(+), 22 deletions(-) create mode 100644 app/components/admin/Answer.vue create mode 100644 app/middleware/admin.ts create mode 100644 app/pages/hunt/[huntSlug]/[questSlug]/admin.vue create mode 100644 app/pages/hunt/[huntSlug]/admin.vue create mode 100644 prisma/migrations/20250809120120_add_more_review_options/migration.sql create mode 100644 prisma/migrations/20250809121824_remove_unique_urls_on_file/migration.sql create mode 100644 server/api/admin/answer/[answerId]/review.post.ts create mode 100644 server/api/admin/hunt/[huntId]/index.get.ts create mode 100644 server/api/admin/hunt/[huntId]/index.post.ts create mode 100644 server/api/admin/quest/[questId]/index.get.ts create mode 100644 server/utils/json.ts rename {server => shared}/auth.d.ts (100%) diff --git a/app/components/admin/Answer.vue b/app/components/admin/Answer.vue new file mode 100644 index 0000000..68f5dcf --- /dev/null +++ b/app/components/admin/Answer.vue @@ -0,0 +1,137 @@ + + + + + diff --git a/app/layouts/default.vue b/app/layouts/default.vue index 54a2017..c345013 100644 --- a/app/layouts/default.vue +++ b/app/layouts/default.vue @@ -9,10 +9,6 @@ const titleStore = useTitleStore(); const isSidebarVisible = ref(breakpoints.mdUp); -watchEffect(() => { - isSidebarVisible.value = breakpoints.smUp; -}); - const slugs = computed(() => checkSlug(route.params)); @@ -67,6 +63,21 @@ const slugs = computed(() => checkSlug(route.params)); }} + + + + Hunt Admin + + + + + Quest Admin + + checkSlug(route.params)); - + diff --git a/app/middleware/admin.ts b/app/middleware/admin.ts new file mode 100644 index 0000000..0fe62ad --- /dev/null +++ b/app/middleware/admin.ts @@ -0,0 +1,18 @@ +export default defineNuxtRouteMiddleware((to) => { + const { loggedIn, user } = useUserSession(); + + if (!loggedIn.value || !user.value || user.value?.role !== 'ADMIN') { + const split = to.path.endsWith('/') + ? to.path.substring(0, to.path.length - 1).split('/') + : to.path.split('/'); + + const localePath = useLocalePath(); + return navigateTo( + !user.value + ? localePath(`/login?to=${to.path}`) + : localePath( + split.length > 1 ? split.slice(0, split.length - 1).join('/') : '/' + ) + ); + } +}); diff --git a/app/pages/hunt/[huntSlug]/[questSlug]/admin.vue b/app/pages/hunt/[huntSlug]/[questSlug]/admin.vue new file mode 100644 index 0000000..753b8f0 --- /dev/null +++ b/app/pages/hunt/[huntSlug]/[questSlug]/admin.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/app/pages/hunt/[huntSlug]/[questSlug]/index.vue b/app/pages/hunt/[huntSlug]/[questSlug]/index.vue index d8b0df7..6882ea8 100644 --- a/app/pages/hunt/[huntSlug]/[questSlug]/index.vue +++ b/app/pages/hunt/[huntSlug]/[questSlug]/index.vue @@ -7,6 +7,8 @@ definePageMeta({ }); const app = useNuxtApp(); + +const { user } = useUserSession(); const { huntSlug, questSlug } = app.$slugData; const { t, locale } = useI18n(); @@ -86,6 +88,16 @@ const createImageURL = (file: File) => URL.createObjectURL(file); :loading="pending" color="success" >{{ $t('layouts.refresh') }} + Admin
@@ -131,7 +143,7 @@ const createImageURL = (file: File) => URL.createObjectURL(file);

{{ data.answer.review }}

- + Submission
diff --git a/app/pages/hunt/[huntSlug]/admin.vue b/app/pages/hunt/[huntSlug]/admin.vue new file mode 100644 index 0000000..ac8f306 --- /dev/null +++ b/app/pages/hunt/[huntSlug]/admin.vue @@ -0,0 +1,155 @@ + + + + + diff --git a/app/pages/hunt/[huntSlug]/index.vue b/app/pages/hunt/[huntSlug]/index.vue index 0b1787b..bca3c3d 100644 --- a/app/pages/hunt/[huntSlug]/index.vue +++ b/app/pages/hunt/[huntSlug]/index.vue @@ -43,7 +43,12 @@ async function invite() {