JsonApiService
Extends:
Direct Subclass:
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 |
Call a DELETE request on the main obj.type expecting JSON API information. |
|
| public |
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 |
Call a POST request on the main obj.type expecting JSON API information. |
|
| public |
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#constructorPublic 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.
public async get(params: Object, options: String): Promise source
Call a GET request expecting JSON API information.
Params:
| Name | Type | Attribute | Description |
| params | Object |
|
Parameters used to get information from server |
| params.id | Number |
|
Id to get data from the server |
| params.type | String |
|
Type to be used for storage |
| params.filters | Object |
|
Filters to be used for get |
| params.page | Object |
|
Pagination object |
| params.page.size | Object |
|
Size of each page |
| params.page.number | Object |
|
The current page |
| params.page.first | Object |
|
The first page of data |
| params.page.last | Object |
|
The last page of data |
| params.page.prev | Object |
|
The previous page of data |
| params.page.next | Object |
|
The next page of data |
| params.sort | String |
|
The string on how things should be sorted, such as sort1,-sort2,sort3 |
| options | String |
|
Modify the nature of the call and response |
| options.url | String |
|
Override the url for this call |
| options.cacheMode | String |
|
Override the caching method for this call |
| options.meta | String |
|
Pass and retrieve through reference meta data |
Test:
- [unit] RelatedUserService.get should exist
- [unit] RelatedUserService.get should throw an error when there is no id
- [unit] RelatedUserService.get should throw an error when there is no type
- [unit] RelatedUserService.get should throw an error when there is no relationship
- [unit] RelatedUserService.get should return a promise
- [unit] RelatedUserService.get should receive a valid response for a get request with an id
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:
| Name | Type | Attribute | Description |
| 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 |
|
Parameters used to get information from server |
| child.id | Number |
|
Id to get data from the server |
| child.type | String |
|
Type to be used for storage |
| child.filters | Object |
|
Filters to be used for get |
| child.page | Object |
|
Pagination object |
| child.page.size | Number |
|
Size of each page |
| child.page.number | Number |
|
The current page |
| child.page.first | Number |
|
The first page of data |
| child.page.last | Number |
|
The last page of data |
| child.page.prev | Number |
|
The previous page of data |
| child.page.next | Number |
|
The next page of data |
| options | String |
|
Modify the nature of the call and response |
| options.url | String |
|
Override the url for this call |
| options.cacheMode | String |
|
Override the caching method for this call |
| options.meta | String |
|
Pass and retrieve through reference meta data |
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:
| Name | Type | Attribute | Description |
| obj | Object |
|
Object to be inserted |
| options | String |
|
Modify the nature of the call and response |
| options.url | String |
|
Override the url for this call |
| options.cacheMode | String |
|
Override the caching method for this call |
| options.meta | Object |
|
Pass and retrieve through reference meta data |
Manual
Reference
Source
Test
