Home Reference Source
import {ItemResource} from '@fnndsc/chrisstoreapi'
public class | source

ItemResource

Extends:

Resource → ItemResource

API abstract item resource class.

Constructor Summary

Public Constructor
public

constructor(itemUrl: string, auth: Object)

Constructor

Member Summary

Public Members
public
public get

Get the item's data object (REST API descriptors).

Method Summary

Public Methods
public

get(timeout: number): Object

Fetch this item resource from the REST API.

public

Get an array of parameter names that can be used as properties of the data object in PUT requests.

Private Methods
private

_delete(timeout: number): Object

Internal helper method to make a DELETE request to this item resource through the REST API.

private

_getResource(linkRelation: string, ResourceClass: Object, searchParams: Object, timeout: number): Object

Internal method to fetch a related resource from the REST API that is referenced by a link relation within the item object.

private

_put(data: Object, uploadFileObj: Object, timeout: number): Object

Internal helper method to make a PUT request to this item resource through the REST API.

Inherited Summary

From class Resource
public get

Return true if the resource object contains any data.

public
public
public
public
public

Make a deep copy clone of this object resource.

Public Constructors

public constructor(itemUrl: string, auth: Object) source

Constructor

Override:

Resource#constructor

Params:

NameTypeAttributeDescription
itemUrl string

url of the resource

auth Object
  • optional
  • default: null

authentication object

auth.token string
  • optional

authentication token

Public Members

public collection: * source

Override:

Resource#collection

public get data: Object source

Get the item's data object (REST API descriptors).

Public Methods

public get(timeout: number): Object source

Fetch this item resource from the REST API.

Params:

NameTypeAttributeDescription
timeout number
  • optional
  • default: 30000

request timeout

Return:

Object

JS Promise, resolves to this object

public getPUTParameters(): string[] source

Get an array of parameter names that can be used as properties of the data object in PUT requests.

Return:

string[] (nullable: true)

array of PUT data property name or null if this list resource's data has not been fetched from the API yet or it doesn't support PUT requests.

Private Methods

private _delete(timeout: number): Object source

Internal helper method to make a DELETE request to this item resource through the REST API.

Params:

NameTypeAttributeDescription
timeout number
  • optional
  • default: 30000

request timeout

Return:

Object

JS Promise

private _getResource(linkRelation: string, ResourceClass: Object, searchParams: Object, timeout: number): Object source

Internal method to fetch a related resource from the REST API that is referenced by a link relation within the item object.

Params:

NameTypeAttributeDescription
linkRelation string
ResourceClass Object
searchParams Object
  • optional
  • default: null

search parameters object which is resource-specific

searchParams.limit number
  • optional

page limit

searchParams.offset number
  • optional

page offset

timeout number
  • optional
  • default: 30000

request timeout

Return:

Object

JS Promise, resolves to a ResourceClass object

Throw:

RequestException

throw error if this item resource has not yet been fetched from the REST API

RequestException

throw error when the link relation is not found

private _put(data: Object, uploadFileObj: Object, timeout: number): Object source

Internal helper method to make a PUT request to this item resource through the REST API.

Params:

NameTypeAttributeDescription
data Object

request JSON data object

uploadFileObj Object
  • nullable: true

custom file object

uploadFileObj.fname Object

file blob

timeout number
  • optional
  • default: 30000

request timeout

Return:

Object

JS Promise, resolves to this object