Вы можете работать с делом отклонения и применять логику аналогичным образом.
ТАК каждое обещание имеет разрешение и отклонение и блок захвата
promise.then(
resolved=>{},
reject=>{}
).catch(error=>{});
Так и в вашем случае.
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) => {
Leaves.setHodMessage(group, message, curentHOD).then((messageArr) => {
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) => {
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)
},()=>{
//do your rollback stuff here
}).catch((err) => {
console.log(err)
reject(err)
});
}).catch((err) => {
reject(err)
})
})
}
Дай мне знать, если тебе нужна помощь.