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

add task solution #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

hattoriKanto
Copy link

No description provided.

Copy link

@BudnikOleksii BudnikOleksii left a 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

Comment on lines 1 to 26
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);

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

Copy link

@StasSokolov1 StasSokolov1 left a 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🔥

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.

3 participants