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
+95
View File
@@ -0,0 +1,95 @@
import prisma from '~~/lib/prisma';
async function getOwnHunts(userId: number | undefined) {
if (!userId) {
return null;
}
return prisma.hunt.findMany({
select: {
id: true,
name: true,
description: true,
createdAt: true,
start: true,
end: true,
_count: {
select: {
teams: true,
quests: true
}
},
creator: {
select: {
name: true,
id: true
}
}
},
where: {
deletedAt: null,
teams: {
some: {
OR: [
{
ownerId: userId
},
{
members: {
some: {
memberId: userId
}
}
}
]
}
}
}
});
}
export default defineEventHandler(async (event) => {
const user = await getUserSession(event);
const userId = user.user?.id;
const own = await getOwnHunts(userId);
const others = await prisma.hunt.findMany({
select: {
id: true,
name: true,
description: true,
createdAt: true,
start: true,
end: true,
_count: {
select: {
teams: true,
quests: true
}
},
creator: {
select: {
name: true,
id: true
}
}
},
where: {
deletedAt: null,
OR: [
{
start: {
gt: new Date()
}
},
{
start: null
}
],
allowJoin: true,
id: {
notIn: own?.map((h) => h.id) ?? []
}
}
});
return { own, others };
});