feat: implement team management features including team creation, member addition, and deletion
- Added a new page for managing teams with functionalities to create teams, add members, and delete teams. - Enhanced the matches page with improved match creation form and live match display. - Refactored state handling for match states and improved UI for displaying match information.
This commit is contained in:
@@ -1,52 +1,42 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { match, playerRating, matchQueue } from '$lib/server/db/schema';
|
||||
import { eq, desc, sql } from 'drizzle-orm';
|
||||
import { match, team, mappool } from '$lib/server/db/schema';
|
||||
import { eq, desc, count, and, inArray } from 'drizzle-orm';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ locals }) => {
|
||||
if (!locals.user) {
|
||||
return { user: null, rating: null, queueStatus: null, recentMatches: [], poolCount: 0 };
|
||||
}
|
||||
|
||||
const rating = await db.query.playerRating.findFirst({
|
||||
where: eq(playerRating.userId, locals.user.id)
|
||||
});
|
||||
|
||||
const queueEntry = await db.query.matchQueue.findFirst({
|
||||
where: eq(matchQueue.userId, locals.user.id)
|
||||
});
|
||||
|
||||
const queueCount = await db
|
||||
.select({ count: sql<number>`count(*)` })
|
||||
.from(matchQueue);
|
||||
|
||||
const poolCount = await db
|
||||
.select({ count: sql<number>`count(*)` })
|
||||
.from(db._.fullSchema.mappool);
|
||||
if (!locals.user) redirect(302, '/');
|
||||
|
||||
// Recent matches (last 5)
|
||||
const recentMatches = await db.query.match.findMany({
|
||||
with: {
|
||||
participants: {
|
||||
with: { team: true, players: true }
|
||||
}
|
||||
},
|
||||
with: { participants: { with: { team: true } } },
|
||||
orderBy: desc(match.createdAt),
|
||||
limit: 10
|
||||
limit: 5
|
||||
});
|
||||
|
||||
const userMatches = recentMatches.filter((m) =>
|
||||
m.participants.some((p) => p.players.some((pl) => pl.userId === locals.user!.id))
|
||||
);
|
||||
// Live matches
|
||||
const liveMatches = await db.query.match.findMany({
|
||||
with: { participants: { with: { team: true } } },
|
||||
where: inArray(match.state, ['LOBBY', 'ROLLING', 'PICKING', 'PLAYING'])
|
||||
});
|
||||
|
||||
// Counts
|
||||
const [matchCount] = await db.select({ count: count() }).from(match);
|
||||
const [teamCount] = await db.select({ count: count() }).from(team);
|
||||
const [poolCount] = await db.select({ count: count() }).from(mappool);
|
||||
const [finishedCount] = await db
|
||||
.select({ count: count() })
|
||||
.from(match)
|
||||
.where(eq(match.state, 'FINISHED'));
|
||||
|
||||
return {
|
||||
user: locals.user,
|
||||
rating: rating ?? { elo: 1000, wins: 0, losses: 0 },
|
||||
queueStatus: {
|
||||
inQueue: !!queueEntry,
|
||||
queueSize: Number(queueCount[0].count),
|
||||
joinedAt: queueEntry?.joinedAt ?? null
|
||||
},
|
||||
recentMatches: userMatches,
|
||||
poolCount: Number(poolCount[0].count)
|
||||
recentMatches,
|
||||
liveMatches,
|
||||
stats: {
|
||||
matches: matchCount.count,
|
||||
finished: finishedCount.count,
|
||||
teams: teamCount.count,
|
||||
mappools: poolCount.count
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user