survey-model

Methods

(static) createNewEnketoId(idopt, triesRemainingopt) → {Promise.<(Error|string|Promise)>}

Source:

Generates a new random Enketo ID that has not been used yet, or checks whether a provided id has not been used. 8 characters keeps the chance of collisions below about 10% until about 10,000,000 IDs have been generated

Parameters:
Name Type Attributes Description
id string <optional>

This is only really included to write tests for collissions or a future "vanity ID" feature

triesRemaining number <optional>

Avoid infinite loops when collissions become the norm.

Returns:

a Promise that resolves with a new unique Enketo ID

Type
Promise.<(Error|string|Promise)>

(static) get(id) → {Promise.<SurveyObject>}

Source:

Returns the information stored in the database for an enketo id.

Parameters:
Name Type Description
id string

Survey ID

Returns:

Promise that resolves with a survey object

Type
Promise.<SurveyObject>

(static) getId(survey) → {Promise.<(Error|null|string)>}

Source:
Parameters:
Name Type Description
survey module:survey-model~SurveyObject

survey object

Returns:

Promise that resolves with survey ID

Type
Promise.<(Error|null|string)>

(static) getList(server) → {Promise.<(Error|Array.<SurveyObject>)>}

Source:
Parameters:
Name Type Description
server string

Server URL

Returns:

Promise that resolves with a list of SurveyObjects

Type
Promise.<(Error|Array.<SurveyObject>)>

(static) getNumber(server) → {Promise.<(Error|string|number)>}

Source:
Parameters:
Name Type Description
server string

Server URL

Returns:

Promise that resolves with number of surveys

Type
Promise.<(Error|string|number)>

(static) incrementSubmissions(id) → {Promise.<(Error|string)>}

Source:
Parameters:
Name Type Description
id string

Survey ID

Returns:

Promise that eventually resolves with survey ID

Type
Promise.<(Error|string)>

(static) set(survey) → {Promise.<(Error|string)>}

Source:

Function for updating or creating a survey

Parameters:
Name Type Description
survey SurveyObject

survey object

Returns:

Promise that eventually resolves with Survey ID

Type
Promise.<(Error|string)>

(static) update(survey) → {Promise.<(Error|string)>}

Source:
Parameters:
Name Type Description
survey module:survey-model~SurveyObject

survey object

Returns:

Promise that resolves with survey ID

Type
Promise.<(Error|string)>

(inner) _404Empty(error) → {object}

Source:
Parameters:
Name Type Description
error Error

error object

Returns:

Empty object for 404 errors; throws normally for other

Type
object

(inner) _addSurvey(openRosaKey, survey) → {Promise.<(Error|string)>}

Source:
Parameters:
Name Type Description
openRosaKey string
survey module:survey-model~SurveyObject

survey object

Returns:

Promise that eventually resolves with survey ID

Type
Promise.<(Error|string)>

(inner) _ascendingLaunchDate(a, b) → {number}

Source:

Function for launch date comparison

Parameters:
Name Type Description
a module:survey-model~SurveyObject

a survey object

b module:survey-model~SurveyObject

a survey object

Returns:

difference in launch date as a number

Type
number

(inner) _getActiveSurveys(openRosaIds) → {Promise.<SurveyObject>}

Source:
Parameters:
Name Type Description
openRosaIds Array.<string>

A list of openRosaIds

Returns:

a Promise that resolves with a list of survey objects

Type
Promise.<SurveyObject>

(inner) _getEnketoId(openRosaKey) → {Promise.<(Error|null|string)>}

Source:
Parameters:
Name Type Description
openRosaKey string

database key of survey

Returns:

Promise that resolves with survey ID

Type
Promise.<(Error|null|string)>

(inner) _nonEmpty(survey) → {boolean}

Source:
Parameters:
Name Type Description
survey module:survey-model~SurveyObject

survey object

Returns:

Whether survey has openRosaId

Type
boolean

(inner) _updateProperties(id, survey) → {Promise.<(Error|string)>}

Source:
Parameters:
Name Type Description
id string

Survey ID

survey module:survey-model~SurveyObject

New survey

Returns:

Promise that resolves with survey ID

Type
Promise.<(Error|string)>

Type Definitions

EnketoTransformerPreprocess(doc) → {XMLJSDocument}

Source:
Parameters:
Name Type Description
doc XMLJSDocument
Returns:
Type
XMLJSDocument

ManifestItem

Source:
Properties:
Name Type Description
downloadUrl string
filename string
hash string

SurveyCredentials

Source:
Properties:
Name Type Description
user string
pass string
bearer string

SurveyExternalData

Source:
Properties:
Name Type Description
id string
src string
xml string | Document

SurveyInfo

Source:
Properties:
Name Type Description
downloadUrl string
manifestUrl string

SurveyObject

Source:
Properties:
Name Type Attributes Description
openRosaServer string
openRosaId string
enketoId string
theme string
info SurveyInfo <optional>
account AccountObj <optional>
active boolean | 'true' | 'false' <optional>
cookie string <optional>
credentials SurveyCredentials <optional>
customParam string <optional>
externalData Array.<(SurveyExternalData|undefined)> <optional>
form string <optional>
formHash string <optional>
instance EnketoRecord <optional>
instanceAttachments Array.<(string|object)> <optional>
instanceId string <optional>
lastSavedRecord EnketoRecord <optional>
languageMap Record.<string, unknown> <optional>
manifest Array.<ManifestItem> <optional>
model string <optional>
preprocess EnketoTransformerPreprocess <optional>
returnUrl string <optional>
xslHash string <optional>

SurveyObject is Enketo's internal representation of an XForm, with some additional properties representing resolved/deserialized external data. This type definition captures the current state of "what is"—i.e. the full known set of properties which may be added to a SurveyObject through several data flow paths throught enketo-express. Some related resources, notably those describing instances, are only populated in paths specific to the interaction between a SurveyObject and those resources.