Manual Reference Source Test

src/helpers/content/ContentType.js

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

/**
 * Helper class representing a Content Type.
 */
class ContentType extends aggregate(ContentTypeModel, Helper) {
  /**
   * Constructor for helper class representing a Content Type
   *
   * @param {Object} json - json api response from server
   */
  constructor(json = {}) {
    super(json);
  }

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

  /**
   * Gets the attribute keys associated to this content type.
   *
   * @param  {Object} [params]            - Parameters used to get information from server
   * @param  {Number} [params.id]         - Id to get data from the server
   * @param  {Object} [params.filters]    - Filters to be used for get
   * @param  {String} [options]           - Modify the nature of the call and response
   * @param  {String} [options.url]       - Override the url for this call
   * @param  {String} [options.cacheMode] - Override the caching method for this call
   * @return {Promise}                    - Promise with data (array or object)
   *
   * @example
   * import { ContentType, clinical6 } from 'clinical6';
   * const contentType = new ContentType({ id: 23 });
   * contentType.getAttributes({ id: 5 });
   * contentType.getAttributes({ filters: { member_type: 'patient' }});
   *
   * // Combined with clinical6.get
   * clinical6.get(ContentType).then(contentType => { contentType[0].getAttributes() });
   */
  async getAttributes(params = {}, options = {}) {
    const service = serviceFactory.get(this.type);
    const attributes = { type: ContentAttribute.type };
    if (params.id) {
      attributes.id = params.id;
    } else if (params.filters) {
      attributes.filters = params.filters;
    }
    return service.getChildren(this, attributes, options);
  }
}

export default ContentType;