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

Updating dateNextPurchased with smart calculation of new date #33

Merged
merged 9 commits into from
Sep 15, 2024

Conversation

bbland1
Copy link
Collaborator

@bbland1 bbland1 commented Sep 11, 2024

Description

  • Created getDaysBetweenDates function taking 2 dates as parameters to calculate the whole number of days between dates.
  • Updated the firebase api to utilize the getDaysBetweenDates and calculateEstimate functions to use the items previous dateNextPurchase, totalPurchases and a calculated daysSinceLastPurchased to determine a new estimated dateNextPurchased.
  • Updating the database the new dateNextPurchased to store for future reference.

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 return the number of days that have passed between them

Type of Changes

Type
💯 Enhancement
✨ New Feature

Updates

No screenshots, focused on API changes that apply updates to the DB.

Testing Steps / QA Criteria

  • From your terminal, pull down this branch with git pull origin bb-rc/update-next-purchase-date and check that branch out with git checkout bb-rc/update-next-purchase-date
  • Then npm ci to install the newly added dependencies locally and npm start to launch the app.
  • Add some testing console.logs above the variable updates on firebase.ts line 280.
	console.log("item date last purchased:", item.dateLastPurchased?.toDate());
	console.log("previous estimate:", previousEstimate);
	console.log("Original next purchase date:", item.dateNextPurchased.toDate());
	console.log("New Next Purchase Date!", newDateNextPurchased);
  • Log in to the application
  • Open the browser console
  • Click a list, and click List in the nav bar to navigate to
  • Check off an item to be marked as purchased.
  • View the console.logs or the firebase if you have access to verify the changes in dateNextPurchase

Copy link

github-actions bot commented Sep 11, 2024

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

https://tcl-77-smart-shopping-list--pr33-bb-rc-update-next-pu-qbfc9v9o.web.app

(expires Sun, 22 Sep 2024 18:59:48 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b77df24030dca7d8b6561cb24957d2273c5e9d72

@bbland1 bbland1 added enhancement New feature or request new feature labels Sep 11, 2024
@bbland1 bbland1 marked this pull request as ready for review September 11, 2024 20:44
@bbland1 bbland1 changed the title created getDaysBetweenDates function Updating dateNextPurchased with smart calculation of new date Sep 11, 2024
Copy link
Collaborator

@alex-andria alex-andria left a comment

Choose a reason for hiding this comment

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

Great work y'all! Good use of the importing of utils and functions provided while also doing the math for getDaysBetweenDates. I know back when I had worked on this card I had a hard time wrapping my head around the Timestamp dates by firebase needing to be converted with toDate() for JS/TS. This is very clean!

My only suggestion is to remove the console and maybe paste it as a test case instruction in your PR for code reviewers to test in local. I understand the intention, and do love that you two thought that out to make it easier for us to test rather than calculate manually after reviewing firebase! However we shouldn't push console logs to production (just main in our case haha).

src/api/firebase.ts Outdated Show resolved Hide resolved
@bbland1 bbland1 dismissed alex-andria’s stale review September 15, 2024 19:04

The console.logs have been removed before pushing to main

@bbland1 bbland1 merged commit 5ea939b into main Sep 15, 2024
2 checks passed
@bbland1 bbland1 deleted the bb-rc/update-next-purchase-date branch September 15, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new feature
Projects
None yet
5 participants