Add comments

This commit is contained in:
Timo John 2020-07-10 15:16:04 +02:00
parent 2c16bbf3e7
commit 29666babbc
5 changed files with 23 additions and 10 deletions

View File

@ -19,10 +19,9 @@ const update = require("./routes/update");
const app = express();
// Swagger API doc set up
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
// Swagger set up
const swaggerOptions = {
swaggerDefinition: {
openapi: "3.0.0",
@ -43,9 +42,6 @@ const swaggerOptions = {
}
},
servers: [
{
url: "http://localhost:3000/api/v1"
},
{
url: "https://travopti.de/api/v1"
}
@ -57,11 +53,11 @@ const swaggerOptions = {
"./Models/handleClimateUpdateV2.js",
]
};
const swaggerDocs = swaggerJsdoc(swaggerOptions);
(async () => {
try {
// Connect to MariaDB
const dbConn = await dbConnection();
// Express middleware
@ -92,7 +88,6 @@ const swaggerDocs = swaggerJsdoc(swaggerOptions);
console.log(`Travopti backend listening at http://localhost:${port}`)
});
} catch (error) {
// TODO: logging
console.error("Failed to start the webserver");
console.error(error);
}

View File

@ -14,10 +14,20 @@ exports.base64ToObj = function(base64) {
return JSON.parse(atob(base64));
}
/**
* Decodes a base64 encoded object.
* @param base64 encoded object
* @returns {string} decoded object
*/
function atob(base64) {
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) {
return Buffer.from(string).toString('base64')
}

View File

@ -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) => {
if (array !== null && array !== undefined) {
const value = array

View File

@ -1,5 +1,3 @@
module.exports = function (dbConn) {
return async function getAllRegionsWithClimatePerMonth(month) {
console.log('getAllRegionsWithClimatePerMonth')

View File

@ -1,7 +1,12 @@
const sqlstring = require("sqlstring")
/**
* Sanitizes value if it isn't a numerical value
* @param val
* @returns string Sanitized String
*/
module.exports = (val) => {
if(!isNaN(val)) {
if(!isNaN(val)) { // Checks if the value is a numerical value (in a string)
return val
} else {
return sqlstring.escape(val)