feat(server): Added a parameter to multiply the rate by X number (conv_amount)

This commit is contained in:
Данил 2024-12-22 21:01:57 +03:00
parent c2720114c4
commit b80015a6c3
2 changed files with 10 additions and 1 deletions

View file

@ -18,6 +18,7 @@ module.exports = async function getRateRoute(fastify) {
query['from_currency'],
query['conv_currency'],
query['date'],
query['conv_amount'] ? query['conv_amount'] : 1
);
else if (query['start_date'] && query['end_date'])
rate_res = await rate.getPeriod(

View file

@ -1,7 +1,7 @@
const pool = require('./postgresql.js');
const logger = require('../../logger/src/main.js');
async function getDay(from_currency, conv_currency, date) {
async function getDay(from_currency, conv_currency, date, conv_amount) {
if (!from_currency || !conv_currency)
return new Error('fromCurrency and convCurrency are required');
else if (!date) return new Error('date is required');
@ -12,8 +12,16 @@ async function getDay(from_currency, conv_currency, date) {
[from_currency.toUpperCase(), conv_currency.toUpperCase(), date],
);
if (data?.['rows'].length <= 0) return 'Missing data';
if (conv_amount) {
let conv_rate = data?.['rows'][0]['rate'] * conv_amount;
const point = conv_rate.toString().indexOf('.') + 4;
data['rows'][0]['rate'] = Number(conv_rate.toString().slice(0, point));
}
logger.debug(data['rows'][0]);
return data['rows'][0];