- Remove explicit ADMIN role checks in API handlers - Replace combined creator/member role checks with membership-only filters - Update seed data roles to reflect changed authorization logic - Add migration to insert hunt creators as members for consistent checks - Prevent removal of hunt creator as a member with new explicit check - Adjust related user role updates and queries accordingly - Upgrade dependencies including nuxt and zod for compatibility
43 lines
771 B
TypeScript
43 lines
771 B
TypeScript
import { useValidatedParams, z, zh } from 'h3-zod';
|
|
import prisma from '~~/lib/prisma';
|
|
|
|
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
|
|
}
|
|
});
|
|
if (!hunt) {
|
|
throw createError({ status: 404, statusText: 'Not found!' });
|
|
}
|
|
|
|
await prisma.hunt.update({
|
|
where: {
|
|
id: huntId
|
|
},
|
|
data: {
|
|
pictureId: null
|
|
}
|
|
});
|
|
|
|
return { success: true };
|
|
});
|