title: How to implement transactions with node promises
body: <p>I'm developing an application with <code>node</code>,<code>mysql</code> and <code>angular4</code>. There , I have set of functions that related to a single task. all these are asynchronous function that works with promises that look like this</p>
  
  <pre><code>setAprroveTrue(curentHOD, user, group, message, approvemail, approved_byHR = 0) { //HR or super admin can override anyones leave. default it is set as not by and hr.
          return new Promise((resolve, reject) =&gt; {
              Leaves.setHodMessage(group, message, curentHOD).then((messageArr) =&gt; {
                  q = "update leave_taken_superior_map set lstm_col_status= ? ,ltsm_all_approved = 1,ltsm_overide_by_hr = ?,ltsm_message = ? where ltsm_group_id = ?;update leave_taken set alt_leave_approved = 1 where alt_group_by = ?";
                  params = [config.key_word_approved_leave, approved_byHR, messageArr, group, group];
                  sqlq.executeQuery(q, params).then((data) =&gt; {
                      if (approvemail === true) {
                          emails.sendEmail('pavithrarox1@gmail.com', 'pavithra@gmail.lk', 'Good news! Your leave request has been approved', emails.getLeaveApprovedEmail(group))
                      } else {
                          emails.sendEmail('pavithrarox1@gmail.com', 'pavithra@gmail.lk', 'Bad news! Your leave request has been rejected', emails.getLeaveDissapprovedEmail(group))
                      }
                      //no need to wait for email to send.it will work as a background procass
                      resolve(data)
                  }).catch((err) =&gt; {
                      console.log(err)
                      reject(err)
                  });
              }).catch((err) =&gt; {
                  reject(err)
              })
          })
      } 
  </code></pre>
  
  <p>How can I implement transactions in this function?
  So, if <code>setHodMessage</code> function executed successfully and if something goes wrong with <code>executeQuery</code> function. How do i roll back everything?</p>