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
|
@ -7,5 +7,4 @@ const config = () => {
|
|||
return yaml.parse(fs.readFileSync('../config.yaml', 'utf-8'));
|
||||
};
|
||||
|
||||
|
||||
module.exports = config;
|
||||
module.exports = config;
|
||||
|
|
|
@ -10,20 +10,22 @@ const logger = require('../../logger/src/main.js');
|
|||
*/
|
||||
|
||||
async function getDay(from_currency, conv_currency, date) {
|
||||
if (!from_currency || !conv_currency) return new Error('fromCurrency and convCurrency are required');
|
||||
if (!from_currency || !conv_currency)
|
||||
return new Error('fromCurrency and convCurrency are required');
|
||||
else if (!date) return new Error('date is required');
|
||||
|
||||
const data = await pool.query('SELECT from_currency, conv_currency, date, rate FROM currency ' +
|
||||
'WHERE from_currency = $1 AND conv_currency = $2 AND date = $3', [
|
||||
from_currency.toUpperCase(),
|
||||
conv_currency.toUpperCase(),
|
||||
date
|
||||
]);
|
||||
const data = await pool.query(
|
||||
'SELECT from_currency, conv_currency, date, rate FROM currency ' +
|
||||
'WHERE from_currency = $1 AND conv_currency = $2 AND date = $3',
|
||||
[from_currency.toUpperCase(), conv_currency.toUpperCase(), date],
|
||||
);
|
||||
|
||||
if (!data) return new Error('Missing data');
|
||||
|
||||
const set_date = data['rows'][0]['date'];
|
||||
data['rows'][0]['date'] = new Date(set_date.setDate(set_date.getDate() + 1));
|
||||
data['rows'][0]['date'] = new Date(
|
||||
set_date.setDate(set_date.getDate() + 1),
|
||||
);
|
||||
|
||||
logger.debug(data['rows'][0]);
|
||||
|
||||
|
@ -40,16 +42,21 @@ async function getDay(from_currency, conv_currency, date) {
|
|||
*/
|
||||
|
||||
async function getPeriod(from_currency, conv_currency, start_date, end_date) {
|
||||
if (!from_currency || !conv_currency) return new Error('from_currency and conv_currency are required');
|
||||
else if(!start_date || !end_date) return new Error('start_date and end_date are required');
|
||||
if (!from_currency || !conv_currency)
|
||||
return new Error('from_currency and conv_currency are required');
|
||||
else if (!start_date || !end_date)
|
||||
return new Error('start_date and end_date are required');
|
||||
|
||||
const data = await pool.query('SELECT * FROM currency WHERE ' +
|
||||
'(date BETWEEN $3 AND $4) AND from_currency = $1 AND conv_currency = $2 ORDER BY date', [
|
||||
const data = await pool.query(
|
||||
'SELECT * FROM currency WHERE ' +
|
||||
'(date BETWEEN $3 AND $4) AND from_currency = $1 AND conv_currency = $2 ORDER BY date',
|
||||
[
|
||||
from_currency.toUpperCase(),
|
||||
conv_currency.toUpperCase(),
|
||||
start_date,
|
||||
end_date
|
||||
]);
|
||||
end_date,
|
||||
],
|
||||
);
|
||||
|
||||
if (!data) return new Error('Missing data');
|
||||
|
||||
|
@ -63,4 +70,4 @@ async function getPeriod(from_currency, conv_currency, start_date, end_date) {
|
|||
return data['rows'];
|
||||
}
|
||||
|
||||
module.exports = { getDay, getPeriod };
|
||||
module.exports = { getDay, getPeriod };
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
const pg = require("pg");
|
||||
const config = require("../../config/src/main.js")();
|
||||
const pg = require('pg');
|
||||
const config = require('../../config/src/main.js')();
|
||||
|
||||
const pool = new pg.Pool({
|
||||
user: config['database']['user'],
|
||||
user: config['database']['user'],
|
||||
password: config['database']['password'],
|
||||
host: config['database']['host'],
|
||||
port: config['database']['port'],
|
||||
database: config['database']['name']
|
||||
database: config['database']['name'],
|
||||
});
|
||||
|
||||
|
||||
module.exports = pool;
|
||||
module.exports = pool;
|
||||
|
|
|
@ -11,37 +11,46 @@ function getCallerFile() {
|
|||
const err = new Error();
|
||||
let currentFile;
|
||||
|
||||
Error.prepareStackTrace = function (err, stack) { return stack; };
|
||||
Error.prepareStackTrace = function (err, stack) {
|
||||
return stack;
|
||||
};
|
||||
currentFile = err.stack.shift().getFileName();
|
||||
|
||||
while (err.stack.length) {
|
||||
callerFile = err.stack.shift().getFileName();
|
||||
if (currentFile !== callerFile) break;
|
||||
}
|
||||
} catch { return; }
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
Error.prepareStackTrace = originalFunc;
|
||||
|
||||
return callerFile ? path.basename(callerFile) : 'unknown';
|
||||
}
|
||||
|
||||
const logger = pino({
|
||||
level: config['server']['log']['level'] ? config['server']['log']['level'] : 'info',
|
||||
prettifier: pretty,
|
||||
prettify: true,
|
||||
messageKey: 'msg',
|
||||
timestampKey: 'time',
|
||||
}, pretty({
|
||||
ignore: 'pid,hostname',
|
||||
messageFormat: '{msg}',
|
||||
}));
|
||||
const logger = pino(
|
||||
{
|
||||
level: config['server']['log']['level']
|
||||
? config['server']['log']['level']
|
||||
: 'info',
|
||||
prettifier: pretty,
|
||||
prettify: true,
|
||||
messageKey: 'msg',
|
||||
timestampKey: 'time',
|
||||
},
|
||||
pretty({
|
||||
ignore: 'pid,hostname',
|
||||
messageFormat: '{msg}',
|
||||
}),
|
||||
);
|
||||
|
||||
function wrapLogger(logger) {
|
||||
const levels = ['fatal', 'error', 'warn', 'info', 'debug', 'trace'];
|
||||
|
||||
const wrappedLogger = {};
|
||||
|
||||
levels.forEach(level => {
|
||||
levels.forEach((level) => {
|
||||
wrappedLogger[level] = function (msg, ...args) {
|
||||
const callerFile = getCallerFile();
|
||||
const msgWithFilename = `[${callerFile}] ${msg}`;
|
||||
|
|
Loading…
Add table
Reference in a new issue