-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/dhairyagothi/StationGuide
- Loading branch information
Showing
32 changed files
with
1,175 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import WheelchairBooking from "../models/WheelChairBooking.js"; | ||
import { io } from "../index.js"; | ||
|
||
// Controller to handle booking creation | ||
export const createWheelchairBooking = async (req, res) => { | ||
const { station, bookingDate, bookingTime, wheelchairType } = req.body; | ||
|
||
try { | ||
const newBooking = new WheelchairBooking({ | ||
station, | ||
bookingDate: new Date(bookingDate), | ||
bookingTime, | ||
wheelchairType: wheelchairType || "manual", | ||
}); | ||
|
||
const savedBooking = await newBooking.save(); | ||
|
||
// Emit real-time booking confirmation to the client | ||
io.emit("wheelchairBookingConfirmation", { | ||
message: `Your booking at ${station} for ${bookingDate} has been confirmed.`, | ||
booking: savedBooking, | ||
}); | ||
|
||
// Send back HTTP response as well | ||
res | ||
.status(201) | ||
.json({ message: "Booking created successfully", booking: savedBooking }); | ||
} catch (error) { | ||
res.status(500).json({ message: "Server error." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { io } from "../index.js"; | ||
import CloakroomBooking from "../models/CloakroomBooking.js"; | ||
|
||
export const createCloakroomBooking = async (req, res) => { | ||
const { station, items, storageStartDate, storageEndDate, charges } = | ||
req.body; | ||
|
||
if (!station || !items || !storageStartDate || !storageEndDate || !charges) { | ||
return res | ||
.status(400) | ||
.json({ message: "Please provide all required fields" }); | ||
} | ||
|
||
try { | ||
const newBooking = new CloakroomBooking({ | ||
station, | ||
items, | ||
storageStartDate: new Date(storageStartDate), | ||
storageEndDate: new Date(storageEndDate), | ||
charges, | ||
}); | ||
|
||
const savedBooking = await newBooking.save(); | ||
|
||
io.emit("cloakroomBookingConfirmation", { | ||
message: `Your booking at ${station} for ${items} has been confirmed.`, | ||
booking: savedBooking, | ||
}); | ||
|
||
res.status(201).json(savedBooking); | ||
} catch (error) { | ||
console.error("Error creating cloakroom booking:", error); | ||
res | ||
.status(500) | ||
.json({ message: "Server error. Could not create booking." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { io } from "../index.js"; | ||
import CoolieBooking from "../models/CoolieBooking.js"; | ||
|
||
export const createCoolieBooking = async (req, res) => { | ||
try { | ||
const { | ||
station, | ||
pickupLocation, | ||
departureLocation, | ||
bookingDate, | ||
bookingTime, | ||
price, | ||
} = req.body; | ||
|
||
if ( | ||
!station || | ||
!pickupLocation || | ||
!departureLocation || | ||
!bookingDate || | ||
!bookingTime || | ||
!price | ||
) { | ||
return res | ||
.status(400) | ||
.json({ message: "Please fill all the required fields." }); | ||
} | ||
|
||
const coolieBooking = new CoolieBooking({ | ||
station, | ||
pickupLocation, | ||
departureLocation, | ||
bookingDate, | ||
bookingTime, | ||
price, | ||
}); | ||
|
||
const savedBooking = await coolieBooking.save(); | ||
|
||
io.emit("coolieBookingConfirmation", { | ||
message: `Your booking at ${station} for coolie has been confirmed.`, | ||
booking: savedBooking, | ||
}); | ||
|
||
res.status(201).json({ | ||
message: "Coolie booking created successfully.", | ||
data: savedBooking, | ||
}); | ||
} catch (error) { | ||
console.error("Error creating coolie booking:", error); | ||
res | ||
.status(500) | ||
.json({ message: "An error occurred while creating the booking." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM node:18-alpine | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
RUN npm install | ||
|
||
COPY . . | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,63 @@ | ||
import express from 'express'; | ||
import cors from 'cors'; | ||
import connectDB from './config/dbConnection.js'; | ||
import cookieParser from 'cookie-parser'; | ||
import express from "express"; | ||
import cors from "cors"; | ||
import connectDB from "./config/dbConnection.js"; | ||
import cookieParser from "cookie-parser"; | ||
import { createServer } from "http"; | ||
import { Server } from "socket.io"; | ||
|
||
const app = express(); | ||
const server = createServer(app); | ||
|
||
const port = process.env.PORT || 3000; | ||
|
||
app.use(cors({ | ||
origin: 'http://localhost:5173', | ||
methods: ['GET', 'POST'], | ||
allowedHeaders: ['Content-Type'], | ||
credentials: true | ||
})); // Enable CORS | ||
app.use( | ||
cors({ | ||
origin: ["http://localhost:5173", "http://127.0.0.1:5500"], | ||
methods: ["GET", "POST"], | ||
allowedHeaders: ["Content-Type"], | ||
credentials: true, | ||
}) | ||
); | ||
|
||
app.use(cookieParser()); // Parse cookies | ||
app.use(express.json()); // Parse incoming request bodies in a middleware before your handlers | ||
app.use(express.urlencoded({ extended: true })); // Parse URL-encoded bodies | ||
app.use(cookieParser()); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
|
||
// Connect to MongoDB | ||
connectDB(); | ||
|
||
// Routes | ||
import authRoutes from './routes/authRoutes.js'; | ||
app.use('/auth', authRoutes); | ||
import authRoutes from "./routes/authRoutes.js"; | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Working...'); | ||
app.use("/auth", authRoutes); | ||
app.use("/api", authRoutes); | ||
|
||
app.get("/", (req, res) => { | ||
res.send("Working..."); | ||
}); | ||
|
||
|
||
|
||
const io = new Server(server, { | ||
cors: { | ||
origin: ["http://localhost:5173", "http://127.0.0.1:5500"], | ||
methods: ["GET", "POST"], | ||
credentials: true, | ||
}, | ||
}); | ||
|
||
io.on("connection", (socket) => { | ||
console.log("A user connected:", socket.id); | ||
|
||
socket.on("disconnect", () => { | ||
console.log("User disconnected:", socket.id); | ||
}); | ||
|
||
socket.on("error", (err) => { | ||
console.error("Socket error:", err); | ||
}); | ||
}); | ||
// Start the server | ||
app.listen(port, () => { | ||
|
||
server.listen(port, () => { | ||
console.log(`Server is running on http://localhost:${port}`); | ||
}); | ||
}); | ||
|
||
export { io }; |
Oops, something went wrong.