From 29666babbcfefeebe996f5e0d87fb48b073db153 Mon Sep 17 00:00:00 2001 From: Timo John Date: Fri, 10 Jul 2020 15:16:04 +0200 Subject: [PATCH] Add comments --- backend/index.js | 9 ++------- backend/util/base64.js | 10 ++++++++++ backend/util/databaseArrayFormatting.js | 5 +++++ backend/util/getAllRegionsWithClimatePerMonth.js | 2 -- backend/util/sqlstring_sanitizer.js | 7 ++++++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/backend/index.js b/backend/index.js index cac2fa7..58d9037 100644 --- a/backend/index.js +++ b/backend/index.js @@ -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); } diff --git a/backend/util/base64.js b/backend/util/base64.js index d4d9583..f5e8039 100644 --- a/backend/util/base64.js +++ b/backend/util/base64.js @@ -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') } \ No newline at end of file diff --git a/backend/util/databaseArrayFormatting.js b/backend/util/databaseArrayFormatting.js index 7f705b3..eebf83d 100644 --- a/backend/util/databaseArrayFormatting.js +++ b/backend/util/databaseArrayFormatting.js @@ -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 diff --git a/backend/util/getAllRegionsWithClimatePerMonth.js b/backend/util/getAllRegionsWithClimatePerMonth.js index 557afbc..0ee0f6f 100644 --- a/backend/util/getAllRegionsWithClimatePerMonth.js +++ b/backend/util/getAllRegionsWithClimatePerMonth.js @@ -1,5 +1,3 @@ - - module.exports = function (dbConn) { return async function getAllRegionsWithClimatePerMonth(month) { console.log('getAllRegionsWithClimatePerMonth') diff --git a/backend/util/sqlstring_sanitizer.js b/backend/util/sqlstring_sanitizer.js index 286b516..e1c016a 100644 --- a/backend/util/sqlstring_sanitizer.js +++ b/backend/util/sqlstring_sanitizer.js @@ -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)