Many an update!
This commit is contained in:
parent
85195d6c7a
commit
d588c49946
35 changed files with 3528 additions and 1142 deletions
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue