-
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
Develop #269
base: master
Are you sure you want to change the base?
Develop #269
Conversation
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; |
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.
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
const normalize = ({ id, name }) => { | ||
return { id, name }; | ||
}; |
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.
why do you need this function
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.
to not return to client other fields like created_at, as was suggested in video lesson
No description provided.