Manual Reference Source Test

src/helpers/identifier/TemporaryId.js

import TempIdentifierModel from '../../models/identifier/TemporaryId';
import Helper from '../Helper';
import { aggregate } from '../../utilities/ClassUtility';
import TemporaryIdService from '../../services/TemporaryIdService';

/**
 * Helper class representing a Temporary Identifier.
 *
 * @extends {TempIdentifierModel}
 * @extends {Helper}
 *
 * @example
 * // To save or insert, you can either use the .save() capability or clinical6
 * myTempIdentifier.save(); // insert without id
 * clinical6.insert(new TemporaryId({...}));
 * clinical6.update(myTempIdentifier);
 *
*/
class TemporaryId extends aggregate(TempIdentifierModel, Helper) {
  /**
   * Constructor for helper class representing a Temporary Identifier
   *
   * @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 'temporary_identifiers';
  }

  /** @type {User} */
  get user() {
    return this._relationships.cohort;
  }

  /** @type {User} */
  set user(user) {
    /** @type {Cohort} */
    this._relationships.user = user;
  }

  /**
   * Saves a temporary identifier (insert only without id)
   * @return {Promise<TemporaryId>} - Returns a promise via ajax call.
   *
   * @example
   * import { TemporaryId } from 'clinical6';
   *
   * // Inserts new temporaryId (no existing id)
   * const temporaryId = new TemporaryId(
   *   "type": "temporary_identifiers",
   *   "attributes": {
   *   });
   *
   * temporaryId.save();
   *
   */
  async save() {
    return new TemporaryIdService().insert(this);
  }
}

export default TemporaryId;