eve2ntme65nt
Version:
EventManagementApp is a comprehensive solution for planning events.
134 lines (107 loc) • 4.1 kB
JavaScript
class EventManagementApp {
constructor() {
this.events = [];
this.attendees = [];
this.emailQueue = [];
}
createEvent(eventDetails) {
// Create a new event with the provided details
const newEvent = {
id: this.generateUniqueId(),
details: eventDetails,
attendees: [],
registrationDeadline: new Date(eventDetails.date).setHours(12, 0, 0, 0), // Set registration deadline to noon on event date
status: 'Pending', // Initial status of the event
ticketSales: 0, // Initial ticket sales count
revenue: 0, // Initial revenue generated
};
this.events.push(newEvent);
return newEvent.id;
}
registerAttendee(eventId, attendeeDetails) {
// Find the event with the given ID
const event = this.events.find((event) => event.id === eventId);
if (event && new Date() < event.registrationDeadline) {
// Create a new attendee with the provided details
const newAttendee = {
id: this.generateUniqueId(),
details: attendeeDetails,
registrationDate: new Date(),
};
event.attendees.push(newAttendee);
this.attendees.push(newAttendee);
// Update ticket sales count and revenue
event.ticketSales++;
event.revenue += event.details.ticketPrice;
// Check if event is close to capacity
if (event.ticketSales >= event.details.capacity * 0.9) {
this.emailQueue.push({
eventId: event.id,
subject: 'Event Capacity Alert',
body: `Dear Event Organizer,\n\nThe event ${event.details.name} is close to reaching its maximum capacity. Please take necessary actions.\n\nBest regards,\nEvent Management System`,
});
}
return newAttendee.id;
}
return null;
}
promoteEvent(eventId) {
// Find the event with the given ID
const event = this.events.find((event) => event.id === eventId);
if (event && event.status !== 'Promoted') {
// Promote the event by updating its status and sending promotional emails
event.status = 'Promoted';
// Send promotional emails to attendees
event.attendees.forEach((attendee) => {
this.sendEmail(attendee.details.email, 'Event Promotion', `Dear ${attendee.details.name},\n\nWe are pleased to inform you that the ${event.details.name} has been promoted. Don't miss out on this exciting event!\n\nBest regards,\nEvent Management Team`);
});
return true;
}
return false;
}
manageAttendees(eventId) {
// Find the event with the given ID
const event = this.events.find((event) => event.id === eventId);
if (event) {
// Return the list of attendees for the event
return event.attendees;
}
return [];
}
generateUniqueId() {
// Generate a unique ID for events and attendees
return Math.random().toString(36).substr(2, 9);
}
sendEmail(email, subject, body) {
// Simulate sending email (can be replaced with actual email sending code)
console.log(`Sending email to ${email}: Subject - ${subject}\nBody - ${body}`);
}
processEmailQueue() {
// Process the email queue and send pending emails
while (this.emailQueue.length > 0) {
const email = this.emailQueue.shift();
this.sendEmail('admin@example.com', email.subject, email.body);
}
}
}
// Example usage
const app = new EventManagementApp();
const eventId = app.createEvent({
name: 'Music Festival',
date: '2024-07-15',
location: 'City Park',
capacity: 1000, // Maximum capacity of the event
ticketPrice: 50, // Ticket price in USD
});
const attendeeId = app.registerAttendee(eventId, {
name: 'John Doe',
email: 'johndoe@example.com',
age: 30,
occupation: 'Software Engineer',
});
app.promoteEvent(eventId);
app.processEmailQueue();
const attendees = app.manageAttendees(eventId);
console.log('Event ID:', eventId);
console.log('Attendee ID:', attendeeId);
console.log('Attendees:', attendees);