Project Introduction
The Event Management System is a comprehensive web application designed to facilitate the planning, organization, and management of events. Built using Node.js, this platform allows event organizers to create and manage events, while attendees can register, purchase tickets, and provide feedback. The system supports multiple user roles, including admin, organizer, attendee, and vendor, ensuring a tailored experience for each user type. The underlying MySQL database schema is structured to manage users, events, tickets, registrations, agendas, feedback, notifications, and vendors, providing a robust foundation for effective event management.
Project Objectives
- To develop a user-friendly interface for organizers to create and manage events.
- To implement a secure user authentication system with role-based access control.
- To facilitate ticket sales and manage ticket availability for events.
- To enable attendees to register for events and track their registrations.
- To provide a feedback mechanism for attendees to rate events and provide comments.
- To manage event agendas, including session titles, speakers, and timings.
- To implement a notification system to keep users informed about important updates and reminders.
- To ensure the application is scalable and maintainable for future enhancements.
Project Modules
- User Management Module:
This module handles user registration, authentication, and role management, allowing users to manage their accounts based on their designated roles.
- Event Management Module:
This module allows organizers to create, update, and manage events, including details such as event name, date, location, and description.
- Ticket Management Module:
This module manages ticket types, pricing, and availability for each event, enabling attendees to purchase tickets.
- Registration Management Module:
This module tracks attendee registrations for events, including payment statuses and ticket assignments.
- Agenda Management Module:
This module allows organizers to create and manage event agendas, including session details and speaker information.
- Feedback Management Module:
This module enables attendees to provide feedback on events, including ratings and comments.
- Notification Module:
This module sends notifications to users regarding important updates, event reminders, and announcements.
- Vendor Management Module:
This module manages vendor information, including contact details and service types offered for events.
Steps Overview
Set Up the Project: Initialize a new Node.js project and install the required packages.
Configure Sequelize: Set up Sequelize to connect to your database and define models based on the provided schema.
Create Repositories: Implement repository patterns for data access.
Create Controllers: Implement controllers to handle business logic.
Set Up Routes: Define routes for the application.
Create Views: Use EJS to create views for the application with Bootstrap 5 for styling.
Implement CRUD Operations: Implement the CRUD operations for the Users, Roles, Events, Venues, Registrations, Tickets, Notifications, Vendors, MarketingCampaigns, Feedbacks, AttendanceReports, FinancialReports, and PerformanceMetrics tables.
Step 1: Set Up the Project
mkdir event-management-app
cd event-management-app
npm init -y
npm install express sequelize mysql2 ejs body-parser
Step 2: Configure Sequelize
Create a config folder and a database.js file to configure Sequelize.
// config/database.js
const { Sequelize } = require('sequelize');
const sequelize = new Sequelize('database_name', 'username', 'password', {
host: 'localhost',
dialect: 'mysql',
});
module.exports = sequelize;
Step 3: Define Models
Create a models folder and define the models based on the provided schema.
1. User Model: models/User.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const User = sequelize.define('User ', {
UserId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
Username: {
type: DataTypes.STRING(50),
allowNull: false,
unique: true,
},
PasswordHash: {
type: DataTypes.STRING(256),
allowNull: false,
},
Email: {
type: DataTypes.STRING(100),
allowNull: false,
unique: true,
},
Phone: {
type: DataTypes.STRING(15),
},
RoleId: {
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = User;
2. Role Model: models/Role.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Role = sequelize.define('Role', {
RoleId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
RoleName: {
type: DataTypes.STRING(50),
allowNull: false,
unique: true,
},
}, {
timestamps: false,
});
module.exports = Role;
3. Event Model: models/Event.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Event = sequelize.define('Event', {
EventId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventName: {
type: DataTypes.STRING(100),
allowNull: false,
},
Description: {
type: DataTypes.TEXT,
allowNull: false,
},
StartDate: {
type: DataTypes.DATE,
allowNull: false,
},
EndDate: {
type: DataTypes.DATE,
allowNull: false,
},
VenueId: {
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = Event;
4. Venue Model: models/Venue.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Venue = sequelize.define('Venue', {
VenueId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
VenueName: {
type: DataTypes.STRING(100),
allowNull: false,
},
Address: {
type: DataTypes.STRING(255),
allowNull: false,
},
Capacity: {
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = Venue;
5. Registration Model: models/Registration.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Registration = sequelize.define('Registration', {
RegistrationId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
UserId: {
type: DataTypes.INTEGER,
},
EventId: {
type: DataTypes.INTEGER,
},
RegistrationDate: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
},
Status: {
type: DataTypes.STRING(20),
defaultValue: 'Registered',
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Registration;
6. Ticket Model: models/Ticket.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Ticket = sequelize.define('Ticket', {
TicketId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
RegistrationId: {
type: DataTypes.INTEGER,
},
TicketType: {
type: DataTypes.STRING(50),
},
Price: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Ticket;
7. Notification Model: models/Notification.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Notification = sequelize.define('Notification', {
NotificationId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
UserId: {
type: DataTypes.INTEGER,
},
Message: {
type: DataTypes.TEXT,
},
IsRead: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Notification;
8. Vendor Model: models/Vendor.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Vendor = sequelize.define('Vendor', {
VendorId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
VendorName: {
type: DataTypes.STRING(100),
allowNull: false,
},
ContactPerson: {
type: DataTypes.STRING(100),
},
Phone: {
type: DataTypes.STRING(15),
},
Email: {
type: DataTypes.STRING(100),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = Vendor;
9. MarketingCampaign Model: models/MarketingCampaign.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const MarketingCampaign = sequelize.define('MarketingCampaign', {
CampaignId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
CampaignName: {
type: DataTypes.STRING(100),
allowNull: false,
},
StartDate: {
type: DataTypes.DATE,
},
EndDate: {
type: DataTypes.DATE,
},
Budget: {
type: DataTypes.DECIMAL(10, 2),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = MarketingCampaign;
10. Feedback Model: models/Feedback.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Feedback = sequelize.define('Feedback', {
FeedbackId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
UserId: {
type: DataTypes.INTEGER,
},
EventId: {
type: DataTypes.INTEGER,
},
Comments: {
type: DataTypes.TEXT,
},
Rating: {
type: DataTypes.INTEGER,
validate: {
min: 1,
max: 5,
},
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Feedback;
11. AttendanceReport Model: models/AttendanceReport.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const AttendanceReport = sequelize.define('AttendanceReport', {
ReportId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventId: {
type: DataTypes.INTEGER,
},
TotalAttendees: {
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = AttendanceReport;
12. FinancialReport Model: models/FinancialReport.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const FinancialReport = sequelize.define('FinancialReport', {
FinancialReportId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventId: {
type: DataTypes.INTEGER,
},
TotalRevenue: {
type: DataTypes.DECIMAL(10, 2),
},
TotalExpenses: {
type: DataTypes.DECIMAL(10, 2),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = FinancialReport;
13. PerformanceMetric Model: models/PerformanceMetric.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const PerformanceMetric = sequelize.define('PerformanceMetric', {
MetricId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventId: {
type: DataTypes.INTEGER,
},
MetricName: {
type: DataTypes.STRING(100),
},
MetricValue: {
type: DataTypes.DECIMAL(10, 2),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = PerformanceMetric;
Step 4: Create Repositories
Create a repositories folder and implement repository patterns for data access. For example, create a User Repository.js.
// repositories/UserRepository.js
const User = require('../models/User');
class UserRepository {
async createUser (userData) {
return await User.create(userData);
}
async getAllUsers() {
return await User.findAll();
}
async get User ById(userId) {
return await User.findByPk(userId);
}
async updateUser (userId, userData) {
const user = await this.getUser ById(userId);
if (user) {
return await user.update(userData);
}
return null;
}
async deleteUser (userId) {
const user = await this.getUser ById(userId);
if (user) {
await user.destroy();
return true;
}
return false;
}
}
module.exports = new UserRepository();
Step 5: Create Controllers
Create a controllers folder and implement controllers to handle business logic. For example, create a User Controller.js.
// controllers/UserController.js
const UserRepository = require('../repositories/UserRepository');
class UserController {
async createUser (req, res) {
try {
const user = await UserRepository.createUser (req.body);
res.redirect('/users');
} catch (error) {
console.error("Error creating user:", error);
res.status(500).send("Internal Server Error");
}
}
async getAllUsers(req, res) {
try {
const users = await UserRepository.getAllUsers();
res.render('users/index', { users });
} catch (error) {
console.error("Error fetching users:", error);
res.status(500).send("Internal Server Error");
}
}
async getUser ById(req, res) {
try {
const user = await UserRepository.getUser ById(req.params.id);
if (user) {
res.render('users/edit', { user });
} else {
res.status(404).send("User not found");
}
} catch (error) {
console.error("Error fetching user:", error);
res.status(500).send("Internal Server Error");
}
}
async updateUser (req, res) {
try {
const updatedUser = await UserRepository.updateUser (req.params.id, req.body);
if (updatedUser ) {
res.redirect('/users');
} else {
res.status(404).send("User not found");
}
} catch (error) {
console.error("Error updating user:", error);
res.status(500).send("Internal Server Error");
}
}
async deleteUser (req, res) {
try {
const deleted = await UserRepository.deleteUser (req.params.id);
if (deleted) {
res.redirect('/users');
} else {
res.status(404).send("User not found");
}
} catch (error) {
console.error("Error deleting user:", error);
res.status(500).send("Internal Server Error");
}
}
}
module.exports = new UserController();
Step 6: Set Up Routes
Create a routes folder and define routes for the application. For example, create a userRoutes.js.
// routes/userRoutes.js
const express = require('express');
const router = express.Router();
const UserController = require('../controllers/UserController');
router.get('/', UserController.getAllUsers);
router.get('/create', (req, res) => res.render('users/create'));
router.post('/', UserController.createUser );
router.get('/:id', UserController.getUser ById);
router.post('/:id', UserController.updateUser );
router.delete('/:id', UserController.deleteUser );
module.exports = router;
Step 7: Create Views
Create a views folder and set up EJS views for the application with Bootstrap 5 for styling. For example, create a users/index.ejs.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Users</title>
</head>
<body>
<div class="container">
<h1>Users</h1>
<a href="/users/create" class="btn btn-primary">Create User</a>
<table class="table">
<thead>
<tr>
<th>UserId</th>
<th>Username</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% users.forEach(user => { %>
<tr>
<td><%= user.UserId %></td>
<td><%= user.Username %></td>
<td><%= user.Email %></td>
<td>
<a href="/users/<%= user.UserId %>" class="btn btn-warning ">Edit</a>
<form action="/users/<%= user.UserId %>?_method=DELETE" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
Step 8: Create Create User View
Create a view for creating a new user, views/users/create.ejs.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create User</title>
</head>
<body>
<div class="container">
<h1>Create User</h1>
<form action="/users" method="POST">
<div class="mb-3">
<label for="Username" class="form-label">Username</label>
<input type="text" class="form-control" id="Username" name="Username" required>
</div>
<div class="mb-3">
<label for="PasswordHash" class="form-label">Password</label>
<input type="password" class="form-control" id="PasswordHash" name="PasswordHash" required>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type="email" class="form-control" id="Email" name="Email" required>
</div>
<div class="mb-3">
<label for="Phone" class="form-label">Phone</label>
<input type="text" class="form-control" id="Phone" name="Phone">
</div>
<button type="submit" class="btn btn-primary">Create User</button>
</form>
</div>
</body>
</html>
Step 9: Integrate All Routes in the Main Application
In your main application file (e.g., app.js), integrate the user routes and set up the server.
// app.js
const express = require('express');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
const sequelize = require('./config/database');
const userRoutes = require('./routes/userRoutes');
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('_method'));
app.use(express.static('public'));
app.use('/users', userRoutes);
const PORT = process.env.PORT || 3000;
sequelize.sync().then(() => {
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
});
With these steps, you have created a complete CRUD application for managing users in an event management system using Node.js, Sequelize, Express, EJS, and Bootstrap 5. You can replicate similar steps for other entities like Roles, Events, Venues, Registrations, Tickets, Notifications, Vendors, MarketingCampaigns, Feedbacks, AttendanceReports, FinancialReports, and PerformanceMetrics by creating corresponding models, repositories, controllers, routes, and views.
Further Implementation for Remaining Models
Following are the complete implementation for the remaining models based on your SQL schema: Events, Venues, Registrations, Tickets, Notifications, Vendors, MarketingCampaigns, Feedbacks, AttendanceReports, FinancialReports, and PerformanceMetrics. Each model will include the following:
1. Events
Model: models/Event.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Event = sequelize.define('Event', {
EventId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventName: {
type: DataTypes.STRING(100),
allowNull: false,
},
Description: {
type: DataTypes.TEXT,
allowNull: false,
},
StartDate: {
type: DataTypes.DATE,
allowNull: false,
},
EndDate: {
type: DataTypes.DATE,
allowNull: false,
},
VenueId: {
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = Event;
Repository: repositories/EventRepository.js
const Event = require('../models/Event');
class EventRepository {
async create(eventData) {
return await Event.create(eventData);
}
async findAll() {
return await Event.findAll();
}
async findById(id) {
return await Event.findByPk(id);
}
async update(id, eventData) {
const event = await this.findById(id);
if (event) {
return await event.update(eventData);
}
return null;
}
async delete(id) {
const event = await this.findById(id);
if (event) {
return await event.destroy();
}
return null;
}
}
module.exports = new EventRepository();
Controller: controllers/EventController.js
const EventRepository = require('../repositories/EventRepository');
class EventController {
async create(req, res) {
await EventRepository.create(req.body);
res.redirect('/events');
}
async findAll(req, res) {
const events = await EventRepository.findAll();
res.render('events/index', { events });
}
async findById(req, res) {
const event = await EventRepository.findById(req.params.id);
res.render('events/edit', { event });
}
async update(req, res) {
await EventRepository.update(req.params.id, req.body);
res.redirect('/events');
}
async delete(req, res) {
await EventRepository.delete(req.params.id);
res.redirect('/events');
}
}
module.exports = new EventController();
Routes: routes/eventRoutes.js
const express = require('express');
const router = express.Router();
const EventController = require('../controllers/EventController');
router.get('/', EventController.findAll);
router.get('/create', (req, res) => res.render('events/create'));
router.post('/', EventController.create);
router.get('/:id/edit', EventController.findById);
router.post('/:id', EventController.update);
router.post('/:id/delete', EventController.delete);
module.exports = router;
Views
views/events/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Events</title>
</head>
<body>
<div class="container">
<h1>Events</h1>
<a href="/events/create" class="btn btn-primary">Create Event</a>
<table class="table">
<thead>
<tr>
<th>EventId</th>
<th>EventName</th>
<th>StartDate</th>
<th>EndDate</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% events.forEach(event => { %>
<tr>
<td><%= event.EventId %></td>
<td><%= event.EventName %></td>
<td><%= event.StartDate.toISOString().split('T')[0] %></td>
<td><%= event.EndDate.toISOString().split('T')[0] %></td>
<td>
<a href="/events/<%= event.EventId %>/edit" class="btn btn-warning">Edit</a>
<form action="/events/<%= event.EventId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/events/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Event</title>
</head>
<body>
<div class="container">
<h1>Create Event</h1>
<form action="/events" method="POST">
<div class="mb-3">
<label for="EventName" class="form-label">Event Name</label>
<input type="text" class="form-control" id="EventName" name="EventName" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description" required></textarea>
</div>
<div class="mb-3">
<label for="StartDate" class="form-label">Start Date</label>
<input type="datetime-local" class="form-control" id="StartDate" name="StartDate" required>
</div>
<div class="mb-3">
<label for="EndDate" class="form-label">End Date</label>
<input type="datetime-local" class="form-control" id="EndDate" name="EndDate" required>
</div <div class="mb-3">
<label for="VenueId" class="form-label">Venue ID</label>
<input type="number" class="form-control" id="VenueId" name="VenueId">
</div>
<button type="submit" class="btn btn-primary">Create Event</button>
</form>
</div>
</body>
</html>
2. Venues
Model: models/Venue.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Venue = sequelize.define('Venue', {
VenueId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
VenueName: {
type: DataTypes.STRING(100),
allowNull: false,
},
Address: {
type: DataTypes.STRING(255),
allowNull: false,
},
Capacity: {
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = Venue;
Repository: repositories/VenueRepository.js
const Venue = require('../models/Venue');
class VenueRepository {
async create(venueData) {
return await Venue.create(venueData);
}
async findAll() {
return await Venue.findAll();
}
async findById(id) {
return await Venue.findByPk(id);
}
async update(id, venueData) {
const venue = await this.findById(id);
if (venue) {
return await venue.update(venueData);
}
return null;
}
async delete(id) {
const venue = await this.findById(id);
if (venue) {
return await venue.destroy();
}
return null;
}
}
module.exports = new VenueRepository();
Controller: controllers/VenueController.js
const VenueRepository = require('../repositories/VenueRepository');
class VenueController {
async create(req, res) {
await VenueRepository.create(req.body);
res.redirect('/venues');
}
async findAll(req, res) {
const venues = await VenueRepository.findAll();
res.render('venues/index', { venues });
}
async findById(req, res) {
const venue = await VenueRepository.findById(req.params.id);
res.render('venues/edit', { venue });
}
async update(req, res) {
await VenueRepository.update(req.params.id, req.body);
res.redirect('/venues');
}
async delete(req, res) {
await VenueRepository.delete(req.params.id);
res.redirect('/venues');
}
}
module.exports = new VenueController();
Routes: routes/venueRoutes.js
const express = require('express');
const router = express.Router();
const VenueController = require('../controllers/VenueController');
router.get('/', VenueController.findAll);
router.get('/create', (req, res) => res.render('venues/create'));
router.post('/', VenueController.create);
router.get('/:id/edit', VenueController.findById);
router.post('/:id', VenueController.update);
router.post('/:id/delete', VenueController.delete);
module.exports = router;
Views
views/venues/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Venues</title>
</head>
<body>
<div class="container">
<h1>Venues</h1>
<a href="/venues/create" class="btn btn-primary">Create Venue</a>
<table class="table">
<thead>
<tr>
<th>VenueId</th>
<th>VenueName</th>
<th>Address</th>
<th>Capacity</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% venues.forEach(venue => { %>
<tr>
<td><%= venue.VenueId %></td>
<td><%= venue.VenueName %></td>
<td><%= venue.Address %></td>
<td><%= venue.Capacity %></td>
<td>
<a href="/venues/<%= venue.VenueId %>/edit" class="btn btn-warning">Edit</a>
<form action="/venues/<%= venue.VenueId %>/delete" method="POST" style=" display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/venues/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Venue</title>
</head>
<body>
<div class="container">
<h1>Create Venue</h1>
<form action="/venues" method="POST">
<div class="mb-3">
<label for="VenueName" class="form-label">Venue Name</label>
<input type="text" class="form-control" id="VenueName" name="VenueName" required>
</div>
<div class="mb-3">
<label for="Address" class="form-label">Address</label>
<input type="text" class="form-control" id="Address" name="Address" required>
</div>
<div class="mb-3">
<label for="Capacity" class="form-label">Capacity</label>
<input type="number" class="form-control" id="Capacity" name="Capacity">
</div>
<button type="submit" class="btn btn-primary">Create Venue</button>
</form>
</div>
</body>
</html>
3. Registrations
Model: models/Registration.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Registration = sequelize.define('Registration', {
RegistrationId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
UserId: {
type: DataTypes.INTEGER,
},
EventId: {
type: DataTypes.INTEGER,
},
RegistrationDate: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
},
Status: {
type: DataTypes.STRING(20),
defaultValue: 'Registered',
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Registration;
Repository: repositories/RegistrationRepository.js
const Registration = require('../models/Registration');
class RegistrationRepository {
async create(registrationData) {
return await Registration.create(registrationData);
}
async findAll() {
return await Registration.findAll();
}
async findById(id) {
return await Registration.findByPk(id);
}
async update(id, registrationData) {
const registration = await this.findById(id);
if (registration) {
return await registration.update(registrationData);
}
return null;
}
async delete(id) {
const registration = await this.findById(id);
if (registration) {
return await registration.destroy();
}
return null;
}
}
module.exports = new RegistrationRepository();
Controller: controllers/RegistrationController.js
const RegistrationRepository = require('../repositories/RegistrationRepository');
class RegistrationController {
async create(req, res) {
await RegistrationRepository.create(req.body);
res.redirect('/registrations');
}
async findAll(req, res) {
const registrations = await RegistrationRepository.findAll();
res.render('registrations/index', { registrations });
}
async findById(req, res) {
const registration = await RegistrationRepository.findById(req.params.id);
res.render('registrations/edit', { registration });
}
async update(req, res) {
await RegistrationRepository.update(req.params.id, req.body);
res.redirect('/registrations');
}
async delete(req, res) {
await RegistrationRepository.delete(req.params.id);
res.redirect('/registrations');
}
}
module.exports = new RegistrationController();
Routes: routes/registrationRoutes.js
const express = require('express');
const router = express.Router();
const RegistrationController = require('../controllers/RegistrationController');
router.get('/', RegistrationController.findAll);
router.get('/create', (req, res) => res.render('registrations/create'));
router.post('/', RegistrationController.create);
router.get('/:id/edit', RegistrationController.findById);
router.post('/:id', RegistrationController.update);
router.post('/:id/delete', RegistrationController.delete);
module.exports = router;
Views
views/registrations/index.ejs:
<!DOCTYPE html>
<html lang=" en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Registrations</title>
</head>
<body>
<div class="container">
<h1>Registrations</h1>
<a href="/registrations/create" class="btn btn-primary">Create Registration</a>
<table class="table">
<thead>
<tr>
<th>RegistrationId</th>
<th>UserId</th>
<th>EventId</th>
<th>RegistrationDate</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% registrations.forEach(registration => { %>
<tr>
<td><%= registration.RegistrationId %></td>
<td><%= registration.UserId %></td>
<td><%= registration.EventId %></td>
<td><%= registration.RegistrationDate.toISOString().split('T')[0] %></td>
<td><%= registration.Status %></td>
<td>
<a href="/registrations/<%= registration.RegistrationId %>/edit" class="btn btn-warning">Edit</a>
<form action="/registrations/<%= registration.RegistrationId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/registrations/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Registration</title>
</head>
<body>
<div class="container">
<h1>Create Registration</h1>
<form action="/registrations" method="POST">
<div class="mb-3">
<label for="User Id" class="form-label">User ID</label>
<input type="number" class="form-control" id="User Id" name="User Id" required>
</div>
<div class="mb-3">
<label for="EventId" class="form-label">Event ID</label>
<input type="number" class="form-control" id="EventId" name="EventId" required>
</div>
<button type="submit" class="btn btn-primary">Create Registration</button>
</form>
</div>
</body>
</html>
4. Tickets
Model: models/Ticket.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Ticket = sequelize.define('Ticket', {
TicketId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
RegistrationId: {
type: DataTypes.INTEGER,
},
TicketType: {
type: DataTypes.STRING(50),
},
Price: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Ticket;
Repository: repositories/TicketRepository.js
const Ticket = require('../models/Ticket');
class TicketRepository {
async create(ticketData) {
return await Ticket.create(ticketData);
}
async findAll() {
return await Ticket.findAll();
}
async findById(id) {
return await Ticket.findByPk(id);
}
async update(id, ticketData) {
const ticket = await this.findById(id);
if (ticket) {
return await ticket.update(ticketData);
}
return null;
}
async delete(id) {
const ticket = await this.findById(id);
if (ticket) {
return await ticket.destroy();
}
return null;
}
}
module.exports = new TicketRepository();
Controller: controllers/TicketController.js
const TicketRepository = require('../repositories/TicketRepository');
class TicketController {
async create(req, res) {
await TicketRepository.create(req.body);
res.redirect('/tickets');
}
async findAll(req, res) {
const tickets = await TicketRepository.findAll();
res.render('tickets/index', { tickets });
}
async findById(req, res) {
const ticket = await TicketRepository.findById(req.params.id);
res.render('tickets/edit', { ticket });
}
async update(req, res) {
await TicketRepository.update(req.params.id, req.body);
res.redirect('/tickets');
}
async delete(req, res) {
await TicketRepository.delete(req.params.id);
res.redirect('/tickets');
}
}
module.exports = new TicketController();
Routes: routes/ticketRoutes.js
const express = require('express');
const router = express.Router();
const TicketController = require('../controllers/TicketController');
router.get('/', TicketController.findAll);
router.get('/create', (req, res) => res.render('tickets/create'));
router.post('/', TicketController.create);
router.get('/:id/edit', TicketController.findById);
router.post('/:id', TicketController.update);
router.post('/:id/delete', TicketController.delete);
module.exports = router;
Views
views/tickets/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Tickets</title>
</head>
<body>
<div class="container">
<h1>Tickets</h1>
<a href="/tickets/create" class="btn btn-primary">Create Ticket</a>
<table class="table">
<thead>
<tr>
<th>TicketId</th>
<th>RegistrationId</th>
<th>TicketType</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% tickets.forEach(ticket => { %>
<tr>
<td><%= ticket.TicketId %></td>
<td><%= ticket.RegistrationId %></td>
<td><%= ticket.TicketType %></td>
<td><%= ticket.Price %></td>
<td>
<a href="/tickets/<%= ticket.TicketId %>/edit" class="btn btn-warning">Edit</a>
<form action="/tickets/<%= ticket.TicketId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/tickets/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Ticket</title>
</head>
<body>
<div class="container">
<h1>Create Ticket</h1>
<form action="/tickets" method="POST">
<div class="mb-3">
<label for="RegistrationId" class="form-label">Registration ID</label>
<input type="number" class="form-control" id="RegistrationId" name="RegistrationId" required>
</div>
<div class="mb-3">
<label for="TicketType" class="form-label">Ticket Type</label>
<input type="text" class="form-control" id="TicketType" name="TicketType" required>
</div>
<div class="mb-3">
<label for="Price" class="form-label">Price</label>
<input type="number" step="0.01" class="form-control" id="Price" name="Price" required>
</div>
<button type="submit" class="btn btn-primary">Create Ticket</button>
</form>
</div>
</body>
</html>
5. Notifications
Model: models/Notification.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Notification = sequelize.define('Notification', {
NotificationId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
UserId: {
type: DataTypes.INTEGER,
},
Message: {
type: DataTypes.TEXT,
},
IsRead: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Notification;
Repository: repositories/NotificationRepository.js
const Notification = require('../models/Notification');
class NotificationRepository {
async create(notificationData) {
return await Notification.create(notificationData);
}
async findAll() {
return await Notification.findAll();
}
async findById(id) {
return await Notification.findByPk(id);
}
async update(id, notificationData) {
const notification = await this.findById(id);
if (notification) {
return await notification.update(notificationData);
}
return null;
}
async delete(id) {
const notification = await this.findById(id);
if (notification) {
return await notification.destroy();
}
return null;
}
}
module.exports = new NotificationRepository();
Controller: controllers/NotificationController.js
const NotificationRepository = require('../repositories/NotificationRepository');
class NotificationController {
async create(req, res) {
await NotificationRepository.create(req.body);
res.redirect('/notifications');
}
async findAll(req, res) {
const notifications = await NotificationRepository.findAll();
res.render('notifications/index', { notifications });
}
async findById(req, res) {
const notification = await NotificationRepository.findById(req.params.id);
res.render('notifications/edit', { notification });
}
async update(req, res) {
await NotificationRepository.update(req.params.id, req.body);
res.redirect('/notifications');
}
async delete(req, res) {
await NotificationRepository.delete(req.params.id);
res.redirect('/notifications');
}
}
module.exports = new NotificationController();
Routes: routes/notificationRoutes.js
const express = require('express');
const router = express.Router();
const NotificationController = require('../controllers/NotificationController');
router.get('/', NotificationController.findAll);
router.get('/create', (req, res) => res.render('notifications/create'));
router.post('/', NotificationController.create);
router.get('/:id/edit', NotificationController.findById);
router.post('/:id', NotificationController.update);
router.post('/:id/delete', NotificationController.delete);
module.exports = router;
Views
views/notifications/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Notifications</title>
</head>
<body>
<div class="container">
<h1>Notifications</h1>
<a href="/notifications/create" class="btn btn-primary">Create Notification</a>
<table class="table">
<thead>
<tr>
<th>NotificationId</th>
<th>UserId</th>
<th>Message</th>
<th>IsRead</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% notifications.forEach(notification => { %>
<tr>
<td><%= notification.NotificationId %></td>
<td><%= notification.UserId %></td>
<td><%= notification.Message %></td>
<td><%= notification.IsRead ? 'Yes' : 'No' %></td>
<td>
<a href="/notifications/<%= notification.NotificationId %>/edit" class="btn btn-warning">Edit</a>
<form action="/notifications/<%= notification.NotificationId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/notifications/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Notification</title>
</head>
<body>
<div class="container">
<h1>Create Notification</h1>
<form action="/notifications" method="POST">
<div class="mb-3">
<label for="User Id " class="form-label">User ID</label>
<input type="number" class="form-control" id="User Id" name="User Id" required>
</div>
<div class="mb-3">
<label for="Message" class="form-label">Message</label>
<textarea class="form-control" id="Message" name="Message" required></textarea>
</div>
<div class="mb-3">
<label for="IsRead" class="form-label">Is Read</label>
<select class="form-control" id="IsRead" name="IsRead">
<option value="false">No</option>
<option value="true">Yes</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Create Notification</button>
</form>
</div>
</body>
</html>
6. Vendors
Model: models/Vendor.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Vendor = sequelize.define('Vendor', {
VendorId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
VendorName: {
type: DataTypes.STRING(100),
allowNull: false,
},
ContactPerson: {
type: DataTypes.STRING(100),
},
Phone: {
type: DataTypes.STRING(15),
},
Email: {
type: DataTypes.STRING(100),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = Vendor;
Repository: repositories/VendorRepository.js
const Vendor = require('../models/Vendor');
class VendorRepository {
async create(vendorData) {
return await Vendor.create(vendorData);
}
async findAll() {
return await Vendor.findAll();
}
async findById(id) {
return await Vendor.findByPk(id);
}
async update(id, vendorData) {
const vendor = await this.findById(id);
if (vendor) {
return await vendor.update(vendorData);
}
return null;
}
async delete(id) {
const vendor = await this.findById(id);
if (vendor) {
return await vendor.destroy();
}
return null;
}
}
module.exports = new VendorRepository();
Controller: controllers/VendorController.js
const VendorRepository = require('../repositories/VendorRepository');
class VendorController {
async create(req, res) {
await VendorRepository.create(req.body);
res.redirect('/vendors');
}
async findAll(req, res) {
const vendors = await VendorRepository.findAll();
res.render('vendors/index', { vendors });
}
async findById(req, res) {
const vendor = await VendorRepository.findById(req.params.id);
res.render('vendors/edit', { vendor });
}
async update(req, res) {
await VendorRepository.update(req.params.id, req.body);
res.redirect('/vendors');
}
async delete(req, res) {
await VendorRepository.delete(req.params.id);
res.redirect('/vendors');
}
}
module.exports = new VendorController();
Routes: routes/vendorRoutes.js
const express = require('express');
const router = express.Router();
const VendorController = require('../controllers/VendorController');
router.get('/', VendorController.findAll);
router.get('/create', (req, res) => res.render('vendors/create'));
router.post('/', VendorController.create);
router.get('/:id/edit', VendorController.findById);
router.post('/:id', VendorController.update);
router.post('/:id/delete', VendorController.delete);
module.exports = router;
Views
views/vendors/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Vendors</title>
</head>
<body>
<div class="container">
<h1>Vendors</h1>
<a href="/vendors/create" class="btn btn-primary">Create Vendor</a>
<table class="table">
<thead>
<tr>
<th>VendorId</th>
<th>VendorName</th>
<th>ContactPerson</th>
<th>Phone</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% vendors.forEach(vendor => { %>
<tr>
<td><%= vendor.VendorId %></td>
<td><%= vendor.VendorName %></td>
<td><%= vendor.ContactPerson %></td>
<td><%= vendor.Phone %></td>
<td><%= vendor.Email %></td>
<td>
<a href="/vendors/<%= vendor.VendorId %>/edit" class="btn btn-warning">Edit</a>
<form action="/vendors/<%= vendor.VendorId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/vendors/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Vendor</title>
</head>
<body>
<div class="container">
<h1>Create Vendor</h1>
<form action="/vendors" method="POST">
<div class="mb-3">
<label for="VendorName" class="form-label">Vendor Name</label>
<input type="text" class="form-control" id="VendorName" name="VendorName" required>
</div>
<div class="mb-3">
<label for="ContactPerson" class="form-label">Contact Person</label>
<input type="text" class="form-control" id="ContactPerson" name="ContactPerson">
</div>
<div class="mb-3">
<label for="Phone" class="form-label">Phone</label>
<input type="text" class="form-control" id="Phone" name="Phone">
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type="email" class="form-control" id="Email" name="Email">
</div>
<button type="submit" class="btn btn-primary">Create Vendor</button>
</form>
</div>
</body>
</html>
7. Marketing Campaigns
Model: models/MarketingCampaign.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const MarketingCampaign = sequelize.define('MarketingCampaign', {
CampaignId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
CampaignName: {
type: DataTypes.STRING(100),
allowNull: false,
},
StartDate: {
type: DataTypes.DATE,
},
EndDate: {
type: DataTypes.DATE,
},
Budget: {
type: DataTypes.DECIMAL(10, 2),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
});
module.exports = MarketingCampaign;
Repository: repositories/MarketingCampaignRepository.js
const MarketingCampaign = require('../models/MarketingCampaign');
class MarketingCampaignRepository {
async create(campaignData) {
return await MarketingCampaign.create(campaignData);
}
async findAll() {
return await MarketingCampaign.findAll();
}
async findById(id) {
return await MarketingCampaign.findByPk(id);
}
async update(id, campaignData) {
const campaign = await this.findById(id);
if (campaign) {
return await campaign.update(campaignData);
}
return null;
}
async delete(id) {
const campaign = await this.findById(id);
if (campaign) {
return await campaign.destroy();
}
return null;
}
}
module.exports = new MarketingCampaignRepository();
Controller: controllers/MarketingCampaignController.js
const MarketingCampaignRepository = require('../repositories/MarketingCampaignRepository');
class MarketingCampaignController {
async create(req, res) {
await MarketingCampaignRepository.create(req.body);
res.redirect('/marketing-campaigns');
}
async findAll(req, res) {
const campaigns = await MarketingCampaignRepository.findAll();
res.render('marketing-campaigns/index', { campaigns });
}
async findById(req, res) {
const campaign = await MarketingCampaignRepository.findById(req.params.id);
res.render('marketing-campaigns/edit', { campaign });
}
async update(req, res) {
await MarketingCampaignRepository.update(req.params.id, req.body);
res.redirect('/marketing-campaigns');
}
async delete(req, res) {
await MarketingCampaignRepository.delete(req.params.id);
res.redirect('/marketing-campaigns');
}
}
module.exports = new MarketingCampaignController();
Routes: routes/marketingCampaignRoutes.js
const express = require('express');
const router = express.Router();
const MarketingCampaignController = require('../controllers/MarketingCampaignController');
router.get('/', MarketingCampaignController.findAll);
router.get('/create', (req, res) => res.render('marketing-campaigns/create'));
router.post('/', MarketingCampaignController.create);
router.get('/:id/edit', MarketingCampaignController.findById);
router.post('/:id', MarketingCampaignController.update);
router.post('/:id/delete', MarketingCampaignController.delete);
module.exports = router;
Views
views/marketing-campaigns/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Marketing Campaigns</title>
</head>
<body>
<div class="container">
<h1>Marketing Campaigns</h1>
<a href="/marketing-campaigns/create" class="btn btn-primary">Create Campaign</a>
<table class="table">
<thead>
<tr>
<th>CampaignId</th>
<th>CampaignName</th>
<th>StartDate</th>
<th>EndDate</th>
<th>Budget</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% campaigns.forEach(campaign => { %>
<tr>
<td><%= campaign.CampaignId %></td>
<td><%= campaign.CampaignName %></td>
<td><%= campaign.StartDate ? campaign.StartDate.toISOString().split('T')[0] : 'N/A' %></td>
<td><%= campaign.EndDate ? campaign.EndDate.toISOString().split('T')[0] : 'N/A' %></td>
<td><%= campaign.Budget %></td>
<td>
<a href="/marketing-campaigns/<%= campaign.CampaignId %>/edit" class="btn btn-warning">Edit</a>
<form action="/marketing-campaigns/<%= campaign.CampaignId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/marketing-campaigns/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Marketing Campaign</title>
</head>
<body>
<div class="container">
<h1>Create Marketing Campaign</h1>
<form action="/marketing-campaigns" method="POST">
<div class="mb-3">
<label for="CampaignName" class="form-label">Campaign Name</label>
<input type="text" class="form-control" id="CampaignName" name="CampaignName" required>
</div>
<div class="mb-3">
<label for="StartDate" class="form-label">Start Date</label>
<input type="datetime-local" class="form-control" id="StartDate" name="StartDate">
</div>
<div class="mb-3">
<label for="EndDate" class="form-label">End Date</label>
<input type="datetime-local" class="form-control" id="EndDate" name="EndDate">
</div>
<div class="mb-3">
<label for="Budget" class="form-label">Budget</label>
<input type="number" step="0.01" class="form-control" id="Budget" name="Budget">
</div>
<button type="submit" class="btn btn-primary">Create Campaign</button>
</form>
</div>
</body>
</html>
8. Feedbacks
Model: models/Feedback.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Feedback = sequelize.define('Feedback', {
FeedbackId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
UserId: {
type: DataTypes.INTEGER,
},
EventId: {
type: DataTypes.INTEGER,
},
Comments: {
type: DataTypes.TEXT,
},
Rating: {
type: DataTypes.INTEGER,
validate: {
min: 1,
max: 5,
},
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = Feedback;
Repository: repositories/FeedbackRepository.js
const Feedback = require('../models/Feedback');
class FeedbackRepository {
async create(feedbackData) {
return await Feedback.create(feedbackData);
}
async findAll() {
return await Feedback.findAll();
}
async findById(id) {
return await Feedback.findByPk(id);
}
async update(id, feedbackData) {
const feedback = await this.findById(id);
if (feedback) {
return await feedback.update(feedbackData);
}
return null;
}
async delete(id) {
const feedback = await this.findById(id);
if (feedback) {
return await feedback.destroy();
}
return null;
}
}
module.exports = new FeedbackRepository();
Controller: controllers/FeedbackController.js
const FeedbackRepository = require('../repositories/FeedbackRepository');
class FeedbackController {
async create(req, res) {
await FeedbackRepository.create(req.body);
res.redirect('/feedbacks');
}
async findAll(req, res) {
const feedbacks = await FeedbackRepository.findAll();
res.render('feedbacks/index', { feedbacks });
}
async findById(req, res) {
const feedback = await FeedbackRepository.findById(req.params.id);
res.render('feedbacks/edit', { feedback });
}
async update(req, res) {
await FeedbackRepository.update(req.params.id, req.body);
res.redirect('/feedbacks');
}
async delete(req, res) {
await FeedbackRepository.delete(req.params.id);
res.redirect('/feedbacks');
}
}
module.exports = new FeedbackController();
Routes: routes/feedbackRoutes.js
const express = require('express');
const router = express.Router();
const FeedbackController = require('../controllers/FeedbackController');
router.get('/', FeedbackController.findAll);
router.get('/create', (req, res) => res.render('feedbacks/create'));
router.post('/', FeedbackController.create);
router.get('/:id/edit', FeedbackController.findById);
router.post('/:id', FeedbackController.update);
router.post('/:id/delete', FeedbackController.delete);
module.exports = router;
Views
views/feedbacks/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Feedbacks</title>
</head>
<body>
<div class="container">
<h1>Feedbacks</h1>
<a href="/feedbacks/create" class="btn btn-primary">Create Feedback</a>
<table class="table">
<thead>
<tr>
<th>FeedbackId</th>
<th>UserId</th>
<th>EventId</th>
<th>Comments</th>
<th>Rating</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% feedbacks.forEach(feedback => { %>
<tr>
<td><%= feedback.FeedbackId %></td>
<td><%= feedback.UserId %></td>
<td><%= feedback.EventId %></td>
<td><%= feedback.Comments %></td>
<td><%= feedback.Rating %></td>
<td>
<a href="/feedbacks/<%= feedback.FeedbackId %>/edit" class="btn btn-warning">Edit</a>
<form action="/feedbacks/<%= feedback.FeedbackId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button </form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/feedbacks/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Feedback</title>
</head>
<body>
<div class="container">
<h1>Create Feedback</h1>
<form action="/feedbacks" method="POST">
<div class="mb-3">
<label for="User Id" class="form-label">User ID</label>
<input type="number" class="form-control" id="User Id" name="User Id" required>
</div>
<div class="mb-3">
<label for="EventId" class="form-label">Event ID</label>
<input type="number" class="form-control" id="EventId" name="EventId" required>
</div>
<div class="mb-3">
<label for="Comments" class="form-label">Comments</label>
<textarea class="form-control" id="Comments" name="Comments" required></textarea>
</div>
<div class="mb-3">
<label for="Rating" class="form-label">Rating</label>
<input type="number" class="form-control" id="Rating" name="Rating" min="1" max="5" required>
</div>
<button type="submit" class="btn btn-primary">Create Feedback</button>
</form>
</div>
</body>
</html>
9. Attendance Reports
Model: models/AttendanceReport.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const AttendanceReport = sequelize.define('AttendanceReport', {
ReportId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventId: {
type: DataTypes.INTEGER,
},
TotalAttendees: {
type: DataTypes.INTEGER,
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = AttendanceReport;
Repository: repositories/AttendanceReportRepository.js
const AttendanceReport = require('../models/AttendanceReport');
class AttendanceReportRepository {
async create(reportData) {
return await AttendanceReport.create(reportData);
}
async findAll() {
return await AttendanceReport.findAll();
}
async findById(id) {
return await AttendanceReport.findByPk(id);
}
async update(id, reportData) {
const report = await this.findById(id);
if (report) {
return await report.update(reportData);
}
return null;
}
async delete(id) {
const report = await this.findById(id);
if (report) {
return await report.destroy();
}
return null;
}
}
module.exports = new AttendanceReportRepository();
Controller: controllers/AttendanceReportController.js
const AttendanceReportRepository = require('../repositories/AttendanceReportRepository');
class AttendanceReportController {
async create(req, res) {
await AttendanceReportRepository.create(req.body);
res.redirect('/attendance-reports');
}
async findAll(req, res) {
const reports = await AttendanceReportRepository.findAll();
res.render('attendance-reports/index', { reports });
}
async findById(req, res) {
const report = await AttendanceReportRepository.findById(req.params.id);
res.render('attendance-reports/edit', { report });
}
async update(req, res) {
await AttendanceReportRepository.update(req.params.id, req.body);
res.redirect('/attendance-reports');
}
async delete(req, res) {
await AttendanceReportRepository.delete(req.params.id);
res.redirect('/attendance-reports');
}
}
module.exports = new AttendanceReportController();
Routes: routes/attendanceReportRoutes.js
const express = require('express');
const router = express.Router();
const AttendanceReportController = require('../controllers/AttendanceReportController');
router.get('/', AttendanceReportController.findAll);
router.get('/create', (req, res) => res.render('attendance-reports/create'));
router.post('/', AttendanceReportController.create);
router.get('/:id/edit', AttendanceReportController.findById);
router.post('/:id', AttendanceReportController.update);
router.post('/:id/delete', AttendanceReport Controller.delete);
module.exports = router;
Views
views/attendance-reports/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Attendance Reports</title>
</head>
<body>
<div class="container">
<h1>Attendance Reports</h1>
<a href="/attendance-reports/create" class="btn btn-primary">Create Report</a>
<table class="table">
<thead>
<tr>
<th>ReportId</th>
<th>EventId</th>
<th>TotalAttendees</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% reports.forEach(report => { %>
<tr>
<td><%= report.ReportId %></td>
<td><%= report.EventId %></td>
<td><%= report.TotalAttendees %></td>
<td>
<a href="/attendance-reports/<%= report.ReportId %>/edit" class="btn btn-warning">Edit</a>
<form action="/attendance-reports/<%= report.ReportId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/attendance-reports/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Attendance Report</title>
</head>
<body>
<div class="container">
<h1>Create Attendance Report</h1>
<form action="/attendance-reports" method="POST">
<div class="mb-3">
<label for="EventId" class="form-label">Event ID</label>
<input type="number" class="form-control" id="EventId" name="EventId" required>
</div>
<div class="mb-3">
<label for="TotalAttendees" class="form-label">Total Attendees</label>
<input type="number" class="form-control" id="TotalAttendees" name="TotalAttendees" required>
</div>
<button type="submit" class="btn btn-primary">Create Report</button>
</form>
</div>
</body>
</html>
10. Financial Reports
Model: models/FinancialReport.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const FinancialReport = sequelize.define('FinancialReport', {
FinancialReportId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventId: {
type: DataTypes.INTEGER,
},
TotalRevenue: {
type: DataTypes.DECIMAL(10, 2),
},
TotalExpenses: {
type: DataTypes.DECIMAL(10, 2),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = FinancialReport;
Repository: repositories/FinancialReportRepository.js
const FinancialReport = require('../models/FinancialReport');
class FinancialReportRepository {
async create(reportData) {
return await FinancialReport.create(reportData);
}
async findAll() {
return await FinancialReport.findAll();
}
async findById(id) {
return await FinancialReport.findByPk(id);
}
async update(id, reportData) {
const report = await this.findById(id);
if (report) {
return await report.update(reportData);
}
return null;
}
async delete(id) {
const report = await this.findById(id);
if (report) {
return await report.destroy();
}
return null;
}
}
module.exports = new FinancialReportRepository();
Controller: controllers/FinancialReportController.js
const FinancialReportRepository = require('../repositories/FinancialReportRepository');
class FinancialReportController {
async create(req, res) {
await FinancialReportRepository.create(req.body);
res.redirect('/financial-reports');
}
async findAll(req, res) {
const reports = await FinancialReportRepository.findAll();
res.render('financial-reports/index', { reports });
}
async findById(req, res) {
const report = await FinancialReportRepository.findById(req.params.id);
res.render('financial-reports/edit', { report });
}
async update(req, res) {
await FinancialReportRepository.update(req.params.id, req.body);
res.redirect('/financial-reports');
}
async delete(req, res) {
await FinancialReportRepository.delete(req.params.id);
res.redirect('/financial-reports');
}
}
module.exports = new FinancialReportController();
Routes: routes/financialReportRoutes.js
const express = require('express');
const router = express.Router();
const FinancialReportController = require('../controllers/FinancialReportController');
router.get('/', FinancialReportController.findAll);
router.get('/create', (req, res) => res.render('financial-reports/create'));
router.post('/', FinancialReportController.create);
router.get('/:id/edit', FinancialReportController.findById);
router.post('/:id', FinancialReportController.update);
router.post('/:id/delete', FinancialReportController.delete);
module.exports = router;
Views
views/financial-reports/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Financial Reports</title>
</head>
<body>
<div class="container">
<h1>Financial Reports</h1>
<a href="/financial-reports/create" class="btn btn-primary">Create Report</a>
<table class="table">
<thead>
<tr>
<th>FinancialReportId</th>
<th>EventId</th>
<th>TotalRevenue</th>
<th>TotalExpenses</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% reports.forEach(report => { %>
<tr>
<td><%= report.FinancialReportId %></td>
<td><%= report.EventId %></td>
<td><%= report.TotalRevenue %></td>
<td><%= report.TotalExpenses %></td>
<td>
<a href="/financial-reports/<%= report.FinancialReportId %>/edit" class="btn btn-warning">Edit</a>
<form action="/financial-reports/<%= report.FinancialReportId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/financial-reports/create.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Financial Report</title>
</head>
<body>
<div class="container">
<h1>Create Financial Report</h1>
<form action="/financial-reports" method="POST">
<div class="mb-3">
<label for="EventId" class="form-label">Event ID</label>
<input type="number" class="form-control" id="EventId" name="EventId" required>
</div>
<div class="mb-3">
<label for="TotalRevenue" class="form-label">Total Revenue</label>
<input type="number" step="0.01" class="form-control" id="TotalRevenue" name="TotalRevenue" required>
</div>
<div class="mb-3">
<label for="TotalExpenses" class="form-label">Total Expenses</label>
<input type="number" step="0.01" class="form-control" id="TotalExpenses" name="TotalExpenses" required>
</div>
<button type="submit" class="btn btn-primary">Create Report</button>
</form>
</div>
</body>
</html>
11. Performance Metrics
Model: models/PerformanceMetric.js
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const PerformanceMetric = sequelize.define('PerformanceMetric', {
MetricId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
EventId: {
type: DataTypes.INTEGER,
},
MetricName: {
type: DataTypes.STRING(100),
},
MetricValue: {
type: DataTypes.DECIMAL(10, 2),
},
}, {
timestamps: true,
createdAt: 'CreatedAt',
});
module.exports = PerformanceMetric;
Repository: repositories/PerformanceMetricRepository.js
const PerformanceMetric = require('../models/PerformanceMetric');
class PerformanceMetricRepository {
async create(metricData) {
return await PerformanceMetric.create(metricData);
}
async findAll() {
return await PerformanceMetric.findAll();
}
async findById(id) {
return await PerformanceMetric.findByPk(id);
}
async update(id, metricData) {
const metric = await this.findById(id);
if (metric) {
return await metric.update(metricData);
}
return null;
}
async delete(id) {
const metric = await this.findById(id);
if (metric) {
return await metric.destroy();
}
return null;
}
}
module.exports = new PerformanceMetricRepository();
Controller: controllers/PerformanceMetricController.js
const PerformanceMetricRepository = require('../repositories/PerformanceMetricRepository');
class PerformanceMetricController {
async create(req, res) {
await PerformanceMetricRepository.create(req.body);
res.redirect('/performance-metrics');
}
async findAll(req, res) {
const metrics = await PerformanceMetricRepository.findAll();
res.render('performance-metrics/index', { metrics });
}
async findById(req, res) {
const metric = await PerformanceMetricRepository.findById(req.params.id);
res.render('performance-metrics/edit', { metric });
}
async update(req, res) {
await PerformanceMetricRepository.update(req.params.id, req.body);
res.redirect('/performance-metrics');
}
async delete(req, res) {
await PerformanceMetricRepository.delete(req.params.id);
res.redirect('/performance-metrics');
}
}
module.exports = new PerformanceMetricController();
Routes: routes/performanceMetricRoutes.js
const express = require('express');
const router = express.Router();
const PerformanceMetricController = require('../controllers/PerformanceMetricController');
router.get('/', PerformanceMetricController.findAll);
router.get('/create', (req, res) => res.render('performance-metrics/create'));
router.post('/', PerformanceMetricController.create);
router.get('/:id/edit', PerformanceMetricController.findById);
router.post('/:id', PerformanceMetricController.update);
router.post('/:id/delete', PerformanceMetricController.delete);
module.exports = router;
Views
views/performance-metrics/index.ejs:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Performance Metrics</title>
</head>
<body>
<div class="container">
<h1>Performance Metrics</h1>
<a href="/performance-metrics/create" class="btn btn-primary">Create Metric</a>
<table class="table">
<thead>
<tr>
<th>MetricId</th>
<th>EventId</th>
<th>MetricName</th>
<th>MetricValue</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% metrics.forEach(metric => { %>
<tr>
<td><%= metric.MetricId %></td>
<td><%= metric.EventId %></td>
<td><%= metric.MetricName %></td>
<td><%= metric.MetricValue %></td>
<td>
<a href="/performance-metrics/<%= metric.MetricId %>/edit" class="btn btn-warning">Edit</a>
<form action="/performance-metrics/<%= metric.MetricId %>/delete" method="POST" style="display:inline;">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</body>
</html>
views/performance-metrics/create.ejs:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> <title>Create Performance Metric</title> </head> <body> <div class="container"> <h1>Create Performance Metric</h1> <form action="/performance-metrics" method="POST"> <div class="mb-3"> <label for="EventId" class="form-label">Event ID</label> <input type="number" class="form-control" id="EventId" name="EventId" required> </div> <div class="mb-3"> <label for="MetricName" class="form-label">Metric Name</label> <input type="text" class="form-control" id="MetricName" name="MetricName" required> </div> <div class="mb-3"> <label for="MetricValue" class="form-label">Metric Value</label> <input type="number" step="0.01" class="form-control" id="MetricValue" name="MetricValue" required> </div> <button type="submit" class="btn btn-primary">Create Metric</button> </form> </div> </body> </html>
Final Integration
To integrate all the routes into your main application file (e.g., app.js), you would do the following:
// app.js
const express = require('express');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
const sequelize = require('./config/database');
const userRoutes = require('./routes/userRoutes');
const eventRoutes = require('./routes/eventRoutes');
const venueRoutes = require('./routes/venueRoutes');
const registrationRoutes = require('./routes/registrationRoutes');
const ticketRoutes = require('./routes/ticketRoutes');
const notificationRoutes = require('./routes/notificationRoutes');
const vendorRoutes = require('./routes/vendorRoutes');
const marketingCampaignRoutes = require('./routes/marketingCampaignRoutes');
const feedbackRoutes = require('./routes/feedbackRoutes');
const attendanceReportRoutes = require('./routes/attendanceReportRoutes');
const financialReportRoutes = require('./routes/financialReportRoutes');
const performanceMetricRoutes = require('./routes/performanceMetricRoutes');
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('_method'));
app.use(express.static('public'));
app.use('/users', userRoutes);
app.use('/events', eventRoutes);
app.use('/venues', venueRoutes);
app.use('/registrations', registrationRoutes);
app.use('/tickets', ticketRoutes);
app.use('/notifications', notificationRoutes);
app.use('/vendors', vendorRoutes);
app.use('/marketing-campaigns', marketingCampaignRoutes);
app.use('/feedbacks', feedbackRoutes);
app.use('/attendance-reports', attendanceReportRoutes);
app.use('/financial-reports', financialReportRoutes);
app.use('/performance-metrics', performanceMetricRoutes);
const PORT = process.env.PORT || 3000;
sequelize.sync().then(() => {
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
});
Conclusion
With this setup, you now have a complete CRUD application for managing Users, Events, Venues, Registrations, Tickets, Notifications, Vendors, Marketing Campaigns, Feedbacks, Attendance Reports, Financial Reports, and Performance Metrics using Node.js, Sequelize, Express, EJS, and Bootstrap 5. Each entity has its own model, repository, controller, routes, and views, allowing for a structured and maintainable codebase.
To create a dashboard page that displays consolidated data related to your event management project, we will follow these steps:
Create a Dashboard Controller: This controller will fetch data from various models and aggregate it.
Set Up Dashboard Routes: Define a route for accessing the dashboard.
Create a Dashboard View: Use EJS to create a view that will render the dashboard and display the consolidated data.
Step 1: Create the Dashboard Controller
Create a file named DashboardController.js in the controllers directory. This controller will fetch and consolidate data from various models.
// controllers/DashboardController.js
const User = require('../models/User');
const Event = require('../models/Event');
const Venue = require('../models/Venue');
const Registration = require('../models/Registration');
const Ticket = require('../models/Ticket');
const Notification = require('../models/Notification');
const Vendor = require('../models/Vendor');
const MarketingCampaign = require('../models/MarketingCampaign');
const Feedback = require('../models/Feedback');
const AttendanceReport = require('../models/AttendanceReport');
const FinancialReport = require('../models/FinancialReport');
const PerformanceMetric = require('../models/PerformanceMetric');
class DashboardController {
async getDashboardData(req, res) {
try {
const userCount = await User.count();
const eventCount = await Event.count();
const venueCount = await Venue.count();
const registrationCount = await Registration.count();
const ticketCount = await Ticket.count();
const notificationCount = await Notification.count();
const vendorCount = await Vendor.count();
const marketingCampaignCount = await MarketingCampaign.count();
const feedbackCount = await Feedback.count();
const attendanceReportCount = await AttendanceReport.count();
const financialReportCount = await FinancialReport.count();
const performanceMetricCount = await PerformanceMetric.count();
const dashboardData = {
userCount,
eventCount,
venueCount,
registrationCount,
ticketCount,
notificationCount,
vendorCount,
marketingCampaignCount,
feedbackCount,
attendanceReportCount,
financialReportCount,
performanceMetricCount,
};
res.render('dashboard', { dashboardData });
} catch (error) {
console.error("Error fetching dashboard data:", error);
res.status(500).send("Internal Server Error");
}
}
}
module.exports = new DashboardController();
Step 2: Set Up Dashboard Routes
Create a file named dashboardRoutes.js in the routes directory. This file will define the route for accessing the dashboard.
// routes/dashboardRoutes.js
const express = require('express');
const router = express.Router();
const DashboardController = require('../controllers/DashboardController');
router.get('/', DashboardController.getDashboardData);
module.exports = router;
Step 3: Create the Dashboard View
Create a file named dashboard.ejs in the views directory. This file will render the dashboard and display the consolidated data.
views/dashboard.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Dashboard</title>
</head>
<body>
<div class="container">
<h1>Dashboard</h1>
<div class="row">
<div class="col-md-3">
<div class="card text-white bg-primary mb-3">
<div class="card-header">Total Users</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.userCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-success mb-3">
<div class="card-header">Total Events</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.eventCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-warning mb-3">
<div class="card-header">Total Venues</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.venueCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-danger mb-3">
<div class="card-header">Total Registrations</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.registrationCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-info mb-3">
<div class="card-header">Total Tickets</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.ticketCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-secondary mb-3">
<div class="card-header">Total Notifications</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.notificationCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-dark mb-3">
<div class="card-header">Total Vendors</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.vendorCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-light text-dark mb-3">
<div class="card-header">Total Marketing Campaigns</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.marketingCampaignCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-success mb-3">
<div class="card-header">Total Feedbacks</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.feedbackCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-danger mb-3">
<div class="card -header">Total Attendance Reports</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.attendanceReportCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-info mb-3">
<div class="card-header">Total Financial Reports</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.financialReportCount %></h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-secondary mb-3">
<div class="card-header">Total Performance Metrics</div>
<div class="card-body">
<h5 class="card-title"><%= dashboardData.performanceMetricCount %></h5>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Final Integration
To integrate the dashboard into your main application file (e.g., app.js), you would add the following:
// app.js
const dashboardRoutes = require('./routes/dashboardRoutes');
// Other existing routes
app.use('/dashboard', dashboardRoutes);
With this setup, you now have a dashboard page that consolidates and displays key metrics related to your event management project. The dashboard fetches data from various models and presents it in a user-friendly format using Bootstrap cards. You can further enhance the dashboard by adding charts or graphs to visualize the data more effectively.