Update license year, enhance user management with last booking date, and improve admin dashboard navigation

This commit is contained in:
mikicvi
2025-10-06 11:18:55 +01:00
parent 7fdd7285a4
commit 69b456f3f8
4 changed files with 202 additions and 53 deletions
+7 -3
View File
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/db';
import { users } from '@/lib/db/schema';
import { eq } from 'drizzle-orm';
import { users, bookings } from '@/lib/db/schema';
import { eq, desc, max, sql, and } from 'drizzle-orm';
import { getSession } from '@/lib/session';
import bcrypt from 'bcryptjs';
@@ -12,6 +12,7 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
// Get all users with their last booking date using LEFT JOIN and GROUP BY
const allUsers = await db
.select({
id: users.id,
@@ -20,8 +21,11 @@ export async function GET(request: NextRequest) {
email: users.email,
role: users.role,
createdAt: users.createdAt,
lastBookingDate: max(bookings.date),
})
.from(users);
.from(users)
.leftJoin(bookings, and(eq(bookings.userId, users.id), eq(bookings.status, 'active')))
.groupBy(users.id, users.name, users.surname, users.email, users.role, users.createdAt);
return NextResponse.json({ users: allUsers });
} catch (error) {