theming, date, time localisation, additional features, seeding initial cleanup
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getSession } from '@/lib/session';
|
||||
import { db } from '@/lib/db';
|
||||
import { bookings } from '@/lib/db/schema';
|
||||
import { bookings, settings } from '@/lib/db/schema';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { logActivity, ACTIONS, ENTITY_TYPES } from '@/lib/activity-logger';
|
||||
|
||||
@@ -28,15 +28,38 @@ export async function PATCH(request: NextRequest, { params }: { params: { id: st
|
||||
|
||||
const booking = existingBooking[0];
|
||||
|
||||
// Check if booking can be modified (more than 2 hours before start time)
|
||||
// Check if booking modifications are allowed
|
||||
const modificationSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'allow_booking_modifications'))
|
||||
.limit(1);
|
||||
|
||||
if (modificationSetting.length > 0 && modificationSetting[0].value !== 'true') {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking modifications are currently disabled by administrator' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Get the time restriction setting
|
||||
const timeSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'booking_modification_hours_before'))
|
||||
.limit(1);
|
||||
|
||||
const requiredHours = timeSetting.length > 0 ? parseFloat(timeSetting[0].value) : 2;
|
||||
|
||||
// Check if booking can be modified (more than required hours before start time)
|
||||
const bookingDateTime = new Date(`${booking.date}T${booking.startTime}`);
|
||||
const now = new Date();
|
||||
const timeDiff = bookingDateTime.getTime() - now.getTime();
|
||||
const hoursDiff = timeDiff / (1000 * 60 * 60);
|
||||
|
||||
if (hoursDiff <= 2) {
|
||||
if (hoursDiff <= requiredHours) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking can only be modified more than 2 hours before the session' },
|
||||
{ error: `Booking can only be modified more than ${requiredHours} hours before the session` },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -97,15 +120,38 @@ export async function DELETE(request: NextRequest, { params }: { params: { id: s
|
||||
|
||||
const booking = existingBooking[0];
|
||||
|
||||
// Check if booking can be cancelled (more than 2 hours before start time)
|
||||
// Check if booking modifications are allowed
|
||||
const modificationSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'allow_booking_modifications'))
|
||||
.limit(1);
|
||||
|
||||
if (modificationSetting.length > 0 && modificationSetting[0].value !== 'true') {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking modifications are currently disabled by administrator' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Get the time restriction setting
|
||||
const timeSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'booking_modification_hours_before'))
|
||||
.limit(1);
|
||||
|
||||
const requiredHours = timeSetting.length > 0 ? parseFloat(timeSetting[0].value) : 2;
|
||||
|
||||
// Check if booking can be cancelled (more than required hours before start time)
|
||||
const bookingDateTime = new Date(`${booking.date}T${booking.startTime}`);
|
||||
const now = new Date();
|
||||
const timeDiff = bookingDateTime.getTime() - now.getTime();
|
||||
const hoursDiff = timeDiff / (1000 * 60 * 60);
|
||||
|
||||
if (hoursDiff <= 2) {
|
||||
if (hoursDiff <= requiredHours) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking can only be cancelled more than 2 hours before the session' },
|
||||
{ error: `Booking can only be cancelled more than ${requiredHours} hours before the session` },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user