- 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
74 lines
1.4 KiB
TypeScript
74 lines
1.4 KiB
TypeScript
import { useValidatedParams, z, zh } from 'h3-zod';
|
|
import prisma from '~~/lib/prisma';
|
|
import { sendJson } from '~~/server/utils/json';
|
|
|
|
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 hunt = await prisma.hunt.findUnique({
|
|
where: {
|
|
id: huntId,
|
|
members: {
|
|
some: {
|
|
memberId: userId
|
|
}
|
|
}
|
|
},
|
|
select: {
|
|
id: true,
|
|
name_de: true,
|
|
name_en: true,
|
|
description_de: true,
|
|
description_en: true,
|
|
virtual: true,
|
|
public: true,
|
|
start: true,
|
|
end: true,
|
|
allowJoin: true,
|
|
revealQuests: true,
|
|
revealAnswers: true,
|
|
updatedAt: true,
|
|
picture: {
|
|
select: {
|
|
id: true,
|
|
url: true
|
|
}
|
|
},
|
|
creator: {
|
|
select: {
|
|
name: true,
|
|
id: true,
|
|
email: true
|
|
}
|
|
},
|
|
members: {
|
|
select: {
|
|
member: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
email: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
if (!hunt) {
|
|
throw createError({ status: 404, statusText: 'Not found!' });
|
|
}
|
|
|
|
setHeader(event, 'Content-Type', 'application/json');
|
|
|
|
return sendJson(hunt);
|
|
});
|