Compare commits

...

2 Commits

Author SHA1 Message Date
Levente Orban
1b79e6da58 fix: validating capacity limit when users add guests 2025-11-03 09:04:01 +01:00
Levente Orban
8cde1d44eb fix: error when editing the events, location_type 2025-10-29 10:15:12 +01:00
2 changed files with 10 additions and 8 deletions

View File

@@ -104,14 +104,15 @@ export const actions: Actions = {
// Get current RSVPs // Get current RSVPs
const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId)); const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));
// Calculate total attendees (including guests) // Calculate remaining spots and ensure main attendee + guests fit
const totalAttendees = currentRSVPs.length + numberOfGuests; const newAttendeesCount = 1 + numberOfGuests;
const remainingSpots = (eventData.attendeeLimit ?? 0) - currentRSVPs.length;
// Check if event is full (for limited type events) // Check if event is full (for limited type events)
if (eventData.type === 'limited' && eventData.attendeeLimit) { if (eventData.type === 'limited' && eventData.attendeeLimit) {
if (totalAttendees > eventData.attendeeLimit) { if (newAttendeesCount > remainingSpots) {
return fail(400, { return fail(400, {
error: `Event capacity exceeded. You're trying to add ${numberOfGuests + 1} attendees (including yourself), but only ${eventData.attendeeLimit - currentRSVPs.length} spots remain.` error: `Event capacity exceeded. You're trying to add ${newAttendeesCount} attendee${newAttendeesCount === 1 ? '' : 's'} (including yourself), but only ${remainingSpots} spot${remainingSpots === 1 ? '' : 's'} remain.`
}); });
} }
} }

View File

@@ -129,14 +129,15 @@ export const actions: Actions = {
// Get current RSVPs // Get current RSVPs
const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId)); const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));
// Calculate total attendees (including guests) // Calculate remaining spots and ensure main attendee + guests fit
const totalAttendees = currentRSVPs.length + numberOfGuests; const newAttendeesCount = 1 + numberOfGuests;
const remainingSpots = (eventData.attendeeLimit ?? 0) - currentRSVPs.length;
// Check if event is full (for limited type events) // Check if event is full (for limited type events)
if (eventData.type === 'limited' && eventData.attendeeLimit) { if (eventData.type === 'limited' && eventData.attendeeLimit) {
if (totalAttendees > eventData.attendeeLimit) { if (newAttendeesCount > remainingSpots) {
return fail(400, { return fail(400, {
error: `Event capacity exceeded. You're trying to add ${numberOfGuests + 1} attendees (including yourself), but only ${eventData.attendeeLimit - currentRSVPs.length} spots remain.` error: `Event capacity exceeded. You're trying to add ${newAttendeesCount} attendee${newAttendeesCount === 1 ? '' : 's'} (including yourself), but only ${remainingSpots} spot${remainingSpots === 1 ? '' : 's'} remain.`
}); });
} }
} }