Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Event Booking APIs #378

Merged
merged 8 commits into from
Oct 22, 2024

Conversation

haseebzaki-07
Copy link
Contributor

@haseebzaki-07 haseebzaki-07 commented Oct 21, 2024

fixes #363

This PR adds necessary routes and controllers for a user to book any event, get his all event bookings.
Updated the schema of user and events so that a user can be associated with multiple events also the events can be associated by multiple users.

Upadated the method of delete route from "get" to "delete" because it was a bug also associated "/:id" for the specific event to be deleted.

route to book event:

Screenshot 2024-10-21 215741

route to get all bookings of a user:

Screenshot 2024-10-21 215916

route to create an event:

Screenshot 2024-10-21 214529

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced event booking functionality allowing customers to book events and retrieve their booked events.
    • Added new routes for booking events and retrieving booked events by customer ID.
  • Enhancements

    • Updated the contributor list in the README to reflect new contributors.
    • Added fields to the customer and event models to track booked events and associated customers.
  • Bug Fixes

    • Improved error handling in the event booking and retrieval processes.

Copy link

vercel bot commented Oct 21, 2024

@github-actions[bot] is attempting to deploy a commit to the bunty's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve updates to the README.md file to modify the contributors list, as well as significant enhancements to the event booking functionality in the backend. New methods for booking events and retrieving booked events have been added to the event controller, along with corresponding updates to the customer and event models to accommodate these features. Additionally, the event router has been modified to include new API routes for booking and retrieving events.

Changes

File Change Summary
README.md Removed contributor "Nikhil More" and added new contributors: "Bashua Mutiat," "Mohit Rana," "Jai Dhingra," "Dev Mishra," "CHIKATLA RAKESH."
backend/controller/event.controller.js Added methods bookEvent and getBookedEvents, updated module exports to include these methods.
backend/models/customer.model.js Added field bookedEvents to customerSchema to reference booked events.
backend/models/events.model.js Added field bookedCustomers to eventSchema to reference customers who booked the event.
backend/routes/eventRouter.js Added routes for booking events (/book-events) and retrieving booked events (/get-booked-events/:customerId), updated DELETE route to require an ID.

Assessment against linked issues

Objective Addressed Explanation
Implement booking slots for events (#363)
Ensure confirmation message for bookings (#363)
Associate user with booking in the database (#363)

Possibly related PRs

Poem

🐇 In the meadow where events bloom,
New friends join, dispelling gloom.
With bookings made and joy in sight,
Hop along, everything feels right!
Let's cheer for changes, big and small,
Together we can have a ball! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

PORT=3000
EMAIL_PASS=your_16_digit_pass
JWT_SECRET=secret
GOOGLE_CLIENT_ID=your_google_client_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you delete @haseebzaki-07

const mongoose = require("mongoose");
const { string } = require("zod");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haseebzaki-07 is required or not

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (5)
backend/models/customer.model.js (1)

29-32: LGTM! Consider adding an index for performance.

The implementation of the bookedEvents field is correct and aligns with the PR objectives. It effectively establishes a many-to-many relationship between customers and events.

Consider the following improvements:

  1. Add an index to the bookedEvents field to enhance query performance, especially as the dataset grows:
    bookedEvents: [{
      type: Schema.Types.ObjectId,
      ref: "Event",
      index: true
    }],
  2. Implement a custom validator to ensure unique event bookings per customer:
    validate: [arrayLimit, '{PATH} exceeds the limit of unique events']
    Then, define the arrayLimit function:
    function arrayLimit(val) {
      return new Set(val).size === val.length;
    }

These suggestions can improve performance and data integrity but are not critical for the current implementation.

backend/models/events.model.js (2)

39-42: LGTM! Consider adding validation for consistency.

The addition of the bookedCustomers field is well-implemented and aligns with the PR objectives. It correctly establishes a many-to-many relationship between events and customers.

For consistency with other fields in the schema, consider adding a required property set to false (assuming it's optional) and a default value of an empty array. This would make the field's behavior more explicit:

 bookedCustomers: [{
   type: mongoose.Schema.Types.ObjectId,
   ref: 'Customer' // Reference to the Customer model
-  }]
+  }],
+  required: false,
+  default: []
 }

Line range hint 15-22: Consider using Date type for improved data handling

While the current implementation of date and time as strings is functional, consider using native Date types for these fields. This change could provide better data integrity and enable easier querying and sorting of events.

Here's a suggested improvement:

 date: {
-  type: String,
+  type: Date,
   required: true,
 },
 time: {
-  type: String,
+  type: Date,
   required: true,
 },

If you decide to implement this change, remember to update any related controllers or services that interact with these fields to handle Date objects instead of strings.

backend/routes/eventRouter.js (1)

1-2: Consider using a proper logging mechanism instead of console.log.

While console.log can be useful for debugging during development, it's generally not recommended for production code. Consider using the existing logger (imported from "../config/logger") for consistency and better control over log levels.

You could replace the console.log with:

-console.log("eventRouter loaded");
+logger.info("eventRouter loaded");
backend/controller/event.controller.js (1)

74-74: Standardize parameter retrieval for consistency

In bookEvent, customerId and eventId are retrieved from req.body, whereas in getBookedEvents, customerId is retrieved from req.params. For consistent API design, consider using the same method of parameter retrieval in both functions.

If you choose to retrieve IDs from req.params in both functions, adjust the code and routes accordingly.

Also applies to: 103-103

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 23a9149 and 13f2427.

📒 Files selected for processing (7)
  • README.md (0 hunks)
  • backend/.env.example (0 hunks)
  • backend/controller/event.controller.js (2 hunks)
  • backend/index.js (1 hunks)
  • backend/models/customer.model.js (1 hunks)
  • backend/models/events.model.js (1 hunks)
  • backend/routes/eventRouter.js (3 hunks)
💤 Files with no reviewable changes (2)
  • README.md
  • backend/.env.example
🧰 Additional context used
🔇 Additional comments (6)
backend/routes/eventRouter.js (2)

10-11: LGTM: New controller methods imported correctly.

The new methods bookEvent and getBookedEvents have been properly imported from the event controller. This aligns with the PR objectives of implementing event booking functionality.


36-36: LGTM: Delete route corrected and improved.

The delete route has been correctly updated to use the DELETE HTTP method and now includes an ID parameter. This change allows for deleting specific events and aligns with the PR objectives.

backend/index.js (3)

6-6: Clarify the purpose of the added comment.

The comment "// Corrected typo" has been added, but it's not clear what typo was corrected. The import statement for 'passport' on the next line appears unchanged. Could you please clarify the purpose of this comment or remove it if it's no longer relevant?


Line range hint 1-70: Overall structure and configuration look good.

Apart from the issues mentioned above, the rest of the file is well-structured and properly configured for an Express.js application. It includes necessary imports, middleware setup, database connection, route definitions, and error handling. The changes made don't affect the overall functionality of the application.


9-9: ⚠️ Potential issue

Fix typo in errorMiddleware import path.

The import statement for errorMiddleware has been changed, but it appears to introduce a typo rather than correct one. The path now includes an extra 'r' in "error".

Please apply this correction:

-const errorMiddleware = require("./middlewares/errrorMiddleware");
+const errorMiddleware = require("./middlewares/errorMiddleware");

Also, consider moving the "Corrected typo" comment to this line if it was intended for this change.

To ensure the correct file exists, please run:

backend/controller/event.controller.js (1)

2-2: LGTM

The import of the Customer model is correctly added to support the new booking functionality.

Comment on lines 24 to 25
bookEvents : "/event/book-event",
GetBookedEvents : "/event/get-booked-events/:customerId",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Approve changes, but correct the booking events endpoint.

The new endpoints for booking events and getting booked events have been correctly added to the API information. However, there's a minor inconsistency in the booking events endpoint.

Please update the booking events endpoint to match the actual route path:

-        bookEvents : "/event/book-event",
+        bookEvents : "/event/book-events",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
bookEvents : "/event/book-event",
GetBookedEvents : "/event/get-booked-events/:customerId",
bookEvents : "/event/book-events",
GetBookedEvents : "/event/get-booked-events/:customerId",

backend/routes/eventRouter.js Show resolved Hide resolved
backend/controller/event.controller.js Show resolved Hide resolved
backend/controller/event.controller.js Outdated Show resolved Hide resolved
backend/controller/event.controller.js Outdated Show resolved Hide resolved
@haseebzaki-07
Copy link
Contributor Author

hey @RamakrushnaBiswal made the necessary changes and brought back the .env.example

Copy link

vercel bot commented Oct 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
play-cafe ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2024 7:01am

@RamakrushnaBiswal RamakrushnaBiswal merged commit b8aaa36 into RamakrushnaBiswal:main Oct 22, 2024
1 of 2 checks passed
@RamakrushnaBiswal RamakrushnaBiswal added enhancement New feature or request level3 for 45 points gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo level3 for 45 points
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Book your slot for event
2 participants