0% found this document useful (0 votes)
12 views3 pages

Angular Car Rental System Guide

The document outlines the steps to build a car rental management system, including project initialization, schema creation for cars and bookings, and API development for managing bookings. It specifies data fields for car and booking models, as well as requirements for payment calculation and project organization following the Model-View-Controller-Routes structure. Submission requires all source files and the package.json file for the completed project.

Uploaded by

aeskychung
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Angular Car Rental System Guide

The document outlines the steps to build a car rental management system, including project initialization, schema creation for cars and bookings, and API development for managing bookings. It specifies data fields for car and booking models, as well as requirements for payment calculation and project organization following the Model-View-Controller-Routes structure. Submission requires all source files and the package.json file for the completed project.

Uploaded by

aeskychung
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Car Rental Management System

Description
You are tasked with building a car rental management system. The system will store
information about cars, their statuses, customer details, and handle car booking and
payment operations. Follow the steps below to complete the assignment.

Step 1: Project Initialization


1. Create a New Project Directory:
Create a new directory named <yourName>_carRental (for example,
john_carRental).
2. Initialize a [Link] Project:
3. Install Required Libraries:
Install necessary packages such as Express and Mongoose:
Step 2: Create Schema and Model for Car
1. File: [Link]
2. Car Data Fields:
o carNumber (String): The car's license plate number or unique car ID.

o capacity (Number): The seating capacity or load capacity of the car.

o status (String): The car's status. Possible values: "available", "rented",


"maintenance".
o pricePerDay (Number): Rental price per day.

o features (Array): A list of car features/amenities.

Example Data: json


{
"carNumber": "51A-12345",
"capacity": 7,
"status": "available",
"pricePerDay": 500000,
"features": ["automatic", "air-conditioner", "GPS"]
}
Requirement:
Define a CarSchema and export the Car model for MongoDB.
Step 3: Create Schema and Model for Booking
1. File: [Link]
2. Booking Data Fields:
o customerName (String): The customer's name.

o carNumber (String): The car number (or car ID) that is booked.

o startDate (Date): The start date of the rental period.

o endDate (Date): The end date of the rental period.

o totalAmount (Number): The total payment amount.

Example Data: json


{
"customerName": "Nguyen Van A",
"carNumber": "51A-12345",
"startDate": "2023-10-01T00:00:00.000Z",
"endDate": "2023-10-03T00:00:00.000Z",
"totalAmount": 1000000
}
Requirement:
Define a BookingSchema and export the Booking model.
Step 4: Build APIs for Managing Bookings
Implement the following RESTful API endpoints:
4.1 GET /bookings
 Function: Retrieve the list of all car bookings.
4.2 POST /bookings
 Function: Create a new booking.
 Logic:
When creating a booking, validate the startDate and endDate. If the booking
dates overlap with another booking for the same carNumber, handle the
conflict appropriately (reject the booking or apply custom logic).
4.3 PUT /bookings/:bookingId
 Function: Update an existing booking by its bookingId.
4.4 DELETE /bookings/:bookingId
 Function: Delete a booking by its bookingId.
4.5 Payment Calculation
 Requirement:
The system must automatically calculate the totalAmount based on the
number of days booked and the pricePerDay of the car.
The number of rental days can be calculated as: (endDate - startDate) / (1000
* 60 * 60 * 24) (Round the result as per the specific requirement.)
Retrieve the pricePerDay from the Car model based on the carNumber.
Step 5: Organize the Project According to the Model-View-Controller-
Routes (MVCR) Structure
1. Organization:
Separate your project files into folders:
o Models: Contain [Link], [Link], etc.

o Views: Contain EJS files that can call apis

o Controllers: Implement the business logic for handling bookings,


payment calculation, etc. (e.g., [Link], [Link]).
o Routes: Define API endpoints that map to the corresponding controller
functions (e.g., [Link], [Link]).
Submission Requirements
 Source Files:
Submit the complete [Link] file and all source code files, including
[Link], [Link], controller files, route files, etc.

Common questions

Powered by AI

Dynamic data retrieval allows the system to adapt to changes without requiring updates to hardcoded values. Fetching 'pricePerDay' directly during booking calculations ensures that the system always uses the latest pricing information, accommodating adjustments such as price fluctuations or promotional offers. This approach enhances flexibility, as modifications to car pricing are automatically reflected in real-time transactional operations, reducing manual intervention and potential for errors .

It is necessary to round the calculation of rental days because the difference between endDate and startDate may not precisely align with full-day increments, possibly due to partial day overlaps. Rounding ensures that the rental period corresponds accurately to whole days for which the customer will be billed. Not rounding appropriately may lead to undercharging or overcharging the customer, affecting the accuracy and fairness of the total payment calculation .

When defining 'pricePerDay' in the Car model, considerations should include market competition analysis, operational costs, desired profit margin, and customer affordability. Additionally, pricing should reflect the car's value and attributes, like model and features, to ensure competitive pricing and profitability. It's crucial to consider demand variability and adjust prices dynamically based on factors such as peak seasons or availability .

Separating the project files according to the Model-View-Controller-Routes (MVCR) structure helps in organizing the codebase. Models contain the data schema and manage data interaction; views handle user interface elements; controllers implement the business logic, such as handling bookings and payment calculations; and routes define API endpoints linking to controller functions. This separation enhances maintainability, scalability, and readability of the code .

Using Express streamlines the development process by providing a robust framework for building web applications with predefined server capabilities, such as routing and middleware. Mongoose simplifies MongoDB management, offering tools for data schema design, validation, and querying. Together, they enhance system efficiency, allowing developers to focus on business logic rather than setting up fundamental infrastructure, thereby speeding up development while ensuring a scalable, efficient backend for the car rental management system .

Middleware functions play a critical role in RESTful APIs by processing requests and responses between the client and the server, applying logic such as authentication, logging, and error-handling. In a car rental management system, middleware can ensure that each API request is authenticated, log booking transactions for auditing purposes, and uniformly handle errors across different endpoints, improving the system's robustness and security .

In designing the 'GET /bookings' endpoint, strategies could include implementing efficient database queries using indexed fields to rapidly retrieve booking data, paginating results to manage large datasets, applying filtering and sorting to allow users to easily navigate bookings, and using caching mechanisms to store frequent query results for faster retrieval. These strategies enhance system performance and scalability .

When creating a new booking, the system should validate the startDate and endDate against existing bookings for the same carNumber. If the new booking dates overlap with any existing booking, the system must handle the conflict by either rejecting the booking or applying custom logic to resolve the overlap. This ensures that a car is not double-booked for the same dates .

Defining a schema for cars and bookings ensures that data integrity is maintained by enforcing consistent data types and required fields for storing records in the database. For example, car schema fields like carNumber, capacity, status, pricePerDay, and features must adhere to specified data types and rules, preventing corrupt or malformed data entries. Similarly, booking schema fields such as customerName, carNumber, startDate, endDate, and totalAmount follow specific formats to ensure proper data relationships and validation .

When installing libraries for a Node.js project like the car rental management system, developers should consider factors such as ensuring compatibility with the Node.js version, choosing libraries that adequately meet the project's functional requirements (e.g., Express for handling HTTP requests, Mongoose for MongoDB interaction), the library's community support and maintenance status, and potential security vulnerabilities that could affect the application .

You might also like