From ff6ba36dbb46bc6d9a023f1f7bb56ab14a70ca38 Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 31 Jul 2024 14:45:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=87=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA.=20=D0=98=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=BB=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D0=BF=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B5=D0=B4=D0=B8=D0=BD=D1=83=D1=8E=20=D0=BA=D0=BE=D0=BD=D1=86?= =?UTF-8?q?=D0=B5=D0=BF=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/main.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/database/main.js b/database/main.js index 50a2b90..089ec87 100644 --- a/database/main.js +++ b/database/main.js @@ -1,7 +1,8 @@ const pool = require('./postgresql.js'); async function getDay(from_currency, conv_currency, date) { - if (!from_currency || !conv_currency || !date) return + if (!from_currency || !conv_currency) return new Error('fromCurrency and convCurrency are required'); + else if (!date) return new Error('date is required') const data = await pool.query('SELECT from_currency, conv_currency, date, rate FROM currency ' + 'WHERE from_currency = $1 AND conv_currency = $2 AND date = $3', [ @@ -10,26 +11,26 @@ async function getDay(from_currency, conv_currency, date) { date ]); - if (!data) return; + if (!data) return new Error('Missing data'); return data['rows'][0]; } async function getPeriod(from_currency, conv_currency, start_date, end_date) { - if (!from_currency || !conv_currency || !start_date || !end_date) return + if (!from_currency || !conv_currency) return new Error('from_currency and conv_currency are required'); + else if(!start_date || !end_date) return new Error('start_date and end_date are required') const data = await pool.query('SELECT * FROM currency WHERE ' + '(date BETWEEN $3 AND $4) AND from_currency = $1 AND conv_currency = $2', [ - from_currency, - conv_currency, + from_currency.toUpperCase(), + conv_currency.toUpperCase(), start_date, end_date ]); - if (!data) return; + if (!data) return new Error('Missing data'); return data['rows']; } - -module.exports = { getDay, getPeriod }; +module.exports = { getDay, getPeriod }; \ No newline at end of file