saksh-car-reservation-system
v1.0.7
Published
A Node.js package for managing car reservations, including functionalities for adding cars, making reservations, canceling reservations, modifying reservations, and adding reviews.
Downloads
11
Maintainers
Readme
Saksh Car Reservation System
A Node.js package for managing car reservations, including functionalities for adding cars, making reservations, canceling reservations, modifying reservations, and adding reviews.
Installation
To install the package, use npm:
npm install saksh-car-reservation-system
Example
Here's an example to help you get started:
import SakshCarReservationSystem from 'saksh-car-reservation-system';
import mongoose from 'mongoose';
// MongoDB connection URI
const dbUri = 'mongodb://localhost:27017/edb';
try {
await mongoose.connect(dbUri);
console.log('Connected to MongoDB');
} catch (error) {
console.error('Error connecting to MongoDB:', error);
}
const reservationSystem = new SakshCarReservationSystem();
try {
// Add a new car
await reservationSystem.sakshAddCar('Toyota', 'Camry', 2021);
console.log('Car added successfully');
// List all available cars
const availableCars = await reservationSystem.sakshListAvailableCars();
// Make a reservation
const reservation = await reservationSystem.sakshMakeReservation(
availableCars[0]._id,
'userId123',
'John Doe',
'2024-09-10',
'2024-09-11',
100
);
console.log('Reservation made:', reservation);
// Add a review to the reservation
const review = await reservationSystem.sakshAddReview(
reservation._id,
availableCars[0]._id,
'userId123',
5,
'Great experience!'
);
console.log('Review added:', review);
// List reviews for the car
const reviews = await reservationSystem.sakshListReviews(null, availableCars[0]._id);
console.log('Reviews for the car:', reviews);
/*
// Modify the reservation
const modifiedReservation = await reservationSystem.sakshModifyReservation(
reservation._id,
'2024-09-05',
'2024-09-15'
);
console.log('Reservation modified:', modifiedReservation);
*/
// Cancel the reservation
// const canceledReservation = await reservationSystem.sakshCancelReservation(reservation._id);
// console.log('Reservation canceled:', canceledReservation);
// List all reservations
const reservations = await reservationSystem.sakshListReservations();
console.log('All Reservations:', reservations);
// Get reservation history for a user
const userReservations = await reservationSystem.sakshGetReservationHistory('userId123');
console.log('User Reservation History:', userReservations);
// Update payment status of a reservation
const updatedReservation = await reservationSystem.sakshUpdatePaymentStatus(reservation._id, 'paid');
console.log('Payment status updated:', updatedReservation);
// Search for reservations based on filters
const filters = {
minCharge: 50,
maxCharge: 150,
carType: 'Sedan',
startDate: '2024-09-01',
endDate: '2024-09-30',
location: 'New York'
};
const searchResults = await reservationSystem.sakshSearchReservations(filters);
console.log('Search Results:', searchResults);
// Generate daily reservation report
const dailyReport = await reservationSystem.sakshGenerateDailyReservationReport();
console.log('Daily Reservation Report:', dailyReport);
// Generate car utilization report
const utilizationReport = await reservationSystem.sakshGenerateCarUtilizationReport();
console.log('Car Utilization Report:', utilizationReport);
} catch (error) {
console.error('Error:', error);
}
Explanation
Connecting to MongoDB:
- The
sakshConnect
function is called to connect to the MongoDB database using the provided URI. This establishes a connection to the database, allowing the application to perform CRUD operations on the data.
- The
Adding a New Car:
- The
sakshAddCar
function is used to add a new car to the system. It takes parameters such as the car's make, model, and year, and stores this information in the database.
- The
Listing All Available Cars:
- The
sakshListAvailableCars
function retrieves and lists all cars that are currently available for reservation. This allows users to see which cars they can book.
- The
Making a Reservation:
- The
sakshMakeReservation
function allows users to reserve a car. It requires parameters such as the car ID, user ID, user name, start date, end date, and charge. Upon successful reservation, it creates a new reservation record in the database.
- The
Adding a Review:
- The
sakshAddReview
function enables users to add a review for a specific reservation. It takes parameters such as the reservation ID, car ID, user ID, rating, and review text, and stores this information in the database.
- The
Listing Reviews:
- The
sakshListReviews
function retrieves and lists all reviews associated with a specific car or reservation. This helps potential renters gauge the quality of the car based on previous users' experiences.
- The
Modifying a Reservation:
- The
sakshModifyReservation
function allows users to change the details of an existing reservation, such as the dates. It requires the reservation ID and the new start and end dates.
- The
Canceling a Reservation:
- The
sakshCancelReservation
function allows users to cancel a reservation that has not yet started. It takes the reservation ID as a parameter and removes the reservation from the database.
- The
Listing All Reservations:
- The
sakshListReservations
function retrieves and lists all reservations in the system. This is useful for administrators or users who want to see all current bookings.
- The
Getting Reservation History:
- The
sakshGetReservationHistory
function retrieves the reservation history for a specific user. It takes the user ID as a parameter and returns all past reservations made by that user.
- The
Updating Payment Status:
- The
sakshUpdatePaymentStatus
function updates the payment status of a reservation. It requires the reservation ID and the new payment status (e.g., 'paid', 'pending').
- The
Searching for Reservations:
- The
sakshSearchReservations
function allows users to search for reservations based on specific filters such as minimum and maximum charge, car type, date range, and location. This helps users find suitable reservations quickly.
- The
Generating Reports:
The functions
sakshGenerateDailyReservationReport
,sakshGenerateCarUtilizationReport
, andsakshGenerateUserActivityReport
generate various reports. These reports provide insights into daily reservations, how often cars are utilized, and user activity, respectively.
saksh-car-reservation-system Events
The saksh-car-reservation-system
module emits several events that can be used to handle notifications, logging, or other custom actions. Here are the details about each event:
Events Emitted
reservationMade
- Description: Emitted when a new reservation is successfully made.
- Payload: The reservation object.
- Usage:
reservationSystem.on('reservationMade', (reservation) => { console.log('New reservation made:', reservation); // Handle notification or other actions here });
reservationCanceled
- Description: Emitted when a reservation is successfully canceled.
- Payload: The canceled reservation object.
- Usage:
reservationSystem.on('reservationCanceled', (reservation) => { console.log('Reservation canceled:', reservation); // Handle notification or other actions here });
reservationModified
- Description: Emitted when a reservation is successfully modified.
- Payload: The modified reservation object.
- Usage:
reservationSystem.on('reservationModified', (reservation) => { console.log('Reservation modified:', reservation); // Handle notification or other actions here });
paymentStatusUpdated
- Description: Emitted when the payment status of a reservation is updated.
- Payload: The updated reservation object.
- Usage:
reservationSystem.on('paymentStatusUpdated', (reservation) => { console.log('Payment status updated:', reservation); // Handle notification or other actions here });
Example: Handling Events
Here's an example of how you can handle these events to send notifications or perform other actions:
const SakshCarReservationSystem = require('saksh-car-reservation-system');
// MongoDB connection URI
const dbUri = 'your_mongodb_uri';
// Initialize the reservation system
const reservationSystem = new SakshCarReservationSystem(dbUri);
// Connect to MongoDB
reservationSystem.sakshConnect().then(async () => {
try {
// Event listeners
reservationSystem.on('reservationMade', (reservation) => {
console.log('New reservation made:', reservation);
// Send notification to the user
sendNotification(reservation.userId, 'Your reservation has been made successfully.');
});
reservationSystem.on('reservationCanceled', (reservation) => {
console.log('Reservation canceled:', reservation);
// Send notification to the user
sendNotification(reservation.userId, 'Your reservation has been canceled.');
});
reservationSystem.on('reservationModified', (reservation) => {
console.log('Reservation modified:', reservation);
// Send notification to the user
sendNotification(reservation.userId, 'Your reservation has been modified.');
});
reservationSystem.on('paymentStatusUpdated', (reservation) => {
console.log('Payment status updated:', reservation);
// Send notification to the user
sendNotification(reservation.userId, 'The payment status of your reservation has been updated.');
});
// Example functions to demonstrate usage
await reservationSystem.sakshAddCar('Toyota', 'Camry', 2021);
const availableCars = await reservationSystem.sakshListAvailableCars();
const reservation = await reservationSystem.sakshMakeReservation(
availableCars[0]._id,
'userId123',
'John Doe',
'2024-09-01',
'2024-09-10',
100
);
} catch (error) {
console.error('Error:', error);
}
});
// Example notification function
function sendNotification(userId, message) {
// Implement your notification logic here (e.g., email, SMS, push notification)
console.log(`Notification sent to user ${userId}: ${message}`);
}
Summary of Events
- reservationMade: Triggered when a new reservation is made.
- reservationCanceled: Triggered when a reservation is canceled.
- reservationModified: Triggered when a reservation is modified.
- paymentStatusUpdated: Triggered when the payment status of a reservation is updated.
These events allow you to hook into the reservation system's lifecycle and perform custom actions such as sending notifications, logging activities, or updating other systems.
License
This project is licensed under the MIT License. This means you are free to use, modify, and distribute the software, provided that the original license and copyright notice are included in all copies or substantial portions of the software.
For more details, please refer to the LICENSE file in the repository.
Support
For any questions, issues, or support related to the Saksh Car Reservation System, please reach out via email:
Email: [email protected]
We appreciate your feedback and are here to help you with any inquiries you may have!