src/helpers/flow/FlowKeyValue.js
import Helper from '../Helper';
import FlowKeyValueModel from '../../models/flow/FlowKeyValue';
import FlowService from '../../services/FlowService';
import { aggregate } from '../../utilities/ClassUtility';
/**
* Helper class representing Flow Data (Flow Process Value).
*/
class FlowKeyValue extends aggregate(FlowKeyValueModel, Helper) {
/**
* Constructor for helper class representing Flow Data (Flow Process Value)
*
* @param {Object} json - json api response from server
*/
constructor(json = {}) {
super(json);
this.deserializeRelationshipStubs(json);
this.syncRelationships(json);
}
/** @type {String} - The type */
get type() {
return 'data_collection__flow_process_values';
}
/** @type {Flow} */
get flow() {
return this._relationships.flow_process;
}
/** @type {Flow} */
set flow(flow) {
/** @type {Flow} */
this._relationships.flow_process = flow;
}
/** @type {FlowDataGroup} */
get flowDataGroup() {
return this._relationships.captured_value_group;
}
/** @type {FlowDataGroup} */
set flowDataGroup(flowDataGroup) {
/** @type {FlowDataGroup} */
this._relationships.captured_value_group = flowDataGroup;
}
/** @type {Helper} */
get owner() {
return this._relationships.owner;
}
/** @type {Helper} */
set owner(owner) {
/** @type {Helper} */
this._relationships.owner = owner;
}
/**
* Delete (soft delete / hide) a flow process value resource given an id
*
* http://clinical6-docs.s3-website-us-east-1.amazonaws.com/apidoc/v3data_collectionflow_process_values/destroy.html
*
* @return {Promise<any>} - Promise object that returns success or failure
*
* @example
* import { FlowKeyValue } from 'clinical6';
*
* const kfv = new FlowKeyValue({...});
* kfv.delete();
*/
delete() {
return (new FlowService()).deleteKeyValue(this);
}
/**
* Saves a flow key value (insert if id doesn't exist, update if it does)
*
* http://clinical6-docs.s3-website-us-east-1.amazonaws.com/apidoc/v3data_collectionflow_process_values/create.html
*
* @return {Promise<FlowKeyValue>} - Returns a promise via ajax call.
*
* @example
* import { FlowKeyValue, flowService } from 'clinical6';
*
* // Inserts new flow key value (no existing id)
* const flowKeyValue = new FlowKeyValue({...});
* flowKeyValue.save();
*
* // Updates existing flowKeyValue (has existing id)
* flowService.get().then(flowKeyValue => flowKeyValue.save());
*/
save() {
const service = new FlowService();
return ((this.id) ? service.insertKeyValue(this) : service.insertKeyValue(this));
}
}
export default FlowKeyValue;