Add team creation, team join and debug login screen
This commit is contained in:
@@ -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 };
|
||||
});
|
||||
Reference in New Issue
Block a user