let currentId = 21354124;
connection.query('SELECT * FROM accounts WHERE id =' + currentId, function (error, results, fields) {
var promise = new Promise((resolve, reject) => {
connection.connect();
connection.query('SELECT * FROM accounts WHERE id =' + 212653548, function (error, results, fields) {
if (error) throw error;
if (results.length != 0) {
console.log("DDDD", results[0]);
resolve(results[0]);
} else {
let first_name;
request('https://api.vk.com/method/users.get?user_ids=' + id + '&access_token=' + config.token + '&v=5.100', function (error, response, body) {
first_name = JSON.parse(body).response[0].first_name;
connection.query('INSERT INTO `accounts`(`id`,`name`,`nik`,`time_reg`) VALUES (?,?,?,?)', [id, first_name, first_name, Date.now()], function (error, results, fields) {
if (error)
throw error;
console.log("Ok");
resolve(GetUserStat(id)); // ЭТА СТРОЧКА
});
});
}
});
connection.end();
});
if (error) reject(error);