mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 12:43:12 +03:00
Перенес файлы в общую папку
This commit is contained in:
parent
b9a45b69b4
commit
7c835e145a
14 changed files with 7 additions and 9 deletions
1
shared/database/.gitignore
vendored
Normal file
1
shared/database/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules/
|
6
shared/database/data/schema.sql
Normal file
6
shared/database/data/schema.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE currency(
|
||||
from_currency TEXT NOT NULL,
|
||||
conv_currency TEXT NOT NULL,
|
||||
rate FLOAT NOT NULL,
|
||||
date DATE NOT NULL
|
||||
);
|
175
shared/database/package-lock.json
generated
Normal file
175
shared/database/package-lock.json
generated
Normal file
|
@ -0,0 +1,175 @@
|
|||
{
|
||||
"name": "database",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "database",
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"pg": "^8.12.0",
|
||||
"yaml": "^2.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/pg": {
|
||||
"version": "8.12.0",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz",
|
||||
"integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"pg-connection-string": "^2.6.4",
|
||||
"pg-pool": "^3.6.2",
|
||||
"pg-protocol": "^1.6.1",
|
||||
"pg-types": "^2.1.0",
|
||||
"pgpass": "1.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"pg-cloudflare": "^1.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"pg-native": ">=3.0.1"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"pg-native": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/pg-cloudflare": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz",
|
||||
"integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==",
|
||||
"license": "MIT",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/pg-connection-string": {
|
||||
"version": "2.6.4",
|
||||
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.4.tgz",
|
||||
"integrity": "sha512-v+Z7W/0EO707aNMaAEfiGnGL9sxxumwLl2fJvCQtMn9Fxsg+lPpPkdcyBSv/KFgpGdYkMfn+EI1Or2EHjpgLCA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pg-int8": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
||||
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/pg-pool": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.2.tgz",
|
||||
"integrity": "sha512-Htjbg8BlwXqSBQ9V8Vjtc+vzf/6fVUuak/3/XXKA9oxZprwW3IMDQTGHP+KDmVL7rtd+R1QjbnCFPuTHm3G4hg==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"pg": ">=8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/pg-protocol": {
|
||||
"version": "1.6.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.1.tgz",
|
||||
"integrity": "sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pg-types": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
|
||||
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"pg-int8": "1.0.1",
|
||||
"postgres-array": "~2.0.0",
|
||||
"postgres-bytea": "~1.0.0",
|
||||
"postgres-date": "~1.0.4",
|
||||
"postgres-interval": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/pgpass": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
|
||||
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"split2": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-array": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
|
||||
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-bytea": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
|
||||
"integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-date": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
|
||||
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/postgres-interval": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
|
||||
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/split2": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
||||
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">= 10.x"
|
||||
}
|
||||
},
|
||||
"node_modules/xtend": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/yaml": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz",
|
||||
"integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==",
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"yaml": "bin.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
shared/database/package.json
Normal file
23
shared/database/package.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "database",
|
||||
"version": "1.0.0",
|
||||
"main": "src/postgresql.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Redume/Kekkai.git"
|
||||
},
|
||||
"author": "Redume",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Redume/Kekkai/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Redume/Kekkai#readme",
|
||||
"description": "Database management service",
|
||||
"dependencies": {
|
||||
"pg": "^8.12.0",
|
||||
"yaml": "^2.5.0"
|
||||
}
|
||||
}
|
66
shared/database/src/main.js
Normal file
66
shared/database/src/main.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
const pool = require('./postgresql.js');
|
||||
const logger = require('../../logger/src/main.js');
|
||||
|
||||
/**
|
||||
* Getting the currency exchange rate for a specific day
|
||||
* @param from_currency {String}
|
||||
* @param conv_currency {String}
|
||||
* @param date
|
||||
* @returns {Promise<*|Error>}
|
||||
*/
|
||||
|
||||
async function getDay(from_currency, conv_currency, date) {
|
||||
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
|
||||
]);
|
||||
|
||||
if (!data) return new Error('Missing data');
|
||||
|
||||
let set_date = data['rows'][0]['date']
|
||||
set_date = new Date(set_date.setDate(set_date.getDate() + 1));
|
||||
|
||||
logger.debug(data['rows'][0])
|
||||
|
||||
return data['rows'][0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting the exchange rate for a certain period
|
||||
* @param {String} from_currency - The currency that is being converted
|
||||
* @param {String} conv_currency - The currency to be converted into
|
||||
* @param {String} start_date - Start date of the period
|
||||
* @param {String} end_date - End date of the period
|
||||
* @returns {Promise<*|Error>}
|
||||
*/
|
||||
|
||||
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')
|
||||
|
||||
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
|
||||
]);
|
||||
|
||||
if (!data) return new Error('Missing data');
|
||||
|
||||
for (let i = 0; i < data['rows'].length; i++) {
|
||||
let date = data['rows'][i]['date']
|
||||
date = new Date(date.setDate(date.getDate() + 1));
|
||||
}
|
||||
|
||||
logger.debug(data['rows'])
|
||||
|
||||
return data['rows'];
|
||||
}
|
||||
|
||||
module.exports = { getDay, getPeriod };
|
13
shared/database/src/postgresql.js
Normal file
13
shared/database/src/postgresql.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const pg = require("pg");
|
||||
const config = require("../../config/src/main.js")();
|
||||
|
||||
const pool = new pg.Pool({
|
||||
user: config['database']['user'],
|
||||
password: config['database']['password'],
|
||||
host: config['database']['host'],
|
||||
port: config['database']['port'],
|
||||
database: config['database']['name']
|
||||
});
|
||||
|
||||
|
||||
module.exports = pool;
|
Loading…
Add table
Reference in a new issue