Event Management System - Code Implementation
1. Setup and Dependencies
const express = require('express');
const sqlite3 = require('sqlite3').verbose();
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const db = new sqlite3.Database('./database.db');
2. Database Schema (SQL)
-- Users table: Stores organiser and attendee information
CREATE TABLE users (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_name TEXT NOT NULL,
user_type TEXT NOT NULL -- 'organiser' or 'attendee'
);
-- Events table: Stores event details
CREATE TABLE events (
event_id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
description TEXT NOT NULL,
event_date TEXT NOT NULL,
state TEXT NOT NULL, -- 'draft' or 'published'
created_at TEXT NOT NULL,
updated_at TEXT
);
-- Tickets table: Stores ticket information for each event
CREATE TABLE tickets (
ticket_id INTEGER PRIMARY KEY AUTOINCREMENT,
event_id INTEGER NOT NULL,
ticket_type TEXT NOT NULL, -- 'full-price' or 'concession'
price REAL NOT NULL,
quantity INTEGER NOT NULL,
FOREIGN KEY (event_id) REFERENCES events(event_id)
);
-- Bookings table: Stores bookings made by attendees for events
CREATE TABLE bookings (
booking_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
event_id INTEGER NOT NULL,
ticket_type TEXT NOT NULL,
quantity INTEGER NOT NULL,
booking_date TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (event_id) REFERENCES events(event_id)
);
3. Express Routes Implementation
// Home route: Displays all events
app.get('/', (req, res) => {
db.all('SELECT * FROM events WHERE state="published"', [], (err, events) => {
if (err) {
throw err;
res.render('index', { events });
});
});
// Add event form
app.get('/add-event', (req, res) => {
res.render('add-event');
});
// Handle new event submission
app.post('/add-event', (req, res) => {
const { title, description, event_date } = req.body;
const state = 'draft'; // default state for new events
const createdAt = new Date().toISOString();
db.run('INSERT INTO events (title, description, event_date, state, created_at) VALUES (?, ?,
?, ?, ?)',
[title, description, event_date, state, createdAt], function(err) {
if (err) {
return console.log(err.message);
res.redirect('/');
});
});
4. HTML Template for Published Events
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Manager</title>
<link rel="stylesheet" href="/main.css">
</head>
<body>
<h1>Published Events</h1>
<ul>
<% events.forEach(event => { %>
<li>
<h3><%= event.title %></h3>
<p><%= event.description %></p>
<p>Date: <%= event.event_date %></p>
<a href="#">Book Tickets</a>
</li>
<% }) %>
</ul>
<a href="/add-event">Add New Event</a>
</body>
</html>
5. CSS for the Webpage
/* main.css */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
h1 {
text-align: center;
margin-top: 20px;
ul {
list-style-type: none;
padding: 0;
li {
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ddd;
background-color: #f9f9f9;
a{
text-decoration: none;
color: #007bff;
6. Final Remarks
The implementation of the Event Management System allows an organiser to create and
manage events,
while attendees can view and book these events. The routes are set up to handle event
creation, viewing,
and booking. A basic database schema has been designed to store user, event, ticket, and
booking information.
The HTML templates are dynamically rendered using EJS, and CSS is used to style the
pages. The Express.js
framework handles routing, and SQLite stores the data. This project follows a three-tier
architecture,
with separate components for the front-end, back-end, and database.