Manual Reference Source Test

src/services/PlatformMenuService.js

import JsonApiService from './JsonApiService';
import {
  hasToken,
  isRequired,
  validate,
} from '../utilities/ValidationUtility';

/**
 * Service handling PlatformMenu calls with specific endpoints.
 */
class PlatformMenuService extends JsonApiService {
  /**
   * Update type to be platformMenus
   */
  constructor() {
    super('menus',
      {
        title: 'PlatformMenuService',
        obj: 'platformMenu',
        tokenRequired: ['delete', 'get', 'insert', 'update']
      });
  }

  /**
   * @override
   * Call a PATCH request on the main obj.type expecting JSON API information.
   *
   * @param  {PlatformMenu} platformMenu  - PlatformMenu object in which to update
   * @param  {String}       [cacheMode]  - Override the caching method for this call
   * @return {Promise}                    - Message
   *
   * @example
   * import { platformMenuService } from 'clinical6';
   *
   * // You will be able to delete a platformMenu using `delete`.
   * platformMenuService.delete({ id: 23 });
   * // This will also clear the local storage of this type and id
   */
  async delete(platformMenu, cacheMode = undefined) {
    validate('PlatformMenuService.delete',
      hasToken(),
      isRequired({ platformMenu }));
    return super.delete(platformMenu, { cacheMode });
  }

  /**
   * @override
   * Call a GET request expecting JSON API information.
   *
   * @throws {Clinical6Error}     - If missing token or missing required parameters
   * @param  {Object} [params]    - Parameters used to get information from server (such as id)
   * @param  {Number} [params.id] - Id of the platformMenu
   * @param  {String} [cacheMode] - Override the caching method for this call
   * @return {Promise<PlatformMenu[] | PlatformMenu>}
   *                              - Promise object that returns one platformMenu or a key:platformMenu hashtable
   *
   * @example
   * import { platformMenuService } from 'clinical6';
   *
   * // You will be able to access these platformMenus using the `get` method.
   * platformMenuService.get().then(platformMenus => console.log(platformMenus));
   *
   * // Additionally, you can retrieve the subcategories for a specific platformMenu with the `get`
   * // method, using the ID of the desired platformMenu as a parameter.
   * platformMenuService.get({ id: 23 }).then(platformMenu => console.log(platformMenu));
   */
  async get(params = {}, cacheMode = undefined) {
    validate('PlatformMenuService.get',
      hasToken());
    return super.get(params, { cacheMode })
      .then((menus) => {
        if (Array.isArray(menus)) {
          menus.forEach(menu => menu.syncRelationships());
        } else {
          menus.syncRelationships();
        }
        return menus;
      });
  }


  /**
   * @override
   * Call a POST request on the main obj.type expecting JSON API information.
   *
   * @param  {Object} [platformMenu]  - Parameters used to get information from server (such as id)
   * @param  {String} [cacheMode]     - Override the caching method for this call
   * @return {Promise<PlatformMenu>}  - Inserted platformMenu
   *
   * @example
   * import { PlatformMenu, platformMenuService } from 'clinical6';
   * const platformMenu = new PlatformMenu({...});
   *
   * // you can insert a platformMenu using the `insert` method.
   * platformMenuService.insert(platformMenu).then(platformMenu => console.log(platformMenu));
   *
   * // you could also just call `save` on the platformMenu if it doesn't have an id, which will also
   * // invoke the `insert` method
   * platformMenu.save();
   */
  async insert(platformMenu, cacheMode = undefined) {
    validate('PlatformMenuService.insert',
      hasToken(),
      isRequired({ platformMenu }));

    return super.insert(platformMenu, { cacheMode });
  }

  /**
   * @override
   * Call a PATCH request on the main obj.type expecting JSON API information.
   *
   * @param  {PlatformMenu} platformMenu  - PlatformMenu object in which to update
   * @param  {String}       [cacheMode]   - Override the caching method for this call
   * @return {Promise<PlatformMenu>}      - Updated platformMenu
   *
   * @example
   * import { PlatformMenu, platformMenuService } from 'clinical6';
   * const platformMenu = new PlatformMenu({...});
   *
   * // you can update a platformMenu using the `update` method.
   * platformMenuService.update(platformMenu).then(platformMenu => console.log(platformMenu));
   *
   * // you could also just call `save` on the platformMenu if it has an id, which will also
   * // invoke the `update` method
   * platformMenu.save();
   */
  async update(platformMenu, cacheMode = undefined) {
    validate('PlatformMenuService.update',
      hasToken(),
      isRequired({ platformMenu }));
    return super.update(platformMenu, { cacheMode });
  }
}

export default PlatformMenuService;