src/models/flow/Flow.js
/**
* Model representing a flow process (flow template).
*/
class FlowModel {
/**
* @param {Object} response - JSON formatted response of a flow process (flow template)
* @param {Number} response.id - The id of the content
* @param {String} response.name - The id of the content
* @param {Array} response.steps - The array of steps in the flow process (flow template)
* @param {Number} response.first_step - The id of the first step
* @param {Number} response.total - The total number of steps
*/
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
// @TODO This is to help support v3, eventually we don't need this logic
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}`;
}
if (attributes.permanent_link) {
this.permanentLink = attributes.permanent_link;
}
/** @type {String} */
this.name = attributes.name;
/** @type {Array} */
this.steps = response.steps || [];
/** @type {Number} */
this.first_step = response.first_step;
/** @type {Number} */
this.total = response.total;
// v3 --------
if (response.relationships && response.relationships.linked_steps) {
this.steps = response.relationships.linked_steps.data;
this.total = this.steps.length;
}
if (response.relationships && response.relationships.initial_step) {
this.first_step = response.relationships.initial_step.data;
}
if (response.relationships && response.relationships.published) {
this.published = response.relationships.published.data;
}
if (response.relationships && response.relationships.draft) {
this.draft = response.relationships.draft.data;
}
/** @type {String} */
this.conditionalPaths = attributes.conditional_paths;
/** @type {String} */
this.consentCredentials = attributes.consent_credentials;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.owner_type = attributes.owner_type;
// this.ownerType = attributes.owner_type;
/** @type {String} */
this.publishedAt = attributes.published_at;
/** @type {String} */
this.updatedAt = attributes.updated_at;
/** @type {String} */
this.description = attributes.description;
}
}
export default FlowModel;