- Route
/
: this route shows all available surveys to unregistered user. If logged in, only administrator's survey are shown - Route
/login
: route to login by using credentials (email and password) - Route
/survey/:surveyId
: route to answer a survey. Only unlogged user can access it, otherwise 404 page is shown. - Route
/admin/new
: route for logged administrators only. It allows the creation of a new survey. - Route
/admin/survey/:surveyId
: route for logged administrators only. It shows answers to a specific surveyId (only if the owner is the logged user). - Route
/404
: this route will be shown in case an invalid route is requested.
- GET
/api/surveys/all
- No parameters and/or body request
- Gives back a JSON of all available surveys title to unregistered users
[
{
"surveyId": 1,
"title": "How do you move in Turin?"
},
{
"surveyId": 2,
"title": "How's your Web Applications I exam going?"
},
{
"surveyId": 3,
"title": "Do you like science?"
},
{
"surveyId": 4,
"title": "No answers to this survey"
}
]
- GET
/api/surveys/my
- No parameters and/or body request
- Show all available surveys of a logged administrator
[
{ surveyId: 1, title: 'How do you move in Turin?', answersNumber: 2 },
{ surveyId: 4, title: 'No answers to this survey', answersNumber: 0 }
]
- GET
/api/surveys
- Id parameter of the survey to be searched
- Search a survey through its ID for unregistered users
{
"surveyId": 3,
"userId": 3,
"title": "Do you like science?",
"questions": [
{
"questionId": 1,
"surveyId": 3,
"title": "Do you watch Science fictions in TV?",
"min": 0,
"max": 1,
"options": [
{
"optionId": 1,
"surveyId": 3,
"questionId": 1,
"text": "Yes"
},
{
"optionId": 2,
"surveyId": 3,
"questionId": 1,
"text": "No"
}
]
},
{
"questionId": 2,
"surveyId": 3,
"title": "Say something about your passion for Science",
"mandatory": 1
}
],
"answersNumber": 1
}
-
POST
/api/surveys/new
- The body contains the title of the survey and the list of questions
- Add a new survey received from a registered administrator. It gives 200 OK on success, 400 if something is missing, 500 in case of errors.
-
POST
/api/surveys/answer
- The parameter is the ID of the survey that user is answering. Body contains the name of the user plus the list of answers.
- Add a new answer received from unregistered user. It gives 200 OK on success, 400 if something is missing, 404 if ID is wrong, 500 in case of errors.
-
GET
/api/surveys/get/answers
- Id parameter of the answers' survey to be searched
- Show all available answers of a survey to an administrator. It gives 200 OK on success, 404 if the ID of the survey is not of property of logged administrator, 500 in case of errors.
[
{
"name": "Carl",
"answers": [
{
"questionId": 1,
"selOptions": [
1,
2
]
},
{
"questionId": 2,
"openAnswer": "I love it!"
}
]
},
{
"name": "Victor",
"answers": [
{
"questionId": 1,
"selOptions": [
2
]
},
{
"questionId": 2,
"openAnswer": "I use bus"
}
]
}
]
- Table
users
- containsid
,email
,name
andhash
columns of a registered administrator - Table
surveys
- containssurveyId
that identifies a survey,userId
to identify the owner of a survey,title
of a survey,answersNumber
number of answers given to that survey,questions
a JSON column that contains all questions of a survey. - Table
answers
- containsanswerId
that identifies an answer,surveyId
to match the answer to a survey,name
of the user that answered,answers
a JSON column that contains all answers to a survey.
SurveyNavbar
(inSurveyNavbar.js
): renders the navbar, welcome message and login/logout buttons based onloggedIn
state property.LoginForm
(inLoginForm.js
): renders the login page based on a form put in aCard
element.AdminContent
(inAdminContent.js
): if administrator is logged, this component is rendered and makes a call to the API to fetch available surveys of an adminSurveyRow
(inAdminContent.js
): renders a row of a survey of the logged user by writing title, number of answers to that survey and "See answers" button.UserContent
(inUserContent.js
): unlogged users renders this page, which makes a call to the API to fetch all available surveys.SurveyRow
(inUserContent.js
): this object renders the title of a survey which is a link to answer that survey.NotFound
(inNotFound.js
): this component is rendered everytime something is not found.DoSurvey
(inDoSurvey.js
): this component gets the list of question of a survey and renders them to be answered. It contains also validation functions and anhandleSubmit
because the survey is rendered as a form.QuestionsList
(inDoSurvey.js
): renders open and closed questions. It is called for each question of a survey.ErrModal
(inDoSurvey.js
): this component is rendered only if there is a problem in the validation of the survey.NameBox
(inDoSurvey.js
): this component is rendered before the showing of the questions and validates the name of the user (only characters, minimum length: 3).ClosedQuestion
(inDoSurvey.js
): this components renders radio/checkbox form checks and also validates them based on min/max parameters.CreateSurvey
(inCreateSurvey.js
): this components renders the creation of a survey, based on a form. It shows first the required title of a survey, then renders the button "add questions". When everything is validated, calls an API to send survey to server.AddQuestionModal
(inCreateSurvey.js
): this components allows the creation of an open/closed question to a survey. It is another form which is validated and then the new question is created and added to the array.ShowAnswers
(inShowAnswers.js
): this component calls an API to fetch all answers to a survey. It renders also some button to navigate through the answers' array state. It is similar toDoSurvey
but all questions are disabled.
id | name | password | Surveys | |
---|---|---|---|---|
1 | [email protected] | admin | strong | How do you move in Turin? No answers to this survey |
2 | [email protected] | rob | impossible | How's your Web Applications I exam going? |
3 | [email protected] | student | polito | Do you like science? |