src/models/flow/FlowStep.js
/**
* Model representing a step in a flow process.
*/
class FlowStepModel {
/**
* @param {Object} response - JSON formatted response of a step
* @param {Number} response.id - The id of the step
* @param {Object} response.title - The title of the step
* @param {Object} response.description - Description, if any, that explain how to answer
* the step
* @param {String} response.content_type - The format of the step (e.g. single choice,
* multiple choice)
* @param {String} response.image - An image
* @param {Array} response.inputs - Array of inputs
* @param {Array} response.paths - An array of next steps available to the user
* @param {Boolean} response.send_on_capture - Save now or later
*/
constructor(response = {}) {
const _response = response.data || response; // if json api is passed in directly
const attributes = _response.attributes || _response; // if json api is passed in directly
delete attributes.type;
Object.assign(this, attributes); // make sure that we get any custom fields
if (_response.id) {
/** @type {Number} */
this.id = parseInt(_response.id, 10);
if (isNaN(_response.id)) {
this.id = _response.id;
/** @type {String} */
this.permanentLink = _response.id;
}
}
/** @type {Object} */
this.title = attributes.title;
/** @type {Object} */
this.description = attributes.description;
/** @type {String} */
this.content_type = attributes.content_type;
/** @type {Object} */
this.image = attributes.image;
/** @type {Array} */
this.inputs = attributes.inputs || [];
/** @type {Array} */
this.paths = attributes.paths || [];
/** @type {Boolean} */
this.sendOnCapture = attributes.send_on_capture === true;
/** @type {Number} */
this.flowProcessId = attributes.flow_process_id;
}
}
export default FlowStepModel;