Nodejs mysql multiple inserts with condition

Hello

I am trying to post multiple requests from an endpoint into my database using express and node-mysql. Thing is, before i add an item to the db, i have to search for a partner_id and add it as well. It is not part of the item. I am having a hard time figuring out how to pass the partner_id in my insert statement. Any references or recommendations on how to do this will be appreciated. I am also trying to make the process fast because the requests will be many. Thank you.

app.post("/hl7_sync_client", (req, res) => {

    var clients = req.body;

    async.each(clients, function (client, asyncCallback) {
    
        let partner_id = connection.query('SELECT partner_id FROM tbl_partner_facility WHERE mfl_code', client.SENDING_FACILITY, function (err,data) {
            if(err) { console.log(err)}
            console.log(data);
        });

        connection.query('INSERT INTO tbl_clients SET ?', client, function (err, data) {
          return asyncCallback(err, data);
        });
      }, function (err) {
        if (err) {
          // One of the iterations above produced an error.
          // All processing will stop and we have to rollback.
          return callback(err);
        }
    
        // Return without errors
        return callback();
      });

});

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.