Sequelize not finding variables

Viewed 91

I am at a complete loss as to what I'm doing wrong. I am trying to do a simple UPDATE function with Sequelize/mySQL and my command doesn't work as expected. Here is the command:

         await dataArr.map((e) => {
            Users.update(
                { account_status: -1 },
                {
                    returning: true,
                    where: { user_id: e.customer_id }
                }
            ).then((res) => {
                console.log(res);
                return res;
            });
        });

when the command get executed the query looks like:

Executing (default): UPDATE `users` SET `account_status`=? WHERE `user_id` = ?

as you can see the query is missing both the fixed value from account_status and the variable e.customer_id which is definitely being passed as I can console.log it. This has to be something really simple that I'm missing but I haven't found anyone with a similar problem.

1 Answers

I think your error is in the {}. Also, are you sure you are passing along customer_id? Try something like this. Make sure you are passing 'e' to the function.

updateStatus: function(req, res, e) {

    Users
        .update(account_status: -1,
                    {
                        where: { user_id: e.customer_id }
                    }
                )
        .then..........
}

Please clarify what 'e' is, and where it comes from. Maybe post more code, the lines above.

Related