This commit is contained in:
2025-12-25 23:49:47 -07:00
parent 13821cbcd5
commit 0d608cf3f4
26 changed files with 7 additions and 94 deletions

View File

@@ -11,7 +11,6 @@ import { eq, and, gte, lte, sql, desc } from 'drizzle-orm';
const user = Astro.locals.user;
if (!user) return Astro.redirect('/login');
// Get user's organization
const userMembership = await db.select()
.from(members)
.where(eq(members.userId, user.id))
@@ -19,7 +18,6 @@ const userMembership = await db.select()
if (!userMembership) return Astro.redirect('/dashboard');
// Get all team members
const teamMembers = await db.select({
id: users.id,
name: users.name,
@@ -30,26 +28,22 @@ const teamMembers = await db.select({
.where(eq(members.organizationId, userMembership.organizationId))
.all();
// Get all categories
const allCategories = await db.select()
.from(categories)
.where(eq(categories.organizationId, userMembership.organizationId))
.all();
// Get all clients
const allClients = await db.select()
.from(clients)
.where(eq(clients.organizationId, userMembership.organizationId))
.all();
// Parse filter parameters
const url = new URL(Astro.request.url);
const selectedMemberId = url.searchParams.get('member') || '';
const selectedCategoryId = url.searchParams.get('category') || '';
const selectedClientId = url.searchParams.get('client') || '';
const timeRange = url.searchParams.get('range') || 'week';
// Calculate date range
const now = new Date();
let startDate = new Date();
let endDate = new Date();
@@ -77,7 +71,6 @@ switch (timeRange) {
break;
}
// Build query conditions
const conditions = [
eq(timeEntries.organizationId, userMembership.organizationId),
gte(timeEntries.startTime, startDate),
@@ -96,7 +89,6 @@ if (selectedClientId) {
conditions.push(eq(timeEntries.clientId, selectedClientId));
}
// Fetch detailed entries
const entries = await db.select({
entry: timeEntries,
user: users,
@@ -111,7 +103,6 @@ const entries = await db.select({
.orderBy(desc(timeEntries.startTime))
.all();
// Calculate statistics by member
const statsByMember = teamMembers.map(member => {
const memberEntries = entries.filter(e => e.user.id === member.id);
const totalTime = memberEntries.reduce((sum, e) => {
@@ -128,7 +119,6 @@ const statsByMember = teamMembers.map(member => {
};
}).sort((a, b) => b.totalTime - a.totalTime);
// Calculate statistics by category
const statsByCategory = allCategories.map(category => {
const categoryEntries = entries.filter(e => e.category.id === category.id);
const totalTime = categoryEntries.reduce((sum, e) => {
@@ -145,7 +135,6 @@ const statsByCategory = allCategories.map(category => {
};
}).sort((a, b) => b.totalTime - a.totalTime);
// Calculate statistics by client
const statsByClient = allClients.map(client => {
const clientEntries = entries.filter(e => e.client.id === client.id);
const totalTime = clientEntries.reduce((sum, e) => {
@@ -162,7 +151,6 @@ const statsByClient = allClients.map(client => {
};
}).sort((a, b) => b.totalTime - a.totalTime);
// Calculate total time
const totalTime = entries.reduce((sum, e) => {
if (e.entry.endTime) {
return sum + (e.entry.endTime.getTime() - e.entry.startTime.getTime());