Дуб Вот мой говнокод:
function make_report(){
Firebird.attach(options, function(err, db) {
if (err)
throw err;
let current_date = new Date();
current_date.setDate(current_date.getDate() - 1);
let user_list_text = '';
let user_list = [];
if(user_list.length > 0){
user_list.forEach(function(item, i, arr) {
user_list_text += item + ',';
});
user_list_text = ' and STAFF.ID_STAFF IN (' + user_list_text.substring(0, user_list_text.length - 1) + ') ';
}
let firm_list_text = '';
let firm_list = []; //7494
if(firm_list.length > 0){
firm_list.forEach(function(item, i, arr) {
firm_list_text += item + ',';
});
firm_list_text = ' and REG_EVENTS.SUBDIV_ID IN (' + firm_list_text.substring(0, firm_list_text.length - 1) + ') ';
//console.log(firm_list_text);
}
let q_text = querry_text();
q_text = q_text.replace('@user_list_text', user_list_text);
q_text = q_text.replace('@firm_list_text', firm_list_text);
db.query(q_text, [current_date], function(err, result) {
if(err){
console.log(err);
db.detach();
return err;
}
else{
let htm = open_htm;
htm += '<table cellspacing="0" border="1" cellpadding="0" width="100%">';
let pre_time = '';
let pre_usr = '';
let c_name = '';
result.forEach(function(item, i, arr) {
if(item.STAFF_ID != null && pre_usr == item.STAFF_ID.toString() && pre_time == item.TIME_EVENT.toString()){
c_name += item.FIRM.toString();
}
else{
htm += '<tr>';
htm += '<td db_date="' + date_from_date(item.DATE_EVENT) + '">' + time_from_date(item.TIME_EVENT) + '</td>';
htm += '<td db_id="' + item.AREA_ID + '">' + item.AREA + '</td>';
htm += '<td db_id="' + item.STAFF_ID + '">' + item.STAFF + '</td>';
htm += '<td db_id="' + item.FIRMV_ID + '">' + item.FIRM + '</td>';
htm += '</tr>';
c_name = '';
}
pre_usr = item.STAFF_ID.toString();
pre_time = item.TIME_EVENT.toString();
});
htm += '</table>';
htm += close_htm;
/*fs.writeFile('D:/firebird/report.htm', htm, (err) => {if(err){console.error(err); return}});*/
//console.log(htm);
db.detach();
return htm;
}
});
});
}
У тебя эта функция ничего не возвращает. Оберни ее в промис, или внутри ее сделай промис вот так, и вместо return используй resolve, тогда можно будет делать как ты хотел, через await.
function make_report(){
return new Promise((resolve, reject) => {
Firebird.attach(options, function(err, db) {
if (err)
throw err;
let current_date = new Date();
current_date.setDate(current_date.getDate() - 1);
let user_list_text = '';
let user_list = [];
if(user_list.length > 0){
user_list.forEach(function(item, i, arr) {
user_list_text += item + ',';
});
user_list_text = ' and STAFF.ID_STAFF IN (' + user_list_text.substring(0, user_list_text.length - 1) + ') ';
}
let firm_list_text = '';
let firm_list = []; //7494
if(firm_list.length > 0){
firm_list.forEach(function(item, i, arr) {
firm_list_text += item + ',';
});
firm_list_text = ' and REG_EVENTS.SUBDIV_ID IN (' + firm_list_text.substring(0, firm_list_text.length - 1) + ') ';
//console.log(firm_list_text);
}
let q_text = querry_text();
q_text = q_text.replace('@user_list_text', user_list_text);
q_text = q_text.replace('@firm_list_text', firm_list_text);
db.query(q_text, [current_date], function(err, result) {
if(err){
console.log(err);
db.detach();
reject(err);
}
else{
let htm = open_htm;
htm += '<table cellspacing="0" border="1" cellpadding="0" width="100%">';
let pre_time = '';
let pre_usr = '';
let c_name = '';
result.forEach(function(item, i, arr) {
if(item.STAFF_ID != null && pre_usr == item.STAFF_ID.toString() && pre_time == item.TIME_EVENT.toString()){
c_name += item.FIRM.toString();
}
else{
htm += '<tr>';
htm += '<td db_date="' + date_from_date(item.DATE_EVENT) + '">' + time_from_date(item.TIME_EVENT) + '</td>';
htm += '<td db_id="' + item.AREA_ID + '">' + item.AREA + '</td>';
htm += '<td db_id="' + item.STAFF_ID + '">' + item.STAFF + '</td>';
htm += '<td db_id="' + item.FIRMV_ID + '">' + item.FIRM + '</td>';
htm += '</tr>';
c_name = '';
}
pre_usr = item.STAFF_ID.toString();
pre_time = item.TIME_EVENT.toString();
});
htm += '</table>';
htm += close_htm;
/*fs.writeFile('D:/firebird/report.htm', htm, (err) => {if(err){console.error(err); return}});*/
//console.log(htm);
db.detach();
resolve(htm);
}
});
});
});
}