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

16
main.js
View file

@ -33,28 +33,28 @@ async function main() {
console.log('Running scheduled task at:', new Date());
for (const srv of services) {
try {
const result = await srv.parseCurrencies();
const results = await srv.parseCurrencies();
if (result) {
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.");
}
}
});