Adding features
This commit is contained in:
parent
600fef2b7c
commit
2b55ca4104
75 changed files with 9796 additions and 2759 deletions
49
server/api/events/[id]/check-registration.post.js
Normal file
49
server/api/events/[id]/check-registration.post.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import Event from "../../../models/event";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = getRouterParam(event, "id");
|
||||
const body = await readBody(event);
|
||||
const { email } = body;
|
||||
|
||||
if (!email) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Email is required",
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if id is a valid ObjectId or treat as slug
|
||||
const isObjectId = /^[0-9a-fA-F]{24}$/.test(id);
|
||||
const query = isObjectId
|
||||
? { $or: [{ _id: id }, { slug: id }] }
|
||||
: { slug: id };
|
||||
|
||||
const eventDoc = await Event.findOne(query);
|
||||
|
||||
if (!eventDoc) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Event not found",
|
||||
});
|
||||
}
|
||||
|
||||
// Check if the email exists in the registrations array
|
||||
const isRegistered = eventDoc.registrations.some(
|
||||
(registration) =>
|
||||
registration.email.toLowerCase() === email.toLowerCase(),
|
||||
);
|
||||
|
||||
return {
|
||||
isRegistered,
|
||||
eventId: eventDoc._id,
|
||||
eventTitle: eventDoc.title,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error checking registration:", error);
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "Failed to check registration status",
|
||||
});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue