Manual Reference Source Test

src/helpers/content/ContentAttribute.js

import Helper from '../Helper';
import ContentAttributeModel from '../../models/content/ContentAttribute';
import { aggregate } from '../../utilities/ClassUtility';
import { serviceFactory } from '../../utilities/factories/ServiceFactory';

/**
 * Helper class representing an eDiary Entry Group.
 *
 * @extends {ContentAttributeModel}
 * @extends {Helper}
 */
class ContentAttribute extends aggregate(ContentAttributeModel, Helper) {
  /**
   * Constructor for helper class representing an eDiary Entry Group
   *
   * @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 'dynamic_content__attribute_keys';
  }

  /** @type {ContentType} */
  get contentType() {
    return this._relationships.content_type;
  }

  /** @type {ContentType} */
  set contentType(contentType) {
    /** @type {ContentType} */
    this._relationships.content_type = contentType;
  }


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

  /**
   * Saves a content attribute (insert if id doesn't exist, update if it does)
   * @return {Promise<ContentAttribute>} - Returns a promise via ajax call.
   *
   * @example
   * import { ContentAttribute, clinical6 } from 'clinical6';
   *
   * // Inserts new contentAttribute (no existing id)
   * const contentAttribute = new ContentAttribute(
   *   "type": "dynamic_content__attribute_keys",
   *   "attributes": {
   *     "required": true
   *   });
   *
   * contentAttribute.save();
   *
   * // Updates existing contentAttribute(has existing id)
   * clinical6.get(ContentAttribute).then(contentAttributes => contentAttributes[0].save());
   */
  async save() {
    const service = serviceFactory.get(this.type);
    return (this.id) ? service.update(this) : service.insert(this);
  }
}

export default ContentAttribute;