'node overpasses to next loop element with await

in updateHealthInfo function I want to add 0 (number) after query done (query may has more than one element to update it), but node always overpasses this step to the resolve step then redirects page then (after route ends) return to enter the loop and adds 0s. Why is this happening? How can I make it add 0 after query ends then resolve when loop ends? I'm new to NodeJS.

route:

app.post("/updateFile", async function (req, res) {
        //check for post parameters
        if (("pi_post" in req.body) && ("hi_U_post" in req.body) && ("hi_D_post" in req.body) && ("hi_C_post" in req.body)) {
            try {
                let updateHiResults = await updateHealthInfo(req.body.hi_U_post);
                res.redirect("/");
            } catch (error) {
                console.log(error);
                res.send(error);
            }
        } else {
            res.send("error req keys");
        }
    });

updateHealthInfo function:

async function updateHealthInfo(obj) {
    let conn_p = await mysql2_p.createConnection({
        host: 'localhost',
        user: 'test',
        password: 'passwordtesttest',
        database: 'testdb'

    });
    let hi_U = "";
    hi_U = JSON.parse(obj);//result is [{},{},{},...]
    return new Promise((resolve, reject) => {
        resolveds = [];
        hi_U.forEach(async element => {
            if (("iid" in element) && ("DateOfInfo" in element) && ("InfoNote" in element) && ("hiid" in element)) {
                q = "update healthinfo set infoitem_id=?, DateOfInfo=?, InfoNote=? where id=?";
                qValues = [element.iid, element.DateOfInfo, element.InfoNote, element.hiid];
                try {
                    await conn_p.execute(q, qValues);
                    resolveds.push(0);
                } catch (error) {
                    reject(error);
                }

            } else if (Object.keys(element).length == 0) {
                resolveds.push("empty");
            }
            else {
                reject("error hi u keys");
            }
        });
        resolve(resolveds);
    });
}


Sources

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

Source: Stack Overflow

Solution Source