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

Develop #269

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

Develop #269

wants to merge 4 commits into from

Conversation

ekateriina7
Copy link

No description provided.

Comment on lines 29 to 55
let filteredExpenses = expenses;

if (userId !== null) {
filteredExpenses = filteredExpenses.filter(
(expense) => expense.userId === userId,
);
}

if (from && to) {
filteredExpenses = filteredExpenses.filter((expense) => {
const spentAt = new Date(expense.spentAt);

return spentAt >= from && spentAt <= to;
});
}

if (categories.length > 0) {
filteredExpenses = filteredExpenses.reduce((acc, expense) => {
if (categories.includes(expense.category)) {
acc.push(expense);
}

return acc;
}, []);
}

return filteredExpenses;

Choose a reason for hiding this comment

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

Controllers are just the entry point for requests and are responsible for sending back the response to the client. Services, on the other hand, contain the business logic. So move business logic to services

Comment on lines +5 to +7
const normalize = ({ id, name }) => {
return { id, name };
};

Choose a reason for hiding this comment

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

why do you need this function

Copy link
Author

Choose a reason for hiding this comment

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

to not return to client other fields like created_at, as was suggested in video lesson

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.

2 participants