fixes, theming, branding

This commit is contained in:
mikicvi
2025-09-26 22:16:34 +01:00
parent 22c462c61c
commit 220f999f19
24 changed files with 787 additions and 260 deletions
+6 -4
View File
@@ -4,7 +4,7 @@ import { announcements } from '@/lib/db/schema';
import { eq } from 'drizzle-orm';
import { getSession } from '@/lib/session';
export async function PUT(request: NextRequest, { params }: { params: { id: string } }) {
export async function PUT(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session || session.role !== 'admin') {
@@ -12,7 +12,8 @@ export async function PUT(request: NextRequest, { params }: { params: { id: stri
}
const { title, content, priority, expiresAt, isActive } = await request.json();
const announcementId = params.id;
const { id } = await context.params;
const announcementId = id;
if (!title || !content) {
return NextResponse.json({ error: 'Title and content are required' }, { status: 400 });
@@ -49,14 +50,15 @@ export async function PUT(request: NextRequest, { params }: { params: { id: stri
}
}
export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {
export async function DELETE(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session || session.role !== 'admin') {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const announcementId = params.id;
const { id } = await context.params;
const announcementId = id;
// Check if announcement exists
const existing = await db.select().from(announcements).where(eq(announcements.id, announcementId)).limit(1);
+6 -4
View File
@@ -4,7 +4,7 @@ import { courts } from '@/lib/db/schema';
import { eq } from 'drizzle-orm';
import { getSession } from '@/lib/session';
export async function PUT(request: NextRequest, { params }: { params: { id: string } }) {
export async function PUT(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session || session.role !== 'admin') {
@@ -12,7 +12,8 @@ export async function PUT(request: NextRequest, { params }: { params: { id: stri
}
const { name, isActive } = await request.json();
const courtId = params.id;
const { id } = await context.params;
const courtId = id;
if (!name) {
return NextResponse.json({ error: 'Court name is required' }, { status: 400 });
@@ -46,14 +47,15 @@ export async function PUT(request: NextRequest, { params }: { params: { id: stri
}
}
export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {
export async function DELETE(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session || session.role !== 'admin') {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const courtId = params.id;
const { id } = await context.params;
const courtId = id;
// Check if court exists
const existing = await db.select().from(courts).where(eq(courts.id, courtId)).limit(1);
+4
View File
@@ -3,6 +3,7 @@ import { db } from '@/lib/db';
import { settings } from '@/lib/db/schema';
import { eq } from 'drizzle-orm';
import { getSession } from '@/lib/session';
import { invalidateAppConfigCache } from '@/lib/app-config';
export async function GET(request: NextRequest) {
try {
@@ -70,6 +71,9 @@ export async function PUT(request: NextRequest) {
await Promise.all(updatePromises);
// Invalidate app config cache since settings changed
invalidateAppConfigCache();
return NextResponse.json({ message: 'Settings updated successfully' });
} catch (error) {
console.error('Error updating settings:', error);
+6 -4
View File
@@ -5,7 +5,7 @@ import { eq } from 'drizzle-orm';
import { getSession } from '@/lib/session';
import bcrypt from 'bcryptjs';
export async function PUT(request: NextRequest, { params }: { params: { id: string } }) {
export async function PUT(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session || session.role !== 'admin') {
@@ -13,7 +13,8 @@ export async function PUT(request: NextRequest, { params }: { params: { id: stri
}
const { name, surname, email, role, password } = await request.json();
const userId = params.id;
const { id } = await context.params;
const userId = id;
if (!name || !surname || !email) {
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
@@ -58,14 +59,15 @@ export async function PUT(request: NextRequest, { params }: { params: { id: stri
}
}
export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {
export async function DELETE(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session || session.role !== 'admin') {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const userId = params.id;
const { id } = await context.params;
const userId = id;
// Prevent admin from deleting themselves
if (session.userId === userId) {
+6 -4
View File
@@ -5,7 +5,7 @@ import { bookings, settings } from '@/lib/db/schema';
import { eq, and } from 'drizzle-orm';
import { logActivity, ACTIONS, ENTITY_TYPES } from '@/lib/activity-logger';
export async function PATCH(request: NextRequest, { params }: { params: { id: string } }) {
export async function PATCH(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session) {
@@ -13,7 +13,8 @@ export async function PATCH(request: NextRequest, { params }: { params: { id: st
}
const { notes } = await request.json();
const bookingId = params.id;
const { id } = await context.params;
const bookingId = id;
// Check if booking exists and belongs to user
const existingBooking = await db
@@ -98,14 +99,15 @@ export async function PATCH(request: NextRequest, { params }: { params: { id: st
}
}
export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {
export async function DELETE(request: NextRequest, context: { params: Promise<{ id: string }> }) {
try {
const session = await getSession();
if (!session) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const bookingId = params.id;
const { id } = await context.params;
const bookingId = id;
// Check if booking exists and belongs to user
const existingBooking = await db
+6 -2
View File
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/db';
import { bookings, courts, timeSlots, settings, metrics } from '@/lib/db/schema';
import { eq, and } from 'drizzle-orm';
import { eq, and, gte, asc } from 'drizzle-orm';
import { getSession } from '@/lib/session';
import { logActivity, ACTIONS, ENTITY_TYPES } from '@/lib/activity-logger';
@@ -12,6 +12,9 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
// Get today's date to filter out past bookings
const today = new Date().toISOString().split('T')[0];
const userBookings = await db
.select({
id: bookings.id,
@@ -29,7 +32,8 @@ export async function GET(request: NextRequest) {
})
.from(bookings)
.innerJoin(courts, eq(bookings.courtId, courts.id))
.where(eq(bookings.userId, session.userId));
.where(and(eq(bookings.userId, session.userId), eq(bookings.status, 'active'), gte(bookings.date, today)))
.orderBy(asc(bookings.date), asc(bookings.startTime));
return NextResponse.json({ bookings: userBookings });
} catch (error) {
+12
View File
@@ -0,0 +1,12 @@
import { NextResponse } from 'next/server';
import { getAppConfig } from '@/lib/app-config';
export async function GET() {
try {
const config = await getAppConfig();
return NextResponse.json(config);
} catch (error) {
console.error('Error fetching app config:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}