Перенес файлы в общую папку

This commit is contained in:
Данил 2024-08-14 17:14:38 +03:00
parent b9a45b69b4
commit 7c835e145a
14 changed files with 7 additions and 9 deletions

View file

@ -0,0 +1,66 @@
const pool = require('./postgresql.js');
const logger = require('../../logger/src/main.js');
/**
* Getting the currency exchange rate for a specific day
* @param from_currency {String}
* @param conv_currency {String}
* @param date
* @returns {Promise<*|Error>}
*/
async function getDay(from_currency, conv_currency, date) {
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', [
from_currency.toUpperCase(),
conv_currency.toUpperCase(),
date
]);
if (!data) return new Error('Missing data');
let set_date = data['rows'][0]['date']
set_date = new Date(set_date.setDate(set_date.getDate() + 1));
logger.debug(data['rows'][0])
return data['rows'][0];
}
/**
* Getting the exchange rate for a certain period
* @param {String} from_currency - The currency that is being converted
* @param {String} conv_currency - The currency to be converted into
* @param {String} start_date - Start date of the period
* @param {String} end_date - End date of the period
* @returns {Promise<*|Error>}
*/
async function getPeriod(from_currency, conv_currency, start_date, end_date) {
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 ORDER BY date', [
from_currency.toUpperCase(),
conv_currency.toUpperCase(),
start_date,
end_date
]);
if (!data) return new Error('Missing data');
for (let i = 0; i < data['rows'].length; i++) {
let date = data['rows'][i]['date']
date = new Date(date.setDate(date.getDate() + 1));
}
logger.debug(data['rows'])
return data['rows'];
}
module.exports = { getDay, getPeriod };

View file

@ -0,0 +1,13 @@
const pg = require("pg");
const config = require("../../config/src/main.js")();
const pool = new pg.Pool({
user: config['database']['user'],
password: config['database']['password'],
host: config['database']['host'],
port: config['database']['port'],
database: config['database']['name']
});
module.exports = pool;