mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 12:43:12 +03:00
Роуты теперь в отдельной папке
This commit is contained in:
parent
e7b232d189
commit
57c3920853
3 changed files with 77 additions and 67 deletions
|
@ -20,74 +20,11 @@ const fastify = require('fastify')({
|
||||||
: false),
|
: false),
|
||||||
});
|
});
|
||||||
|
|
||||||
const rate = require('../shared/database/src/main.js');
|
const getChartRoute = require('./routes/getChart.js');
|
||||||
const chart = require('../chart/chart.js');
|
const getRateRoute = require('./routes/getRate.js');
|
||||||
|
|
||||||
fastify.get('/api/getRate/', async function (req, res) {
|
fastify.register(getChartRoute);
|
||||||
const query = req.query;
|
fastify.register(getRateRoute);
|
||||||
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['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 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.get('/api/getChart/', async function (req, res) {
|
|
||||||
const query = req.query;
|
|
||||||
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['start_date'] || !query['end_date'])
|
|
||||||
return res.status(400).send({
|
|
||||||
status: 400,
|
|
||||||
message: 'start_date and end_date is required',
|
|
||||||
});
|
|
||||||
|
|
||||||
const charts = await chart.gen_chart(
|
|
||||||
query['from_currency'],
|
|
||||||
query['conv_currency'],
|
|
||||||
query['start_date'],
|
|
||||||
query['end_date'],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (config['currency']['chart']['save'])
|
|
||||||
chart.save_chart(
|
|
||||||
charts,
|
|
||||||
`${query['from_currency']} ${query['conv_currency']} ` +
|
|
||||||
`(${query['start_date']} - ${query['end_date']}).png`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).send({
|
|
||||||
status: 200,
|
|
||||||
message: charts,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
fastify.listen(
|
fastify.listen(
|
||||||
{
|
{
|
||||||
|
|
38
server/routes/getChart.js
Normal file
38
server/routes/getChart.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
const config = require('../../shared/config/src/main.js')();
|
||||||
|
const chart = require('../../chart/chart.js');
|
||||||
|
|
||||||
|
module.exports = async function GetChartRoute(fastify) {
|
||||||
|
fastify.get('/api/getChart/', async function (req, res) {
|
||||||
|
const query = req.query;
|
||||||
|
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['start_date'] || !query['end_date'])
|
||||||
|
return res.status(400).send({
|
||||||
|
status: 400,
|
||||||
|
message: 'start_date and end_date is required',
|
||||||
|
});
|
||||||
|
|
||||||
|
const charts = await chart.gen_chart(
|
||||||
|
query['from_currency'],
|
||||||
|
query['conv_currency'],
|
||||||
|
query['start_date'],
|
||||||
|
query['end_date'],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (config['currency']['chart']['save'])
|
||||||
|
chart.save_chart(
|
||||||
|
charts,
|
||||||
|
`${query['from_currency']} ${query['conv_currency']} ` +
|
||||||
|
`(${query['start_date']} - ${query['end_date']}).png`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
status: 200,
|
||||||
|
message: charts,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
35
server/routes/getRate.js
Normal file
35
server/routes/getRate.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
const rate = require('../../shared/database/src/main.js');
|
||||||
|
|
||||||
|
module.exports = async function getRateRoute(fastify) {
|
||||||
|
fastify.get('/api/getRate/', async function (req, res) {
|
||||||
|
const query = req.query;
|
||||||
|
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['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 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',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue