feat(team): add team settings with edit, leave, and kick functionality

This commit is contained in:
2026-07-31 01:48:31 +02:00
parent e664cf3b96
commit de0eaee521
10 changed files with 579 additions and 9 deletions
@@ -0,0 +1,60 @@
import { useValidatedBody, 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, teamId } = await useValidatedParams(
event,
z.object({
huntId: zh.numAsString,
teamId: zh.numAsString
})
);
const { userId: memberId } = await useValidatedBody(
event,
z.object({
userId: z.int().gt(0)
})
);
// Only the team owner may remove members
const team = await prisma.huntTeam.findFirst({
where: {
id: teamId,
huntId,
ownerId: userId
},
select: {
id: true
}
});
if (!team) {
throw createError({ status: 403, statusText: 'Not allowed!' });
}
if (memberId === userId) {
throw createError({
status: 400,
statusText: 'Owner cannot kick themselves!'
});
}
try {
await prisma.teamMember.delete({
where: {
memberId_teamId: {
memberId,
teamId
}
}
});
} catch (e) {
throw createError({ status: 404, statusText: 'Not found!', cause: e });
}
return { success: true };
});