You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 8, 2021. It is now read-only.
if the database is realy busy, you can change the database name to your firstname.
Please do not commit the .env file. With this method, I want to prevent, that we are starting the development server on the live system, because this will remove all the data in the databse.
Database Tutorial
The connetion of the database is specified inside /db/db.js. The database initialisation script is located inside /db/init.sql. To use the Database in you .js files, you simplly do:
Before starting the project, you need to install all needed packages:
npm install
After a successfull install (Some package installs result in some warnings, but these can be connected, that you are not using a Mac) do:
npm run start
Session Tutorial
We use express-session (https://www.npmjs.com/package/express-session) to create an manage sessions. The client gets a sessionID. With that sessionID can be data associated (i.e. username) wich would normally be stored in the local storage of our server. I say normally, because we use the mysql extension of express-session (https://www.npmjs.com/package/express-mysql-session) wich allows us to store the data in our database, that enables us to use multiple servers for load balancing and persist sessions after server restarts. The session data (here username) can be accessed with:
req.session.username
I would recommend to read the documentation of express-session.
Error handling and validation
Validation
There is a Function to get the permissions of a user in a course. It is defined in ./src/courseFunctions.js. Basic usage is:
varpermission=require("./courseFunctions");permission(req.query.Semester,req.query.CourseName,req.session.username,function(perm){if(perm==="admin"){/* have fun */}else{// respond, that the user has the wrong permissionsnext(newError("wrong permissions or course not found"));}});
BUT THERE IS MORE!!!
Varriable validation is done by the database, which should return an error (can be mor or less easy to handle). For each api function, you PLEASE create a error handling script in ./apiFunctions/errorTranslation/, there are already more than enough examples. Then you insert your error translation into ./apiFunctions/errorTranslation.js. To use your error translation in your code, you can do:
varerrorTranslation=require("../apiFunctions/errorTranslation");// some codesql.query("blablabla",[bla,blub,quark],function(error,results,fields){if(error)returnnext(errorTranslation.theErrorFunctionThatYouWroteOutOfFreeWill(error));});// other code
Error Handling
If you want to throw an error in your function to notify the api user, you can to