Add diashow and styling
This commit is contained in:
@@ -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';
|
||||
|
||||
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(
|
||||
event,
|
||||
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({
|
||||
where: {
|
||||
id: huntId
|
||||
// OR: [
|
||||
// {
|
||||
// creatorId: userId
|
||||
// },
|
||||
// {
|
||||
// members: {
|
||||
// some: {
|
||||
// memberId: userId
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
id: huntId,
|
||||
deletedAt: null,
|
||||
OR: [
|
||||
{
|
||||
revealAnswers: true,
|
||||
revealQuests: true
|
||||
},
|
||||
{
|
||||
creatorId: userId
|
||||
},
|
||||
{
|
||||
members: {
|
||||
some: {
|
||||
memberId: userId
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -163,7 +174,10 @@ export default defineEventHandler(async (event) => {
|
||||
});
|
||||
|
||||
if (!_hunt) {
|
||||
throw createError({ status: 404, statusText: 'Not found!' });
|
||||
throw createError({
|
||||
status: 403,
|
||||
statusText: 'Answers are not revealed yet!'
|
||||
});
|
||||
}
|
||||
|
||||
const { teams, ...hunt } = _hunt;
|
||||
Reference in New Issue
Block a user