Add team creation, team join and debug login screen

This commit is contained in:
2025-08-03 18:58:17 +02:00
parent facb07de5b
commit 36e8ef41bf
15 changed files with 735 additions and 11 deletions
+71
View File
@@ -0,0 +1,71 @@
import { requireUserSession } from '#imports';
import { useValidatedBody, useValidatedParams, z, zh } from 'h3-zod';
import prisma from '~~/lib/prisma';
export default defineEventHandler(async (event) => {
const { huntId } = await useValidatedParams(
event,
z.object({
huntId: zh.numAsString
})
);
const user = await requireUserSession(event);
const userId = user.user.id;
const existingTeam = await prisma.huntTeam.findFirst({
select: {
id: true
},
where: {
huntId,
OR: [
{
ownerId: userId
},
{
members: {
some: {
memberId: userId
}
}
}
]
}
});
if (existingTeam) {
throw createError({ status: 409, statusText: 'You already have a team!' });
}
const { team: teamId, password } = await useValidatedBody(
event,
z.object({
team: z.number().min(1),
password: z.string().max(256)
})
);
const team = await prisma.huntTeam.findUnique({
where: {
huntId,
id: teamId,
password
},
select: { id: true }
});
if (!team) {
throw createError({
status: 404,
statusText: 'Team not found or invalid password!'
});
}
await prisma.teamMember.create({
data: {
memberId: userId,
teamId
}
});
return { success: true };
});