'Sequelize find data and if it exists then update it

I am really new to sequelize and I am looking for a way to check if data exist and then update it. I am using models.Booker.findAll followed by booker id, where it will look for booker id and if exist it returns the data. If the returned value is greater than 0, then only it should update the customer values following models.Customer.update.

As to get values we need to use router.get and to update values we need to use router.put. Is there a way we can use router.get first and if it returns data then use router.put to update the data?

router.get(
    "/customer/email/:email_id/phone/:phone_number/booker_id/:booker_id",
    (req, res) => {
      models.Booker.findAll({
        where: {
          id: req.params.booker_id
        },
      })
      .then((data) => {
        // res.send(data);
        if(data.length > '0'){
          
          models.Customer.update({
            where: {
              test: null,
              email: req.params.email_id,
              phone: req.params.phone_number
            },
          })
          .then((sendValue) => {
            res.send(sendValue);
          })
          .catch((error) => res.json(error));
        }
        else{
          res.send(data);
        }
      })
      .catch((error) => res.json(error));
    }
  ); 



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source