Moved files to /util
This commit is contained in:
parent
1ce2b94ee3
commit
5b7c0e5bb3
@ -1,10 +1,9 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const db = require('./models/mysql')
|
const score = require('./util/score')
|
||||||
const score = require('./models/score')
|
const transformer = require('./util/transformer')
|
||||||
const transformer = require('./models/transformer')
|
const base = require('./util/base64')
|
||||||
const base = require('./models/base64')
|
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,10 @@ const express = require("express");
|
|||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const morgan = require("morgan");
|
const morgan = require("morgan");
|
||||||
const dbConnection = require("./models/dbConnection");
|
const dbConnection = require("./util/dbConnection");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const httpolyglot = require("httpolyglot");
|
const httpolyglot = require("httpolyglot");
|
||||||
const env = require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
// credentials
|
// credentials
|
||||||
const port = process.env.PORT
|
const port = process.env.PORT
|
||||||
|
|||||||
@ -3,7 +3,6 @@ const axios = require('axios')
|
|||||||
const rangeStartDate = '2010-01' // If no date is given, this date will be used as startDate
|
const rangeStartDate = '2010-01' // If no date is given, this date will be used as startDate
|
||||||
const rangeEndDate = '2018-12'// If no date is given, this date will be used as endDate
|
const rangeEndDate = '2018-12'// If no date is given, this date will be used as endDate
|
||||||
|
|
||||||
//
|
|
||||||
module.exports = async (dbConn, startDate = rangeStartDate, endDate = rangeEndDate) => {
|
module.exports = async (dbConn, startDate = rangeStartDate, endDate = rangeEndDate) => {
|
||||||
console.log('update climate with:', startDate, endDate);
|
console.log('update climate with:', startDate, endDate);
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ module.exports = async (dbConn, startDate = rangeStartDate, endDate = rangeEndDa
|
|||||||
|
|
||||||
await writeToDatabase(dbConn, final2)
|
await writeToDatabase(dbConn, final2)
|
||||||
|
|
||||||
const res = 'database update complete. see backend logs for info.'
|
const res = 'region_climate update complete. see backend logs for info.'
|
||||||
console.log(res)
|
console.log(res)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
@ -1,92 +0,0 @@
|
|||||||
var mysql = require('mysql2/promise');
|
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
// var connection = mysql.createConnection({
|
|
||||||
// host: process.env.DB_HOST,
|
|
||||||
// user: process.env.DB_USER,
|
|
||||||
// password: process.env.DB_PASSWORD,
|
|
||||||
// port: process.env.DB_PORT,
|
|
||||||
// database: 'travopti'
|
|
||||||
// });
|
|
||||||
|
|
||||||
const pool = mysql.createPool({
|
|
||||||
connectionLimit: 10,
|
|
||||||
host: process.env.DB_HOST,
|
|
||||||
user: process.env.DB_USER,
|
|
||||||
password: process.env.DB_PASSWORD,
|
|
||||||
port: process.env.DB_PORT,
|
|
||||||
database: 'travopti',
|
|
||||||
// typeCast: function (field, next) {
|
|
||||||
// if (field.type == "INT") {
|
|
||||||
// var value = field.string();
|
|
||||||
// return (value === null) ? null : Number(value);
|
|
||||||
// }
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
decimalNumbers: true
|
|
||||||
});
|
|
||||||
|
|
||||||
pool.getConnection()
|
|
||||||
.then(function (connection) {
|
|
||||||
console.log(`Connected to database: ${process.env.DB_HOST}`);
|
|
||||||
//pool.releaseConnection(connection)
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = pool;
|
|
||||||
|
|
||||||
// let travoptidb = {}
|
|
||||||
// travoptidb.all = () => {
|
|
||||||
// return new Promise((resolve, reject) => {
|
|
||||||
// pool.query(`SELECT * FROM regions`, (err, results) => {
|
|
||||||
// if (err) {
|
|
||||||
// return reject(err)
|
|
||||||
// }
|
|
||||||
// return resolve(results)
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// connection.connect((err) => {
|
|
||||||
// if (err) throw err;
|
|
||||||
// console.log('Database connected!')
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
// exports.getRegions = () => {
|
|
||||||
// let sql = `SELECT * FROM regions`;
|
|
||||||
// console.log(connection.state)
|
|
||||||
// if (connection.state === 'disconnected') {
|
|
||||||
// setTimeout(() => console.log('waiting...'), 1000);
|
|
||||||
// }
|
|
||||||
// console.log('executed')
|
|
||||||
// let res = {}
|
|
||||||
// connection.query(sql, (error, results, fields) => {
|
|
||||||
// if (error) {
|
|
||||||
// return console.error(error.message);
|
|
||||||
// }
|
|
||||||
// console.log('innercallback(1)')
|
|
||||||
// res = results[0]
|
|
||||||
// });
|
|
||||||
// console.log('outsidecallback(2)')
|
|
||||||
// return res;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// exports.getBYTdata = () => {
|
|
||||||
// connection.query(`SELECT * FROM regions_byt`, (error, results, fields) => {
|
|
||||||
// if (error) {
|
|
||||||
// return console.error(error.message);
|
|
||||||
// }
|
|
||||||
// console.log(results[0])
|
|
||||||
// nres = results.map((obj) => {
|
|
||||||
// return obj.region
|
|
||||||
// })
|
|
||||||
// //console.log(nres);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// exports.end = () => connection.end();
|
|
||||||
|
|
||||||
// module.exports = connection;
|
|
||||||
Loading…
Reference in New Issue
Block a user