65013266

Date: 2020-11-25 22:03:51
Score: 5
Natty:
Report link

After googling StackOverflow, I find a similar question and solve my problem. Here is the code, right now, I didn't see any bug. But please let me know if there is anything that can be improved.

exports.getProductsSearchResult = (req, res, next) => {
    let query = {};
    const productCategory = req.query.category;
    const productSize = req.query.size;
    const productGender = req.query.gender
    let payload = { "category": productCategory, "size": productSize, "gender": productGender }
    if (payload.category && payload.category.length > 0) query.category = { $in: payload.category }
    if (payload.size && payload.size.length > 0) query.size = { $in: payload.size };
    if (payload.gender && payload.gender.length > 0) query.gender = { $in: payload.gender };
    console.log('query', query)
    Products.find(query).then(product => {
        // console.log(product)
        res.status(201).json(product)
    }).catch(err => {
        console.log(err)
    })
}

Reasons:
  • Blacklisted phrase (1): StackOverflow
  • RegEx Blacklisted phrase (1.5): please let me know
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2): a similar question
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Xian Li