mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 04:33:11 +03:00
eslint, prettier fix
This commit is contained in:
parent
bdc4450b72
commit
2679fa20d5
10 changed files with 284 additions and 208 deletions
116
server/main.js
116
server/main.js
|
@ -4,43 +4,26 @@ const fs = require('fs');
|
|||
|
||||
const fastify = require('fastify')({
|
||||
logger: config['server']['log']['print'] ? logger : false,
|
||||
...config['server']['ssl']['work'] ? {
|
||||
https: {
|
||||
key: fs.readFileSync(config['server']['ssl']['private_key'], 'utf8'),
|
||||
cert: fs.readFileSync(config['server']['ssl']['cert'], 'utf8'),
|
||||
}
|
||||
} : false
|
||||
...(config['server']['ssl']['work']
|
||||
? {
|
||||
https: {
|
||||
key: fs.readFileSync(
|
||||
config['server']['ssl']['private_key'],
|
||||
'utf8',
|
||||
),
|
||||
cert: fs.readFileSync(
|
||||
config['server']['ssl']['cert'],
|
||||
'utf8',
|
||||
),
|
||||
},
|
||||
}
|
||||
: false),
|
||||
});
|
||||
|
||||
const rate = require('../shared/database/src/main.js');
|
||||
const chart = require('../chart/chart.js');
|
||||
|
||||
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'
|
||||
});
|
||||
});
|
||||
|
||||
fastify.get('/api/getChart/', async function (req, res){
|
||||
fastify.get('/api/getRate/', async function (req, res) {
|
||||
const query = req.query;
|
||||
if (!query['from_currency'] || !query['conv_currency']) {
|
||||
return res.status(400).send({
|
||||
|
@ -48,10 +31,43 @@ fastify.get('/api/getChart/', async function (req, res){
|
|||
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',
|
||||
});
|
||||
|
||||
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'],
|
||||
|
@ -60,11 +76,12 @@ fastify.get('/api/getChart/', async function (req, res){
|
|||
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`
|
||||
);
|
||||
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,
|
||||
|
@ -72,12 +89,15 @@ fastify.get('/api/getChart/', async function (req, res){
|
|||
});
|
||||
});
|
||||
|
||||
fastify.listen({
|
||||
fastify.listen(
|
||||
{
|
||||
port: 3000,
|
||||
host: config['server']['host'] ? config['server']['host'] : 'localhost',
|
||||
}, (err) => {
|
||||
if (err) {
|
||||
fastify.log.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
if (err) {
|
||||
fastify.log.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue