mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 20:51:25 +03:00
feat(server): Added a parameter to multiply the rate by X number (conv_amount)
This commit is contained in:
parent
c2720114c4
commit
b80015a6c3
2 changed files with 10 additions and 1 deletions
|
@ -18,6 +18,7 @@ module.exports = async function getRateRoute(fastify) {
|
||||||
query['from_currency'],
|
query['from_currency'],
|
||||||
query['conv_currency'],
|
query['conv_currency'],
|
||||||
query['date'],
|
query['date'],
|
||||||
|
query['conv_amount'] ? query['conv_amount'] : 1
|
||||||
);
|
);
|
||||||
else if (query['start_date'] && query['end_date'])
|
else if (query['start_date'] && query['end_date'])
|
||||||
rate_res = await rate.getPeriod(
|
rate_res = await rate.getPeriod(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const pool = require('./postgresql.js');
|
const pool = require('./postgresql.js');
|
||||||
const logger = require('../../logger/src/main.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)
|
if (!from_currency || !conv_currency)
|
||||||
return new Error('fromCurrency and convCurrency are required');
|
return new Error('fromCurrency and convCurrency are required');
|
||||||
else if (!date) return new Error('date is 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],
|
[from_currency.toUpperCase(), conv_currency.toUpperCase(), date],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if (data?.['rows'].length <= 0) return 'Missing data';
|
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]);
|
logger.debug(data['rows'][0]);
|
||||||
|
|
||||||
return data['rows'][0];
|
return data['rows'][0];
|
||||||
|
|
Loading…
Add table
Reference in a new issue