From f2618a1f3a8dc20c2ffe22516ad5f5cc1a95fdac Mon Sep 17 00:00:00 2001 From: Redume Date: Fri, 11 Apr 2025 23:53:37 +0300 Subject: [PATCH] fix: Fixed a bug where only the last array response was added by the return function --- main.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index 0440831..e6b8848 100644 --- a/main.js +++ b/main.js @@ -33,29 +33,29 @@ async function main() { console.log('Running scheduled task at:', new Date()); for (const srv of services) { - try { - const result = await srv.parseCurrencies(); - - if (result) { + const results = await srv.parseCurrencies(); + + if (Array.isArray(results) && results.length > 0) { + for (const result of results) { try { const currency = await validateCurrency(result); - + await pool.query( - 'INSERT INTO currency (from_currency, conv_currency, rate, date) ' + - 'VALUES ($1, $2, $3, $4)', + 'INSERT INTO currency (from_currency, conv_currency, rate, date) VALUES ($1, $2, $3, $4)', [ currency.from_currency, currency.conv_currency, currency.rate, currency.date, - ]); + ] + ); } catch (validationError) { console.error(validationError); } } - } catch (err) { - console.error(`Error in service ${srv.name || 'unknown'}:`, err); - } + } else { + console.error("Data not received for writing to the database."); + } } });