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

Resolves Issue #10 (#32) - Estimate Next Purchase Date #55

Merged
merged 7 commits into from
Mar 8, 2020

Conversation

mjhcodes
Copy link
Contributor

@mjhcodes mjhcodes commented Mar 5, 2020

Issue #32

Task

The main purpose of this issue was to calculate the number of days until the next purchase date and store it in the database

Actions

  • Created new state for the Number of Purchases and the Last Estimate, which are included with the other data when an item is added to the database
  • Set the number of seconds in a day (86400) as a constant for use in multiple parts of the code
  • Expanded the onChange to check if the item has already been purchased - if so, enters the purchase date for the first time and increments the number of purchases from zero to one
  • If not, creates a new Last Estimate value based on user provided estimate (if 1st time through) or based on a calculated Next Purchase Date; also determines the most recent interval between purchases for the item; continues to increment by one each time through

Notes

The date of the next purchase is calculated by a provided script - estimates.js

It's largely possible this solution could be heavily refactored, but due to time constraints, we're comfortable submitting what at least appears to be working successfully. :-)

@mjhcodes mjhcodes changed the title Resolves Issue #32 - Estimate Next Purchase Date Resolves Issue #10 (#32) - Estimate Next Purchase Date Mar 5, 2020
Copy link
Contributor

@haleyelder haleyelder left a comment

Choose a reason for hiding this comment

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

Major props to refactoring and setting up all these calculations! I'm hoping we can have a small demo this Sunday since there is quite a bit going on with the calculations and looks pretty good

Copy link
Contributor

@haleyelder haleyelder left a comment

Choose a reason for hiding this comment

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

already left my review but i guess changing the title removed it...

.update({ datePurchased });
console.log(dbItems);
// Checks if a purchase date already exists - if not, creates a purchased date and increments # of purchases - if so, also sets the most recent purchase estimate, the most recent purchase interval and the calculated date of the next purchase
const handleChange = (e, item) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome! I love that you're passing in the item here. This makes it really easy to keep track of which item they selected.

let latestInterval = Math.floor(
(datePurchasedInSeconds - lastDatePurchased.seconds) / HOURS24
);
let db = firebase.fb.firestore();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious, do you think that this could be defined outside of this function? That way we don't have to create it every time this handler function is called.

(datePurchasedInSeconds - lastDatePurchased.seconds) / HOURS24
);
let db = firebase.fb.firestore();
let nextPurchaseDate = calculateEstimate(
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 I love that this logic is split up into a separate function. It helps me follow what's going on!

let db = firebase.fb.firestore();
db.collection(token)
.doc(e.target.value)
.update({ datePurchased, numOfPurchases: item.numOfPurchases + 1 });
Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no datePurchased, will numOfPurchases always be 0, so we always send 1 here?

Copy link
Contributor

@msholty-fd msholty-fd left a comment

Choose a reason for hiding this comment

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

🏅 Very good PR!

The best part about this PR is how well you outlined your intent of the PR in the description. I'll be mentioning this on our next call as a model way to do it!

Copy link

@rmorabia rmorabia 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, y'all! This is amazing work.

.doc(e.target.value)
.update({ datePurchased });
console.log(dbItems);
// Checks if a purchase date already exists - if not, creates a purchased date and increments # of purchases - if so, also sets the most recent purchase estimate, the most recent purchase interval and the calculated date of the next purchase
Copy link

Choose a reason for hiding this comment

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

Small note, move this into a multi-line comment instead of making the whole thing one line. Harder to read this way!

@jcwesley93 jcwesley93 merged commit a2c2091 into master Mar 8, 2020
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.

5 participants