Manual Reference Source Test

src/helpers/trial/SiteContact.js

import SiteContactModel from '../../models/trial/SiteContact';
import { serviceFactory } from '../../utilities/factories/ServiceFactory';
import Helper from '../Helper';
import { aggregate } from '../../utilities/ClassUtility';

/**
 * Helper class representing a supported site contact.
 *
 * @extends {SiteContactModel}
 * @extends {Helper}
 *
 *
 * @example
 * // To save or insert, you can either use the .save() capability or clinical6
 * mySiteContact.save(); // insert if no id, save if id
 * clinical6.insert(new SiteContact({...}));
 * clinical6.update(mySiteContact);
 *
 */
class SiteContact extends aggregate(SiteContactModel, Helper) {
  /**
   * Constructor for helper class representing a SiteContact
   *
   * @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 'trials__site_contacts';
  }

  /** @type {Site} */
  get site() {
    return this._relationships.site;
  }

  /** @type {Site} */
  set site(site) {
    /** @type {Site} */
    this._relationships.site = site;
  }

  /**
   * Saves a siteContact (insert if id doesn't exist, update if it does)
   * @return {Promise<SiteContact>} - Returns a promise via ajax call.
   *
   * @example
   * import { SiteContact, clinical6 } from 'clinical6';
   *
   * // Insert a SiteContact
   * const siteContact = new SiteContact({...});
   * siteContact.save();
   *
   * // Updates existing siteContact (has existing id)
   * clinical6.get(SiteContact).then(siteContacts => siteContacts[0].save());
   */
  save() {
    const service = serviceFactory.get(this.type);
    return (this.id) ? service.update(this) : service.insert(this);
  }
}

export default SiteContact;