Friday, 16 April 2021

Sequelize search API not working as desired expressJS

I want to search all columns and display the search result.

I am new to sequelize so used this code to do so, However here it is checking for full matches

I want to show details for partial matches also

How do i acheive this ?

router.post("/search-employees", async (req, res) => {
  const searchTerm = req.body.searchTerm;
  try {
    const resp = await employee.findAll({
      where: {
        [Op.or]: [
          { name: searchTerm },
          { age: searchTerm },
          { country: searchTerm },
          { position: searchTerm },
          { wage: searchTerm },
        ],
      },
    });
    res.status(200).send(resp);
  } catch (e) {
    res.status(400).send(e);
  }
});


from Sequelize search API not working as desired expressJS

No comments:

Post a Comment