Web application for managing the creation of an online survey and the collection of responses through that survey.
- Route
/: homepage page for the website, used to show available surveys and to login if the user is an admin - Route
/survey/:id: page for filling the survey with the correspondingid - Route
/admin: Initial page for the administrator (protected by authentication) - Route
/admin/newSurvey: page for creating a new survey (protected by authentication) - Route
/admin/viewSurveys: page for viewing all surveys created by the admin (protected by authentication) - Route
/admin/survey/:surveyId: page for viewing the answers given by users to the survey with the correspondingsurveyId(protected by authentication) - Route
/login: page used to log in
-
GET
/api/surveys- description: get all surveys that a user can fill
- request parameters: none
- response:
200 OK(success) or500 Internal Server Error(generic error) - response body content: array of objects, each describing a surveys available (id and title)
[{ "id": 1, "title": "Survey1" }, { "id": 2, "title": "Survey2" }, ... ]
-
GET
/api/survey/:id- description: get all questions related to the survey with the corresponding
id - request parameters:
idof the survey - response:
200 OK(success),400 Bad Request(error in passed parameter) or500 Internal Server Error(generic error) - response body content: array of objects, describing the questions of the survey; error object in case of wrong parameter
Successful response:Error response:[{ "id": 1, "type": "open", "title": "Question 1", "answers": "", "min": 0, "max": 0, "mandatory": 0, "position": 0 },{ "id": 2, "type": "closed", "title": "Question 2", "answers":"[\"MCQ1 answer\",\"MCQ2 answer\",\"MCQ3 answer\",\"MCQ4 answer\"]", "min": 2, "max": 2, "mandatory": 1, "position":1 }, ... ]{ "info": "The server cannot process the request", "error": "Invalid value", "valueReceived": "WrongParameterPassedAsId" }
- description: get all questions related to the survey with the corresponding
-
GET
/api/groupId- description: get the new id used to group answers given by a user
- request parameters: none
- response:
200 OK(success) or500 Internal Server Error(generic error) - response body content: next id to be used for grouping answers
5
-
POST
/api/submit- description: submit one single answer given by the user
- request parameters: none
- request body: object describing the answer to a single question given by the user
Closed answer object:Open answer object:{ "groupId": 5, "surveyId": 1, "questionId": 1, "type": "closed", "answer": "[0]", "user": "User 1", "min": 0, "max": 1, "numAnswers": 3 }{ "groupId": 5, "surveyId": 1, "questionId": 2, "type": "open", "answer": "Answer to the open question", "user": "User 1", "mandatory": 0 } - response:
200 OK(success),400 Bad Request(error in passed parameters) or500 Internal Server Error(generic error) - response body content: none in case of success, error object in case of error
Error in min, max and number of questions constraints for closed questions:{ "info": "The server cannot process the request", "errors": [ { "param": "groupId", "error": "Invalid value" }, { "param": "type", "error": "Invalid value" }, ... ] }{ "info": "The server cannot process the request", "type": "Closed question", "error": "Min, max, numAnswers or the answers are not valid due to the constraints between them" }
-
POST
/api/createSurvey- description: create the survey entry in the database with the corresponding questions
- request parameters: none
- request body: object describing the new survey (
owneris the admin currently logged in){ "title": "Survey title", "questions":[{ "surveyId": -1, "type": "open", "title": "Question 1", "answers": [""], "min": 0, "max": 1, "mandatory": false, "position": 0 },{ "surveyId": -1, "type": "closed", "title":"Question 2", "answers":["MCQ1 answer","MCQ2 answer"], "min": 1, "max": 1, "mandatory": true, "position": 1 } ... ], "owner": 2 } - response:
200 OK(success),400 Bad Request(error in passed parameters) or500 Internal Server Error(generic error) - response body content: none in case of success, error object in case of error (in
titleorowner) or none in case of error in at least one of the questions passed in the request object{ "info": "The server cannot process the request", "errors": [ { "param": "owner", "error": "Invalid value" }, { "param": "title", "error": "Invalid value" } ] }
-
GET
/api/surveys/admin/:id- description: get all surveys created by the admin logged in
- request parameters:
idof the admin - response:
200 OK(success),400 Bad Request(error in passed parameter) or500 Internal Server Error(generic error) - response body content: array of objects, each describing a surveys created by the admin logged in (id, title and number of answers); error object in case of error
Successful response:Error response:[{ "id": 1, "title": "Survey1", "numAnswer": 3 }, { "id": 2, "title": "Survey2", "numAnswer": 2 }, ... ]{ "info": "The server cannot process the request", "error": "Invalid value", "valueReceived": "WrongParameterPassedAsId" }
-
GET
/api/survey/:surveyId/admin/:adminId- description: get all questions related to the survey with the corresponding
surveyIdcreated by the admin with the correspondingadminId - request parameters:
surveyIdof the survey andadminIdof the admin - response:
200 OK(success),400 Bad Request(error in passed parameters) or500 Internal Server Error(generic error) - response body content: object of array of objects, each one describing the answers of the survey given by a user (each key represents a
groupIdand the value associated is the array with the answers given by the user); error object in case of error
Successful response:Error response:{ "4": [{ "groupId": 4, "type": "open", "answer": "Answer to open question x", "user": "User 1", "position": 0, "title": "Question 1", "answers": "[\"\"]" },{ "groupId": 4, "type": "closed", "answer": "[0]", "user": "User 1", "position": 1, "title": "Question 2", "answers": "[\"MCQ answer 1\",\"MCQ answer 2\",\"MCQ answer 3\"]" }, ... ], "5": [{ "groupId": 5, "type": "open", "answer": "Answer to open question y", "user": "User 2", "position": 0, "title": "Question 1", "answers": "[\"\"]" },{ "groupId": 5, "type": "closed", "answer": "[0]", "user": "User 2", "position": 1, "title": "Question 2", "answers": "[\"MCQ answer 1\",\"MCQ answer 2\",\"MCQ answer 3\"]" }, ... ], ... }{ "info": "The server cannot process the request", "errors": [ { "param": "surveyId", "error": "Invalid value", "valueReceived": "WrongParameterPassedAsId" }, { "param": "adminId", "error": "Invalid value", "valueReceived": "WrongParameterPassedAsId" } ] }
- description: get all questions related to the survey with the corresponding
-
POST
/api/sessions- description: request to log in an admin
- request parameters: none
- request body: object describing the user
{ "username": "john@polito.it", "password": "1234abcd" } - response:
200 OK(success) or500 Internal Server Error(generic error) - response body content: user if the login was successful, error otherwise
Successful login:Login error:{ "id": 1, "username": "john@polito.it", "name":"John" }{ "message": "Incorrect username and/or password." }
-
DELETE
/api/sessions/current- description: request to log out an admin
- request parameters: none
- response:
200 OK(success) or500 Internal Server Error(generic error) - response body content: none
-
GET
/api/sessions/current- description: get the status about the user, if he/she is logged in or not
- request parameters: none
- response:
200 OK(success) or401 Unauthorized(authentication error) - response body content: user if he/she is logged in, error otherwise
User already logged in:User not logged in:{ "id": 1, "username": "john@polito.it", "name":"John" }{ "error":"Unauthenticated user!" }
- Table
adminis used to store admin information and the password is not the actual password but its hash. It containsidusernamepasswordname - Table
answersis used to store all answers given by users during filling process. It containsidgroupIdsurveyIdquestionIdtypeansweruser - Table
questionsis used to store the questions related to a survey. It containsidsurveyIdtypetitleanswersminmaxmandatoryposition - Table
surveysis used to store high level information about surveys, then the actual survey to be shown is obtained combining this table and thequestionsone. It containsidtitleowner
Surveys(inSurvey.js): component to generate a list of surveys (for the user side)SurveyItem(inSurvey.js): component to generate a single entity survey (for the user side)Questions(inSurvey.js): component to generate the list of questions of a surveyQuestion(inSurvey.js): single question component, it handles both closed-answer and open-ended questions (the type can be chosen with the propstype)UserNameField(inSurvey.js): username component, it handles the username field before actual questionsSurveysAdmin(inSurveyAdmin.js): component to generate a list of surveys (for the admin side)SurveyAdminItem(inSurveyAdmin.js): component to generate a single entity survey (for the admin side)AddNewQuestionModal(inSurveyAdmin.js): component to generate a modal to create a new question (it handles both closed-answer and open-ended questions)QuestionsAdmin(inSurveyAdmin.js): component to generate the list of questions of a survey not yet published (used in the survey creation process)QuestionAdmin(inSurveyAdmin.js): single question component, it handles both closed-answer and open-ended questions (the type can be chosen with the propstype); this component just shows how the question will be displayed to the users, but fields cannot be filled by the admin during the survey creation processSurveyTitleField(inSurveyAdmin.js): survey title component, it handles the survey title field before actual questionsViewAnswersOneSurvey(inSurveyAdmin.js): component to render all answers from all users (it shows one user at a time, then the admin can move between users' answers using buttons)Login(inLogin.js): component to get data from admin for the loginUnauthorizedUserMessage(inLogin.js): component to render error message if a page is accessed without permissions
- username:
john@polito.it, password:1234abcd- Created surveys:
- Restaurant review
- Music survey
- Running survey
- Created surveys:
- username:
emily@polito.it, password:5678efgh- Created surveys:
- Holiday survey
- Exam test
- Created surveys: