Skip to content

Create food for utsav#278

Open
pallavisavla wants to merge 12 commits into
devfrom
create_food_for_utsav
Open

Create food for utsav#278
pallavisavla wants to merge 12 commits into
devfrom
create_food_for_utsav

Conversation

@pallavisavla
Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Utsav management system by seamlessly integrating food booking and cancellation capabilities. The changes ensure that when an Utsav package is booked or cancelled, the corresponding food arrangements are automatically managed, streamlining the process for both administrators and users. This update improves the overall efficiency and completeness of Utsav event management.

Highlights

  • Food Booking Integration: Introduced new functionality to automatically book and cancel food for Utsav participants based on their Utsav package bookings.
  • New Helper Functions: Added bookFoodForAllMeals and cancelAllMeals in foodBooking.helper.js to manage food bookings for a range of dates, and bookFoodForUtsav and cancelUtsavFoodBookings in utsavBooking.helper.js to integrate with Utsav logic.
  • Utsav Booking Flow Updates: Modified admin and client Utsav booking and cancellation controllers to incorporate the new food booking and cancellation logic.
  • Cron Job Schedule Change: Adjusted the cron job schedule from running every 30 minutes to every minute and integrated food booking cancellation into the cron-triggered booking cancellation process.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • controllers/admin/utsavManagement.controller.js
    • Imported new food booking and cancellation helper functions.
    • Removed the import for adminCancelTransaction.
    • Added logic to automatically book food when an Utsav booking is confirmed.
    • Implemented logic to cancel food bookings when an Utsav booking is cancelled.
  • controllers/client/utsavBooking.controller.js
    • Imported the cancelUtsavFoodBookings helper function.
    • Integrated food booking cancellation into the client-initiated Utsav cancellation process.
  • cron.js
    • Imported the cancelUtsavFoodBookings helper function.
    • Changed the cron job schedule from '*/30 * * * ' to ' * * * *'.
    • Added logic to cancel food bookings when Utsav bookings are cancelled by the cron job.
  • helpers/foodBooking.helper.js
    • Introduced bookFoodForAllMeals to create or update food bookings for all meals over a specified date range.
    • Added cancelAllMeals to set breakfast, lunch, and dinner quantities to zero for food bookings within a given date range.
  • helpers/utsavBooking.helper.js
    • Imported bookFoodForAllMeals and cancelAllMeals from foodBooking.helper.js.
    • Created bookFoodForUtsav to encapsulate the logic for booking food based on Utsav package details.
    • Created cancelUtsavFoodBookings to handle the cancellation of food bookings associated with an Utsav booking.
    • Integrated bookFoodForUtsav into the bookUtsavForMumukshus function to automatically book food upon Utsav registration.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces functionality to book and cancel food for Utsav bookings. The changes are spread across controllers, helpers, and a cron job. My review has identified a critical issue with a call to a non-existent bulkUpdate method which will cause a runtime error. I've also found a few medium to high severity issues, including a potentially problematic change to a cron job's frequency, performance improvements for database updates, a missing null check that could lead to an error, and a fragile date comparison. I've provided suggestions to fix these issues.

I am having trouble creating individual review comments. Click here to see my feedback.

helpers/foodBooking.helper.js (595-597)

critical

FoodDb.bulkUpdate is not a standard Sequelize method and will cause a runtime error. To update multiple model instances that have been modified in memory, you should iterate through them and save each one. Using Promise.all is an efficient way to do this concurrently.

  if (bookingsToUpdate.length > 0) {
    await Promise.all(bookingsToUpdate.map(booking => booking.save({ transaction: t })));
  }

cron.js (40)

high

The cron job schedule has been changed from running every 30 minutes to every minute. This is a 30x increase in frequency which could lead to significant performance degradation and system load in a production environment. Please revert this change if it was intended only for testing purposes.

const job = cron.schedule('*/30 * * * *', async () => {

helpers/foodBooking.helper.js (604-626)

medium

The current implementation of cancelAllMeals first fetches all food bookings and then iterates through them to cancel one by one. This is inefficient as it results in N+1 database queries (1 SELECT + N UPDATEs). This can be optimized to a single UPDATE query without fetching the records first.

  const allDates = getDates(start_date, end_date);
  const updateFields = {
    breakfast: 0,
    lunch: 0,
    dinner: 0,
    updatedBy: updatedBy
  };

  await FoodDb.update(updateFields, {
    where: {
      cardno: cardno,
      date: allDates
    },
    transaction: t
  });

helpers/utsavBooking.helper.js (116-118)

medium

Comparing dates by converting them to strings via new Date().toDateString() can be fragile and might behave unexpectedly depending on the server's timezone. Since package_info.end_date and utsav.end_date are DATEONLY fields, they are returned as 'YYYY-MM-DD' strings. A direct string comparison is more robust and simpler.

  const lastDayOnlyBreakfast = package_info.end_date === utsav.end_date;

helpers/utsavBooking.helper.js (557-558)

medium

If UtsavPackagesDb.findOne returns null, utsavPackage will be null, and accessing utsavPackage.start_date on the next line will throw a TypeError. It's important to add a null check to handle cases where the package might not be found.

  if (utsavPackage) {
    await cancelAllMeals(utsavPackage.start_date, utsavPackage.end_date, booking.cardno, updatedBy, t);
  }

Comment thread config/constants.js
export const ERR_ADHYAYAN_NOT_COMPLETED =
'Cannot submit feedback for ongoing or future adhyayan';

export const ERR_UTSAV_NO_SEATS_AVAILABLE = 'No seats available for this utsav';
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was missing and i found it while testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants