Manual Reference Source Test

src/models/content/ContentAttribute.js

import { fieldsToSnake } from '../../utilities/ClassUtility';

/**
 * Model representing a Content Attribute Model.
 */
class ContentAttributeModel {
  /**
   * @param {Object}  response                - JSON formatted response of a content attribute.
   * @param {Number}  response.id             - The invitation id value
   * @param {String}  response.name           - Content Attribute's name
   * @param {String}  response.attribute_type - Content Attribute's attribute type
   * @param {Boolean} response.required       - Content Attribute's required
   * @param {Number}  response.position       - Content Attribute's position
   * @param {String}  response.display_name   - Content Attribute's display name
   * @param {String}  response.default_value  - Content Attribute's default value
   * @param {String}  response.show_on_index  - Content Attribute's show on index
   * @param {String}  response.status         - Content Attribute's status
   * @param {String}  response.created_at     - Content Attribute's created date
   * @param {String}  response.updated_at     - Content Attribute's updated date
   */
  constructor(response = {}) {
    const _response = response.data || response; // if json api is passed in directly
    const attributes = fieldsToSnake(_response.attributes || _response); // if json api is passed in directly or camel format fields

    if (_response.id) {
      /** @type {Number} */
      this.id = parseInt(_response.id, 10);
    }

    /** @type {String} */
    this.name = attributes.name;

    /** @type {String} */
    this.attributeType = attributes.attribute_type;

    /** @type {Boolean} */
    this.required = attributes.required;

    /** @type {Number} */
    this.position = attributes.position;

    /** @type {String} */
    this.displayName = attributes.display_name;

    /** @type {String} */
    this.defaultValue = attributes.default_value;

    /** @type {Boolean} */
    this.showOnIndex = attributes.show_on_index;

    /** @type {String} */
    this.status = attributes.status;

    /** @type {String} */
    this.createdAt = attributes.created_at;

    /** @type {String} */
    this.updatedAt = attributes.updated_at;
  }
}

export default ContentAttributeModel;