Skip to content

Eval Pull Request#170

Open
martinsalinas0 wants to merge 60 commits intoprojectshft:masterfrom
martinsalinas0:master
Open

Eval Pull Request#170
martinsalinas0 wants to merge 60 commits intoprojectshft:masterfrom
martinsalinas0:master

Conversation

@martinsalinas0
Copy link

No description provided.

try {
const productsPerPage = 9;
const page = parseInt(req.query.page) || 1;
const category = req.query.category || null;

Choose a reason for hiding this comment

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

why the null fallback? undefined is not good enough?

let filterProducts = {};

if (category) {
filterProducts.category = { $regex: `^${category}$`, $options: "i" };

Choose a reason for hiding this comment

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

dry

}

if (search) {
filterProducts.name = { $regex: search, $options: "i" };

Choose a reason for hiding this comment

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

dry

Choose a reason for hiding this comment

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

you can store this as a generic const and just use it twice

filterProducts.name = { $regex: search, $options: "i" };
}

let sort = {};

Choose a reason for hiding this comment

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

can be const

const search = req.query.search || null;


let filterProducts = {};

Choose a reason for hiding this comment

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

not really clear the label, should be more like filterQuery or something more specific


let sort = {};

if (priceSort === "lowest") {

Choose a reason for hiding this comment

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

use consts, will help with DRY


const products = await Product.find(filterProducts)
.sort(sort)
.skip((page - 1) * productsPerPage)

Choose a reason for hiding this comment

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

store in a const or a function to give context for this skip

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