Skip to content

Commit

Permalink
fit: add activity age guard
Browse files Browse the repository at this point in the history
  • Loading branch information
hellos3b committed Jan 9, 2024
1 parent b95ed58 commit b0e124d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/fitness/src/LoggedWorkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ const isInactive = (user) => {
return isAfter(limit, lastActive);
};

const isTooOld = (activity) => {
const started = new Date(activity.start_date);
const age = differenceInHours(new Date(), started);
return age > 48;
};

// -- strava api

const fetchToken = (refreshToken) =>
Expand Down Expand Up @@ -283,13 +289,11 @@ const postWorkout = (discord, db) => async (stravaId, activityId) => {
}

const [activity, streams] = data;
const started = new Date(activity.start_date);
const age = differenceInHours(new Date(), started);
// if (age > 48) {
// return new Error(
// `Activity is too old (${age} hours). It was started ${started.toLocaleDateString()} and today is ${new Date().toLocaleDateString()}`
// );
// }
if (isTooOld(activity)) {
return new Error(
`Activity is too old. It was started ${started.toLocaleDateString()} and today is ${new Date().toLocaleDateString()}`
);
}

const workouts = loggedWorkoutCollection(db);
const workout = workoutFromActivity(user, activity, streams);
Expand Down

0 comments on commit b0e124d

Please sign in to comment.