fix(main): if there was no data, an empty array was returned
Some checks are pending
Create and publish a Docker image / build-and-push-server (push) Waiting to run
Create and publish a Docker image / build-and-push-chart (push) Waiting to run
Create and publish a Docker image / build-and-push-CR (push) Waiting to run
Deploy docs / deploy (push) Waiting to run

This commit is contained in:
Данил 2024-10-29 21:19:26 +03:00
parent 34d216de94
commit 7318b74453
2 changed files with 13 additions and 4 deletions

View file

@ -10,15 +10,16 @@ module.exports = async function getRateRoute(fastify) {
'The from_currency and conv_currency fields are required', 'The from_currency and conv_currency fields are required',
}); });
} }
let rate_res;
if (query['date']) if (query['date'])
return rate.getDay( rate_res = await rate.getDay(
query['from_currency'], query['from_currency'],
query['conv_currency'], query['conv_currency'],
query['date'], query['date'],
); );
else if (query['start_date'] && query['end_date']) else if (query['start_date'] && query['end_date'])
return rate.getPeriod( rate_res = await rate.getPeriod(
query['from_currency'], query['from_currency'],
query['conv_currency'], query['conv_currency'],
query['start_date'], query['start_date'],
@ -32,5 +33,13 @@ module.exports = async function getRateRoute(fastify) {
"There must be fields 'date' or 'start_date' and 'end_date'. " + "There must be fields 'date' or 'start_date' and 'end_date'. " +
'Read more in the documentation', 'Read more in the documentation',
}); });
if (typeof rate_res !== "object") return res.status(400).send({
status: 400,
message: rate_res,
});
else return res.status(200).send(
rate_res
)
}); });
}; };

View file

@ -20,7 +20,7 @@ async function getDay(from_currency, conv_currency, date) {
[from_currency.toUpperCase(), conv_currency.toUpperCase(), date], [from_currency.toUpperCase(), conv_currency.toUpperCase(), date],
); );
if (!data) return new Error('Missing data'); if (data?.['rows'].length <= 0) return 'Missing data';
const set_date = data['rows'][0]['date']; const set_date = data['rows'][0]['date'];
data['rows'][0]['date'] = new Date( data['rows'][0]['date'] = new Date(
@ -58,7 +58,7 @@ async function getPeriod(from_currency, conv_currency, start_date, end_date) {
], ],
); );
if (!data) return new Error('Missing data'); if (data?.['rows'].length <= 0) return 'Missing data';
for (let i = 0; i < data['rows'].length; i++) { for (let i = 0; i < data['rows'].length; i++) {
let date = data['rows'][i]['date']; let date = data['rows'][i]['date'];