Manual Reference Source Test
import JsonApiService from 'clinical6/src/services/JsonApiService.js'
public class | source

JsonApiService

Extends:

AbstractService → JsonApiService

An abstract class to handle generic get, insert, update, delete json api calls.

Note: This class is intended to be extended and not used directly.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

options: *

Method Summary

Public Methods
public

async delete(obj: Object, options: String): Promise

Call a DELETE request on the main obj.type expecting JSON API information.

public

async get(params: Object, options: String): Promise

Call a GET request expecting JSON API information.

public

async getChildren(parent: Object, child: Object, options: String): Promise

Call a GET request expecting JSON API information for children given a parent.

public

async insert(obj: Object, options: String): Promise

Call a POST request on the main obj.type expecting JSON API information.

public

async update(obj: Object, options: String): Promise

Call a PATCH request on the main obj.type expecting JSON API information.

Inherited Summary

From class AbstractService
public get
public set
public
private

Public Constructors

public constructor() source

Setup the cacheMode to be the client's setup

Override:

AbstractService#constructor

Public Members

public options: * source

Public Methods

public async delete(obj: Object, options: String): Promise source

Call a DELETE request on the main obj.type expecting JSON API information.

Params:

NameTypeAttributeDescription
obj Object
  • optional

Object to be deleted

options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Message

Test:

public async get(params: Object, options: String): Promise source

Call a GET request expecting JSON API information.

Params:

NameTypeAttributeDescription
params Object
  • optional

Parameters used to get information from server

params.id Number
  • optional

Id to get data from the server

params.type String
  • optional

Type to be used for storage

params.filters Object
  • optional

Filters to be used for get

params.page Object
  • optional

Pagination object

params.page.size Object
  • optional

Size of each page

params.page.number Object
  • optional

The current page

params.page.first Object
  • optional

The first page of data

params.page.last Object
  • optional

The last page of data

params.page.prev Object
  • optional

The previous page of data

params.page.next Object
  • optional

The next page of data

params.sort String
  • optional

The string on how things should be sorted, such as sort1,-sort2,sort3

options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

options.meta String
  • optional

Pass and retrieve through reference meta data

Return:

Promise

Promise with data (array or object)

Test:

public async getChildren(parent: Object, child: Object, options: String): Promise source

Call a GET request expecting JSON API information for children given a parent.

Params:

NameTypeAttributeDescription
parent Object

Parameters used to get information from server

parent.id Number

Id to get data from the server

parent.type String

Type to be used for storage

child Object
  • optional

Parameters used to get information from server

child.id Number
  • optional

Id to get data from the server

child.type String
  • optional

Type to be used for storage

child.filters Object
  • optional

Filters to be used for get

child.page Object
  • optional

Pagination object

child.page.size Number
  • optional

Size of each page

child.page.number Number
  • optional

The current page

child.page.first Number
  • optional

The first page of data

child.page.last Number
  • optional

The last page of data

child.page.prev Number
  • optional

The previous page of data

child.page.next Number
  • optional

The next page of data

options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

options.meta String
  • optional

Pass and retrieve through reference meta data

Return:

Promise

Promise with data (array or object)

Example:

import { siteService, mobileUserService, SiteMember } from 'clinical6';

siteService.getChildren(site, { type: 'trials/site_members' });
siteService.getChildren(site, new SiteMember());
mobileUserService.getChildren(user, { type: 'ediary/entries' });  // generates /v3/mobile_users/:id/ediary/entries

public async insert(obj: Object, options: String): Promise source

Call a POST request on the main obj.type expecting JSON API information.

Params:

NameTypeAttributeDescription
obj Object
  • optional

Object to be inserted

options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

options.meta Object
  • optional

Pass and retrieve through reference meta data

Return:

Promise

Promise with object

public async update(obj: Object, options: String): Promise source

Call a PATCH request on the main obj.type expecting JSON API information.

Params:

NameTypeAttributeDescription
obj Object
  • optional

Object to be updated

options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Promise with object

Test: