Add pic upload for hunt admins

This commit is contained in:
2025-09-11 23:18:02 +02:00
parent 5d4e802796
commit 3e1bfa46d9
6 changed files with 242 additions and 2 deletions
@@ -0,0 +1,55 @@
import { useValidatedParams, z, zh } from 'h3-zod';
import prisma from '~~/lib/prisma';
export default defineEventHandler(async (event) => {
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({
huntId: zh.numAsString
})
);
const hunt = await prisma.hunt.findUnique({
where: {
id: huntId,
OR: [
{
creatorId: userId
},
{
members: {
some: {
memberId: userId
}
}
}
]
},
select: {
id: true
}
});
if (!hunt) {
throw createError({ status: 404, statusText: 'Not found!' });
}
await prisma.hunt.update({
where: {
id: huntId
},
data: {
pictureId: null
}
});
return {success: true};
});