npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

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.

saksh-car-reservation-system

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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').
  12. 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.
  13. Generating Reports:

    • The functions sakshGenerateDailyReservationReport, sakshGenerateCarUtilizationReport, and sakshGenerateUserActivityReport 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

  1. 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
      });
  2. 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
      });
  3. 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
      });
  4. 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!