Survey API
Description of the functionality of Survey API
Last updated
Description of the functionality of Survey API
Last updated
Note: The following is defined in express/routes/survey.route.js
Private
qmd: ng-client
<'SESSION_ID': [token] Secure Cookie
Public
qmd: ng-client
<url>/api/
i.e. http://localhost:8080/api/
Method
Description
Access
GET
Respond with all survey data
Private
<url>/api/ add
i.e. http://localhost:8080/api/add
Method
Description
Access
POST
Create a new survey data item
Private
<url>/api/ :id
i.e. http://localhost:8080/api/SomeSurveyID
Method
Description
Access
GET
Respond with survey data corresponding to id*
Private/Public
POST
Update survey data item corresponding to id
Private
DELETE
Remove survey data item corresponding to id
Private
*Note: When accessed without private key, scrub data before returning
When sending POST request through API, remember to include all valid fields.
<url>/api/ :id/addState
i.e. http://localhost:8080/api/SomeSurveyID/addState
Method
Description
Access
POST
Append new statement to this survey data item
Private
<url>/api/ :id/delState/:index
i.e. http://localhost:8080/api/SomeSurveyID/delState/SomeStatementIndex
Method
Description
Access
DELETE
Delete statement corresponding to {:index} from survey {:id}
Private
Access through src/app/survey.service.ts
import { SurveyService } from '../../survey.service';
import { Survey } from '../../Survey';
...
export class ... {
constructor( ... , private surveyservice: SurveyService)
}
src/app/survey.service.ts
Adds api key as a HttpHeader
addAuthHeader(api_key)
Param
Type
Description
api_key
string
API Key for authentication
Contacts Survey API through HTTP to add a new survey to the database
addSurvey(name, range, statements)
Param
Type
Description
name
string
String corresponding to the survey's name
range
number
Horizontal-x range of survey's Q-Sort Table
statements
string[]
Array of statement strings
return
HttpResponse<>
HttpErrorResponse
Response (200/400)
Queries Survey API through HTTP for all the survey data in the database, returns array of surveys.
getSurveys()
Param
Type
Description
return
Array of Survey data
Queries Survey API through HTTP given an id, if a survey with this id is in the database, returns survey corresponding to this id.
getSurvey(id)
Param
Type
Description
id
string
ID corresponding to the survey data desired
return
Survey data
Queries Survey API through HTTP with Survey data, returns response from server. *WIP: Need to clean this function up.
updateSurvey(survey)
Param
Type
Description
survey
return
HttpResponse<>
HttpErrorResponse
Response (200/400)
// Requires router in constructor
this.route.params.subscribe(params => {
survey.name = name;
survey.range = range;
this.surveyservice.updateSurvey(survey)
.subscribe( res => this.successfulUpdate(res, false),
// On success, run success function
err => this.failedUpdate(err));
// On error, run error function
});
Queries Survey API through HTTP to delete Survey corresponding to id, returns response from server.
deleteSurvey(id)
Param
Type
Description
id
string
ID corresponding to the survey data desired
return
HttpResponse<>
HttpErrorResponse
Response (200/400)
this.surveyservice.deleteSurvey(id).subscribe(res => {
this.ngOnInit();
console.log('Deleted');
});
// On successful response, re-render
Queries Survey API through HTTP to add statement to survey corresponding to id, returns response from server.
addStatement(id, statement)
Param
Type
Description
id
string
ID corresponding to the survey data desired
statement
string
String of statement to be appended to statements array
return
HttpResponse<>
HttpErrorResponse
Response (200/400)
Queries Survey API through HTTP to delete statement from survey corresponding to id, returns response from server.
deleteStatement(id, statement_id)
Param
Type
Description
id
string
ID corresponding to the survey data desired
statement_id
number
Array index value of statement to be removed
return
HttpResponse<>
HttpErrorResponse
Response (200/400)
[]
A survey object (See )