-
Notifications
You must be signed in to change notification settings - Fork 449
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
add task solution #240
base: master
Are you sure you want to change the base?
add task solution #240
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work 👍
Let's fix one moment
src/utils/getPreparedExpenses.js
Outdated
const getPreparedExpenses = (query, expenses) => { | ||
if (!query) { | ||
return expenses; | ||
} | ||
|
||
const { userId, categories, from, to } = query; | ||
let preparedExpenses = [...expenses]; | ||
|
||
if (userId) { | ||
preparedExpenses = expenses.filter( | ||
(expense) => expense.userId === Number(userId), | ||
); | ||
} | ||
|
||
if (categories) { | ||
preparedExpenses = expenses.filter( | ||
(expense) => expense.category === categories, | ||
); | ||
} | ||
|
||
if (from && to) { | ||
const startDate = new Date(from); | ||
const endDate = new Date(to); | ||
|
||
preparedExpenses = expenses.filter((expense) => { | ||
const currentDate = new Date(expense.spentAt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to filter them, just query from the database what you actually need instead of all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, I'm approving it🔥
No description provided.