Add comments
This commit is contained in:
parent
2c16bbf3e7
commit
29666babbc
@ -19,10 +19,9 @@ const update = require("./routes/update");
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// Swagger API doc set up
|
||||||
const swaggerJsdoc = require('swagger-jsdoc');
|
const swaggerJsdoc = require('swagger-jsdoc');
|
||||||
const swaggerUi = require('swagger-ui-express');
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
|
||||||
// Swagger set up
|
|
||||||
const swaggerOptions = {
|
const swaggerOptions = {
|
||||||
swaggerDefinition: {
|
swaggerDefinition: {
|
||||||
openapi: "3.0.0",
|
openapi: "3.0.0",
|
||||||
@ -43,9 +42,6 @@ const swaggerOptions = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
servers: [
|
servers: [
|
||||||
{
|
|
||||||
url: "http://localhost:3000/api/v1"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
url: "https://travopti.de/api/v1"
|
url: "https://travopti.de/api/v1"
|
||||||
}
|
}
|
||||||
@ -57,11 +53,11 @@ const swaggerOptions = {
|
|||||||
"./Models/handleClimateUpdateV2.js",
|
"./Models/handleClimateUpdateV2.js",
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const swaggerDocs = swaggerJsdoc(swaggerOptions);
|
const swaggerDocs = swaggerJsdoc(swaggerOptions);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
|
// Connect to MariaDB
|
||||||
const dbConn = await dbConnection();
|
const dbConn = await dbConnection();
|
||||||
|
|
||||||
// Express middleware
|
// Express middleware
|
||||||
@ -92,7 +88,6 @@ const swaggerDocs = swaggerJsdoc(swaggerOptions);
|
|||||||
console.log(`Travopti backend listening at http://localhost:${port}`)
|
console.log(`Travopti backend listening at http://localhost:${port}`)
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// TODO: logging
|
|
||||||
console.error("Failed to start the webserver");
|
console.error("Failed to start the webserver");
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,20 @@ exports.base64ToObj = function(base64) {
|
|||||||
return JSON.parse(atob(base64));
|
return JSON.parse(atob(base64));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a base64 encoded object.
|
||||||
|
* @param base64 encoded object
|
||||||
|
* @returns {string} decoded object
|
||||||
|
*/
|
||||||
function atob(base64) {
|
function atob(base64) {
|
||||||
return Buffer.from(base64, 'base64').toString('binary')
|
return Buffer.from(base64, 'base64').toString('binary')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes an object as base64 string.
|
||||||
|
* @param string The object to encode
|
||||||
|
* @returns {string} base64 encoded object
|
||||||
|
*/
|
||||||
function btoa(string) {
|
function btoa(string) {
|
||||||
return Buffer.from(string).toString('base64')
|
return Buffer.from(string).toString('base64')
|
||||||
}
|
}
|
||||||
@ -1,3 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Seperate Strings created via GROUP_CONCAT by database into an array
|
||||||
|
* @param array String with comma-seperated values
|
||||||
|
* @returns [float] array of float values
|
||||||
|
*/
|
||||||
module.exports = (array) => {
|
module.exports = (array) => {
|
||||||
if (array !== null && array !== undefined) {
|
if (array !== null && array !== undefined) {
|
||||||
const value = array
|
const value = array
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
module.exports = function (dbConn) {
|
module.exports = function (dbConn) {
|
||||||
return async function getAllRegionsWithClimatePerMonth(month) {
|
return async function getAllRegionsWithClimatePerMonth(month) {
|
||||||
console.log('getAllRegionsWithClimatePerMonth')
|
console.log('getAllRegionsWithClimatePerMonth')
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
const sqlstring = require("sqlstring")
|
const sqlstring = require("sqlstring")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes value if it isn't a numerical value
|
||||||
|
* @param val
|
||||||
|
* @returns string Sanitized String
|
||||||
|
*/
|
||||||
module.exports = (val) => {
|
module.exports = (val) => {
|
||||||
if(!isNaN(val)) {
|
if(!isNaN(val)) { // Checks if the value is a numerical value (in a string)
|
||||||
return val
|
return val
|
||||||
} else {
|
} else {
|
||||||
return sqlstring.escape(val)
|
return sqlstring.escape(val)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user