Lots of UI fixes
This commit is contained in:
parent
1f7a0f40c0
commit
e8e3b84276
24 changed files with 3652 additions and 1770 deletions
|
|
@ -1,14 +1,15 @@
|
|||
import Event from '../../../models/event';
|
||||
import Event from "../../../models/event";
|
||||
import { sendEventCancellationEmail } from "../../../utils/resend.js";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = getRouterParam(event, 'id');
|
||||
const id = getRouterParam(event, "id");
|
||||
const body = await readBody(event);
|
||||
const { email } = body;
|
||||
|
||||
if (!email) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Email is required'
|
||||
statusMessage: "Email is required",
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -24,22 +25,31 @@ export default defineEventHandler(async (event) => {
|
|||
if (!eventDoc) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Event not found'
|
||||
statusMessage: "Event not found",
|
||||
});
|
||||
}
|
||||
|
||||
// Find the registration index
|
||||
const registrationIndex = eventDoc.registrations.findIndex(
|
||||
registration => registration.email.toLowerCase() === email.toLowerCase()
|
||||
(registration) =>
|
||||
registration.email.toLowerCase() === email.toLowerCase(),
|
||||
);
|
||||
|
||||
if (registrationIndex === -1) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Registration not found'
|
||||
statusMessage: "Registration not found",
|
||||
});
|
||||
}
|
||||
|
||||
// Store registration data before removing (convert to plain object)
|
||||
const registration = {
|
||||
name: eventDoc.registrations[registrationIndex].name,
|
||||
email: eventDoc.registrations[registrationIndex].email,
|
||||
membershipLevel:
|
||||
eventDoc.registrations[registrationIndex].membershipLevel,
|
||||
};
|
||||
|
||||
// Remove the registration
|
||||
eventDoc.registrations.splice(registrationIndex, 1);
|
||||
|
||||
|
|
@ -48,13 +58,26 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
await eventDoc.save();
|
||||
|
||||
// Send cancellation confirmation email
|
||||
try {
|
||||
const eventData = {
|
||||
title: eventDoc.title,
|
||||
slug: eventDoc.slug,
|
||||
_id: eventDoc._id,
|
||||
};
|
||||
await sendEventCancellationEmail(registration, eventData);
|
||||
} catch (emailError) {
|
||||
// Log error but don't fail the cancellation
|
||||
console.error("Failed to send cancellation email:", emailError);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Registration cancelled successfully',
|
||||
registeredCount: eventDoc.registeredCount
|
||||
message: "Registration cancelled successfully",
|
||||
registeredCount: eventDoc.registeredCount,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error cancelling registration:', error);
|
||||
console.error("Error cancelling registration:", error);
|
||||
|
||||
// Re-throw known errors
|
||||
if (error.statusCode) {
|
||||
|
|
@ -63,7 +86,7 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to cancel registration'
|
||||
statusMessage: "Failed to cancel registration",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue