Services/CitizenService

Used by the "CitizenController" to transform HTTP request into request for the models in a way that allows for code reuse between POST/PUT requests

Source:
See:
To Do:
  • Maybe dont exports prepare functions themselves

Methods

(static) addSteps(request, input, prepareFunction) → {Object}

Source:

Processes the input according to the type of request.

Parameters:
Name Type Description
request Object

Express request object, used to initialize models

input Object

Key-Value pairs containing stepname-stepvalue

prepareFunction function

Either module:Services/CitizenService.preparePost or module:Services/CitizenService.preparePut, depending on what type of request is required

Returns:
  • Object containing a list of which steps where added and which steps were edited
Type
Object

(static) preparePost(steps, patterns, storedQuads) → {PreparedReturn}

Source:

Determines which patterns need to be added, edited or deleted based on the input patterns and currently stored quads.

Appends new values to existing steps if a list of values is supplied, otherwise edits steps that are already presesent with a new value

To be used in module:Services/CitizenService.addSteps.

Parameters:
Name Type Description
steps Array

An array of objects representing the steps as {name:..., value:...}

patterns Array.<String>

Array of pattern objects as returned by StepModel.getInputPatternByStep

storedQuads Array.<Array>

Array of currently stored quads for every pattern

Returns:
Type
PreparedReturn

(static) preparePut(steps, patterns, storedQuads) → {PreparedReturn}

Source:

Determines which patterns need to be added, edited or deleted based on the input patterns and currently stored quads.

Overwrites existing steps if a list of values is supplied or if multiple values are already present, otherwise edits steps that are already presesent with a new value.

To be used in module:Services/CitizenService.addSteps.

Parameters:
Name Type Description
steps Array

An array of objects representing the steps as {name:..., value:...}

patterns Array.<String>

Array of pattern objects as returned by StepModel.getInputPatternByStep

storedQuads Array.<Array>

Array of currently stored quads for every pattern

Returns:
Type
PreparedReturn

(async, inner) getStepsAndPatternsFromInput(stepModel, input) → {Array}

Source:
To Do:
  • Maybe dont throw on a bad step name but just not include it

Retrieves the inputpatterns (from reasoning/interim/input/input_patterns.n3") that match the steps provided in "input" Also maps the input into an object thats easyer to use

Parameters:
Name Type Description
stepModel StepModel

StepModel to use to retrieve and check all patterns

input any

Key-Value pairs containing stepname-stepvalue

Throws:
  • If a provided step doesn't exist
Returns:
  • Array containing two elements: - An array of objects representing the steps as {name:..., value:...} - An array of the patterns (strings) deduced from the stepnames
Type
Array

Type Definitions

PreparedReturn

Source:
To Do:
  • Bad name
Properties:
Name Type Description
0 Object

Key-value pairs step names - step values of steps which need to be added.

1 Array

List of existing quads that need to be edited.

2 Array

New values of the abovementioned quads that need editing

3 Array

List of stored patterns that need to be deleted

4 Object

Lists of steps that have been edited or added.

Properties
Name Type Description
edited Array

List of edited steps

added Array

List of added steps

Type:
  • Array