refactor(api): replace TimeFrame middleware with time schema utility #714
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
Description
Simplifies the timeframe input. Previously, we were using a middleware probably because of the need to transform the input to a date, now we are using the
zod
schema directly to transform the input to a date.Previously, the input value
All
was permitted but not processed correctly (check theparseInt
, it was creatingNaN
).The old logic returned a date range where the end date was always set to the end of yesterday and the start date was calculated as (end date minus the number of days). This approach caused issues particularly when handling single-day ranges, requiring special case handling. Now, instead of returning a range with a fixed end date, we simply return a timestamp calculated as the current time minus the number of days in milliseconds. This makes the logic simpler and more consistent across all cases.