теперь можно посмотреть данные за опр. пероид

This commit is contained in:
Данил 2024-02-19 19:05:06 +03:00
parent 33808437e9
commit 4da4bbda91

16
main.js
View file

@ -26,7 +26,7 @@ fastify.get('/api/getRate/', async function (req, reply) {
'periodStart parameter is required' 'periodStart parameter is required'
); );
const data = await pool.query('SELECT * FROM currency WHERE from_currency = $1 AND date = $2', [ let data = await pool.query('SELECT * FROM currency WHERE from_currency = $1 AND date = $2', [
req['query']['codeCurrency'], req['query']['codeCurrency'],
req['query']['periodStart'], req['query']['periodStart'],
]).then(response('error', 500, 'Internal Server Error')); ]).then(response('error', 500, 'Internal Server Error'));
@ -37,6 +37,20 @@ fastify.get('/api/getRate/', async function (req, reply) {
'There is no data for this time' 'There is no data for this time'
); );
if (req['query']?.['periodEnd']) {
let data = await pool.query('SELECT * FROM currency WHERE (date BETWEEN $2 AND $3) AND from_currency = $1', [
req['query']['codeCurrency'],
req['query']['periodStart'],
req['query']['periodEnd'],
]);
console.log(data)
return data['rows'];
} else {
return response('error', 204, 'There is no data for this time')
}
return data['rows']; return data['rows'];
}); });