From 4da4bbda914eedc1b6fb84bb2cf06fc3961d4367 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 19 Feb 2024 19:05:06 +0300 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=BF=D0=BE=D1=81=D0=BC=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D0=B5=D1=82=D1=8C=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=B7=D0=B0=20=D0=BE=D0=BF=D1=80.=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=BE=D0=B8=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 6646e1c..90bc54c 100644 --- a/main.js +++ b/main.js @@ -26,7 +26,7 @@ fastify.get('/api/getRate/', async function (req, reply) { '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']['periodStart'], ]).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' ); + 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']; });