Manual Reference Source Test

src/helpers/consent/ApproverGroupAssignment.js

import ApproverGroupAssignmentModel from '../../models/consent/ApproverGroupAssignment';
import { serviceFactory } from '../../utilities/factories/ServiceFactory';
import Helper from '../Helper';
import { aggregate } from '../../utilities/ClassUtility';

/**
 * Helper class representing an consent approver group assignment.
 *
 * @extends {ApproverGroupAssignmentModel}
 * @extends {Helper}
 *
 *
 * @example
 * // To get a list of Approver Group Assignments you must have the approver group first, then get it based on this approver group
 * import { clinical6, ApproverGroupAssignment } from 'clinical6';
 * const approverGroup = new ApproverGroup({...}); // get the approverGroup in some way
 * approverGroup.getApproverGroupAssignments().then(a => console.log(a)); // use getApproverGroupAssignments
 * clinical6.getChildren(approverGroup, ApproverGroupAssignment).then(a => console.log(a)); // or using get children
 *
 * // To get a single approverGroup, you can also use clinical6
 * clinical6.get({ id: 5, type: 'consent__approver_groups'});
 *
 * // To save or insert, you can either use the .save() capability or clinical6
 * myApproverGroupAssignment.save(); // insert if no id, save if id
 * clinical6.insert(new ApproverGroupAssignment({...}));
 * clinical6.update(myApproverGroupAssignment);
 *
 * // To delete, use clinical6 or .delete();
 * myApproverGroupAssignment.delete();
 * clinical6.delete(myApproverGroupAssignment);
 */
class ApproverGroupAssignment extends aggregate(ApproverGroupAssignmentModel, Helper) {
  /**
   * Constructor for helper class representing an ApproverGroupAssignment
   *
   * @param {Object} json - json api response from server
   */
  constructor(json = {}) {
    super(json);
    this.deserializeRelationshipStubs(json);
    this.syncRelationships(json);
  }

  /** @type {String}  - The type */
  static get type() {
    return 'consent__approver_group_assignments';
  }

  /** @type {ConsentFormVersion} */
  get formVersion() {
    return this._relationships.form_version;
  }

  /** @type {ConsentFormVersion} */
  set formVersion(formVersion) {
    /** @type {ConsentFormVersion} */
    this._relationships.form_version = formVersion;
  }

  /** @type {ApproverGroup} */
  get approverGroup() {
    return this._relationships.approver_group;
  }

  /** @type {ApproverGroup} */
  set approverGroup(approverGroup) {
    /** @type {ApproverGroup} */
    this._relationships.approver_group = approverGroup;
  }

  /**
   * Deletes an ApproverGroupAssignment
   * @return {Promise} - Returns a promise via ajax call.
   *
   * @example
   * import { ApproverGroupAssignment, Client } from 'clinical6';
   *
   * // Removes approverGroupAssignment from server and local storage
   * const approverGroupAssignment = new ApproverGroupAssignment({...});
   * approverGroupAssignment.delete();
   *
   * // No longer in storage
   * Client.instance.storageUtility.has('consent__approver_group_assignments', { id: 1 });
   */
  delete() {
    const service = serviceFactory.get(this.type);
    return service.delete(this);
  }

  /**
   * Saves a approverGroupAssignment (insert if id doesn't exist, update if it does)
   * @return {Promise<ApproverGroupAssignment>} - Returns a promise via ajax call.
   *
   * @example
   * import { ApproverGroupAssignment, clinical6 } from 'clinical6';
   *
   * // Insert is different from other inserts.
   * const approverGroupAssignment = new ApproverGroupAssignment({...});
   * approverGroupAssignment.save();
   *
   * // After you have the authtoken and then you've logged in
   *
   * // Updates existing approverGroupAssignment (has existing id)
   * clinical6.get(ApproverGroupAssignment).then(approverGroupAssignments => approverGroupAssignments[0].save());
   */
  save() {
    const service = serviceFactory.get(this.type);
    return (this.id) ? service.update(this) : service.insert(this);
  }
}

export default ApproverGroupAssignment;