Survey API

Description of the functionality of Survey API

API

Note: The following is defined in express/routes/survey.route.js

Headers

Private qmd: ng-client <'SESSION_ID': [token] Secure Cookie

Public qmd: ng-client

Get All Survey Data

<url>/api/

i.e. http://localhost:8080/api/

Method

Description

Access

GET

Respond with all survey data

Private

Adding New Survey

<url>/api/ add

i.e. http://localhost:8080/api/add

Method

Description

Access

POST

Create a new survey data item

Private

Accessing/Updating Specific Survey Data (from ID)

<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.

Managing Statements (DEPRECIATED 0.0.8a)

<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

Middleware

Access through src/app/survey.service.ts

Importing Into Component

import { SurveyService } from '../../survey.service'; import { Survey } from '../../Survey'; ... export class ... { constructor( ... , private surveyservice: SurveyService) }

Functions

src/app/survey.service.ts

Adding Authorization Header

Adds api key as a HttpHeader

addAuthHeader(api_key)

Param

Type

Description

api_key

string

API Key for authentication

Adding a New Survey

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)

Get all surveys

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

Get a survey

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

Update survey

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

A survey object (See Models)

return

HttpResponse<>

HttpErrorResponse

Response (200/400)

Example

// 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 });

Delete survey

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)

Example

this.surveyservice.deleteSurvey(id).subscribe(res => { this.ngOnInit(); console.log('Deleted'); }); // On successful response, re-render

Add statement to survey

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)

Delete statement from survey

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)

Last updated