-
Notifications
You must be signed in to change notification settings - Fork 128
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' into HamburgerMenu
- Loading branch information
Showing
29 changed files
with
2,725 additions
and
1,071 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,9 @@ | ||
EMAIL_USER=your_gmail | ||
#your email | ||
EMAIL_USER=your_gmail | ||
|
||
# To create a passkey on the phone or computer you’re on: | ||
|
||
# 1. Go to https://myaccount.google.com/signinoptions/passkeys. | ||
# 2. Tap Create a passkey and then Continue.(You'll be required to unlock your device.) | ||
# 3. A 16 character passkey is generated which you can use in below. |
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,49 @@ | ||
import nodemailer from "nodemailer"; | ||
import "dotenv/config"; | ||
|
||
export const createContactUs = async (req, res) => { | ||
const { mail, subject, message } = req.body; | ||
|
||
try { | ||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
host: "smtp.gmail.com", | ||
port: 587, | ||
secure: false, | ||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_PASS, | ||
}, | ||
tls: { | ||
rejectUnauthorized: false, // Disable strict SSL verification | ||
}, | ||
}); | ||
|
||
const mailOptions = { | ||
from: mail, | ||
to: process.env.EMAIL_USER, | ||
subject: subject, | ||
text: message, | ||
}; | ||
|
||
// Send mail with defined transport object | ||
transporter.sendMail(mailOptions, (error, mailOptions) => { | ||
if (error) { | ||
console.error("Error occurred: " + error.message); | ||
return; | ||
} | ||
}); | ||
|
||
res.status(200).json({ | ||
status: "success", | ||
message: "Your contact request has been successfully received.", | ||
}); | ||
} catch (err) { | ||
console.error(`Error at transport : ${err}`); | ||
res.status(500).json({ | ||
status: "error", | ||
message: | ||
"There was an error sending your message. Please try again later.", | ||
}); | ||
} | ||
}; |
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,62 @@ | ||
import Train from "../models/Trains.js"; | ||
|
||
|
||
// Create a new train | ||
export const createTrain = async (req, res) => { | ||
try { | ||
const { trainNumber, trainName, nextStation, services, platformDetails, coachDetails } = req.body; | ||
|
||
|
||
const existingTrain = await Train.findOne({ trainNumber }); | ||
if (existingTrain) { | ||
return res.status(400).json({ message: "Train with this number already exists" }); | ||
} | ||
|
||
|
||
const newTrain = new Train({ | ||
trainNumber, | ||
trainName, | ||
nextStation, | ||
services, | ||
platformDetails, | ||
coachDetails, | ||
}); | ||
|
||
const savedTrain = await newTrain.save(); | ||
|
||
return res.status(201).json({ | ||
message: "Train created successfully", | ||
train: savedTrain, | ||
}); | ||
} catch (error) { | ||
return res.status(500).json({ message: "Error creating train", error: error.message }); | ||
} | ||
}; | ||
|
||
// Fetch all trains | ||
export const getAllTrains = async (req, res) => { | ||
try { | ||
const trains = await Train.find(); | ||
return res.status(200).json(trains); | ||
} catch (error) { | ||
return res.status(500).json({ message: "Error fetching trains", error: error.message }); | ||
} | ||
}; | ||
|
||
// Fetch a single train by train number | ||
export const getTrainByNumber = async (req, res) => { | ||
try { | ||
const { trainNumber } = req.params; | ||
|
||
const train = await Train.findOne({ trainNumber }); | ||
|
||
if (!train) { | ||
return res.status(404).json({ message: "Train not found" }); | ||
} | ||
|
||
return res.status(200).json(train); | ||
} catch (error) { | ||
return res.status(500).json({ message: "Error fetching train", error: error.message }); | ||
} | ||
}; | ||
|
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,82 @@ | ||
// train.js | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const trainSchema = new Schema( | ||
{ | ||
trainNumber: { | ||
type: Number, | ||
required: true, | ||
unique: true, | ||
trim: true, | ||
}, | ||
trainName: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
}, | ||
nextStation: { | ||
type: { | ||
name: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
}, | ||
stationCode: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
}, | ||
arrivalTime: { | ||
type: Date, | ||
required: true, | ||
}, | ||
}, | ||
required: true, | ||
}, | ||
services: { | ||
type: [String], // An array of available services like ["WiFi", "Food", "Lounge"] | ||
required: true, | ||
}, | ||
platformDetails: { | ||
platformNumber: { | ||
type: Number, | ||
required: true, | ||
}, | ||
boardingTime: { | ||
type: Date, | ||
required: true, | ||
}, | ||
}, | ||
coachDetails: [ | ||
{ | ||
coachNumber: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
}, | ||
coachType: { | ||
type: String, | ||
enum: ['Sleeper', 'AC', 'General', 'ChairCar', 'FirstClass'], | ||
required: true, | ||
}, | ||
capacity: { | ||
type: Number, | ||
required: true, | ||
}, | ||
reservedSeats: { | ||
type: Number, | ||
required: true, | ||
default: 0, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
timestamps: true, | ||
} | ||
); | ||
|
||
const Train = mongoose.model("Train", trainSchema); | ||
export default Train; |
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
Oops, something went wrong.