Many an update!

This commit is contained in:
Jennie Robinson Faber 2025-12-01 15:26:42 +00:00
parent 85195d6c7a
commit d588c49946
35 changed files with 3528 additions and 1142 deletions

View file

@ -1,5 +1,8 @@
import Event from "../../../models/event";
import { sendEventCancellationEmail } from "../../../utils/resend.js";
import {
sendEventCancellationEmail,
sendWaitlistNotificationEmail,
} from "../../../utils/resend.js";
export default defineEventHandler(async (event) => {
const id = getRouterParam(event, "id");
@ -71,6 +74,39 @@ export default defineEventHandler(async (event) => {
console.error("Failed to send cancellation email:", emailError);
}
// Notify waitlisted users if waitlist is enabled and there are entries
if (
eventDoc.tickets?.waitlist?.enabled &&
eventDoc.tickets.waitlist.entries?.length > 0
) {
try {
const eventData = {
title: eventDoc.title,
slug: eventDoc.slug,
_id: eventDoc._id,
startDate: eventDoc.startDate,
endDate: eventDoc.endDate,
location: eventDoc.location,
};
// Notify the first person on the waitlist who hasn't been notified yet
const waitlistEntry = eventDoc.tickets.waitlist.entries.find(
(entry) => !entry.notified
);
if (waitlistEntry) {
await sendWaitlistNotificationEmail(waitlistEntry, eventData);
// Mark as notified
waitlistEntry.notified = true;
await eventDoc.save();
}
} catch (waitlistError) {
// Log error but don't fail the cancellation
console.error("Failed to notify waitlist:", waitlistError);
}
}
return {
success: true,
message: "Registration cancelled successfully",