fix: Fixed a bug where only the last array response was added by the return function

This commit is contained in:
Danil 2025-04-11 23:53:37 +03:00
parent 62e42cf12a
commit f2618a1f3a

22
main.js
View file

@ -33,29 +33,29 @@ async function main() {
console.log('Running scheduled task at:', new Date()); console.log('Running scheduled task at:', new Date());
for (const srv of services) { for (const srv of services) {
try { const results = await srv.parseCurrencies();
const result = await srv.parseCurrencies();
if (Array.isArray(results) && results.length > 0) {
if (result) { for (const result of results) {
try { try {
const currency = await validateCurrency(result); const currency = await validateCurrency(result);
await pool.query( await pool.query(
'INSERT INTO currency (from_currency, conv_currency, rate, date) ' + 'INSERT INTO currency (from_currency, conv_currency, rate, date) VALUES ($1, $2, $3, $4)',
'VALUES ($1, $2, $3, $4)',
[ [
currency.from_currency, currency.from_currency,
currency.conv_currency, currency.conv_currency,
currency.rate, currency.rate,
currency.date, currency.date,
]); ]
);
} catch (validationError) { } catch (validationError) {
console.error(validationError); console.error(validationError);
} }
} }
} catch (err) { } else {
console.error(`Error in service ${srv.name || 'unknown'}:`, err); console.error("Data not received for writing to the database.");
} }
} }
}); });