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,57 @@
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 body = await useValidatedBody(
event,
z.object({
name: z.string().min(3).max(256).trim(),
description: z.string().max(256).trim().default(''),
password: z.string().min(1).max(256).trim()
})
);
// Only the team owner may edit the team
const team = await prisma.huntTeam.findFirst({
where: {
id: teamId,
huntId,
ownerId: userId
},
select: {
id: true
}
});
if (!team) {
throw createError({ status: 403, statusText: 'Not allowed!' });
}
return await prisma.huntTeam.update({
where: {
id: teamId
},
data: {
name: body.name,
description: body.description,
password: body.password
},
select: {
id: true,
name: true,
description: true,
password: true
}
});
});