Manual Reference Source Test

src/helpers/esignaccount/SignAccount.js

import SignAccountModel from '../../models/esignaccount/SignAccount';
import Helper from '../Helper';
import { aggregate } from '../../utilities/ClassUtility';
import { serviceFactory } from '../../utilities/factories/ServiceFactory';

/**
 * Helper class representing a Consent Strategy.
 *
 * @extends {SignAccountModel}
 * @extends {Helper}
 *
 * @example
 * // To get a list of eSign Accounts use clinical6.get
 * import { clinical6, SignAccount } from 'clinical6';
 * clinical6.get(SignAccount).then(c => console.log(c));
 *
 * // To get a single SignAccount, you can also use clinical6
 * clinical6.get({ id: 5, type: 'adobe_sign__accounts'});
 *
 * // To save or insert, you can either use the .save() capability or clinical6
 * mySignAccount.save(); // insert if no id, save if id
 * clinical6.insert(new SignAccount({...}));
 * clinical6.update(mySignAccount);
*/
class SignAccount extends aggregate(SignAccountModel, Helper) {
  /**
   * Constructor for helper class representing a Consent Strategy
   *
   * @param {Object} json - json api response from server
   */
  constructor(json = {}) {
    super(json);
  }

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

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

  /**
   * Saves a sign account (insert if id doesn't exist, update if it does)
   * @return {Promise<SignAccount>} - Returns a promise via ajax call.
   *
   * @example
   * import { SignAccount, clinical6 } from 'clinical6';
   *
   * // Inserts new signAccount (no existing id)
   * const signAccount = new SignAccount(
   *   "type": "adobe_sign__accounts",
   *   "attributes": {
   *     "email": "account+email@parallel6.com",
   *     "first_name": "CanBe",
   *     "last_name": "Repeated"
   *     "company_name": "RepeatableCompany"
   *   });
   *
   * signAccount.save();
   *
   * // Updates existing signAccount(has existing id)
   * clinical6.get(SignAccount).then(signAccounts => signAccounts[0].save());
   */
  async save() {
    const service = serviceFactory.get(this.type);
    return (this.id) ? service.update(this) : service.insert(this);
  }
}

export default SignAccount;