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

Calculate Next Purchase Date #31

Merged
merged 9 commits into from
Mar 10, 2024
Merged

Calculate Next Purchase Date #31

merged 9 commits into from
Mar 10, 2024

Conversation

DevinaG007
Copy link
Collaborator

Description

  • Created a function getDaysBetweenDates in dates.js to use with calculateEstimate
  • Imported calculateEstimate from @the-collab-lab/shopping-list-utils module
  • Created a helper function in firebase.js to calculate the nextPurchaseDate for an item
  • Passed in the new estimate to the nextPurchaseDate inside of the updateItem function in firebase.js

Related Issue

closes #11

Acceptance Criteria

  • When the user purchases an item, the item’s dateNextPurchased property is calculated using the calculateEstimate function and saved to the Firestore database
    • dateNextPurchased is saved as a date, not a number
  • A getDaysBetweenDates function is exported from utils/dates.js and imported into api/firebase.js
    • This function takes two JavaScript Dates and returns the number of days that have passed between them

Type of Changes

New Feature

Updates

Before

No changes to UI were made, no images can be provided for our changes.

Testing Steps / QA Criteria

  1. Open the test deployment link below
  2. In another tab, login to Firebase Console, and access the database
  3. Navigate to collection 'asPkEDijgrgtrBRQ7U5jgbiKW6w1', select dinner and then select items
  4. Select cheesecake item (6XjfJylrF2P2B3PHQEy5)
  5. Take note of the currentdateNextPurchased and the most recent dateLastPurchased
  6. "Purchase" cheesecake by clicking the checkbox in the deployed testing application
  7. Note changes in dateNextPurchased, verify that nextPurchaseDate is updated to a future date based on estimate.
  8. Repeat same proccess with tiramisu (3vR3UKTe6OkoRzxIW4C8).

calculateEstimate works by weighing the number of purchases and the previous estimate against the time since last purchased. For example, the higher the number of total purchases is, the more the new estimate will be based off of previous purchases.

If you would like a better understanding of how the calculateEstimate function works, check out this source on calculateEstimate

Sorry, something went wrong.

Copy link

github-actions bot commented Mar 8, 2024

Visit the preview URL for this PR (updated for commit d721a14):

https://tcl-68-smart-shopping-list--pr31-dg-sm-calculate-next-ldwgepl1.web.app

(expires Sun, 17 Mar 2024 13:41:10 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 8cb5d089a99ba9972009993f4dd31796b0cbda84

etiry
etiry previously approved these changes Mar 9, 2024
Copy link
Collaborator

@etiry etiry left a comment

Choose a reason for hiding this comment

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

Another complicated issue tackled well, great job!

src/api/firebase.js Outdated Show resolved Hide resolved
src/api/firebase.js Show resolved Hide resolved
src/api/firebase.js Show resolved Hide resolved
src/api/firebase.js Outdated Show resolved Hide resolved
@DevinaG007 DevinaG007 requested a review from raaynaldo March 9, 2024 18:05
andiedoescode
andiedoescode previously approved these changes Mar 9, 2024
Copy link
Collaborator

@andiedoescode andiedoescode left a comment

Choose a reason for hiding this comment

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

Looking good! Congrats on the continuation of a tough issue!

src/api/firebase.js Show resolved Hide resolved
src/api/firebase.js Show resolved Hide resolved
src/api/firebase.js Show resolved Hide resolved
src/utils/dates.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@raaynaldo raaynaldo left a comment

Choose a reason for hiding this comment

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

Great job! Looks good to me

@sdmisra sdmisra merged commit 8e943e5 into main Mar 10, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants