mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 12:43:12 +03:00
Добавил обработчик ошибок. Изменил поля функции под единую концепцию
This commit is contained in:
parent
ff6ba36dbb
commit
fc3604aa83
1 changed files with 21 additions and 9 deletions
|
@ -1,18 +1,30 @@
|
|||
const fastify = require('fastify')({logger: true})
|
||||
const logger = require('../logger/main.js');
|
||||
const fastify = require('fastify')({logger: logger});
|
||||
const rate = require('../database/main.js');
|
||||
|
||||
fastify.get('/api/getRate/', async function (req, res){
|
||||
const query = req.query;
|
||||
if (!query['fromCurrency'] || !query['convCurrency']) return;
|
||||
if (!query['from_currency'] || !query['conv_currency']) {
|
||||
return res.status(400).send({
|
||||
status: 400,
|
||||
message: 'The from_currency and conv_currency fields are required'
|
||||
})
|
||||
}
|
||||
|
||||
if (query['date']) return rate.getDay(query['fromCurrency'], query['convCurrency'], query['date']);
|
||||
else if (query['startDate'] && query['endDate']) return rate.getPeriod(
|
||||
query['fromCurrency'],
|
||||
query['convCurrency'],
|
||||
query['startDate'],
|
||||
query['endDate']
|
||||
|
||||
if (query['date']) return rate.getDay(query['from_currency'], query['conv_currency'], query['date']);
|
||||
else if (query['start_date'] && query['end_date']) return rate.getPeriod(
|
||||
query['from_currency'],
|
||||
query['conv_currency'],
|
||||
query['start_date'],
|
||||
query['end_date']
|
||||
);
|
||||
else return;
|
||||
else return res.status(400).send({
|
||||
status: 400,
|
||||
message: 'The date or period field is incorrect. ' +
|
||||
'There must be fields \'date\' or \'start_date\' and \'end_date\'. ' +
|
||||
'Read more in the documentation'
|
||||
});
|
||||
});
|
||||
|
||||
fastify.listen({ port: 3000 }, function (err) {
|
||||
|
|
Loading…
Add table
Reference in a new issue