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

ItemResource

Extends:

Resource → ItemResource

API abstract item resource class.

Constructor Summary

Public Constructor
public

constructor(url: 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): Promise<this>

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): Promise

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): Promise<ResourceClass>

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): Promise<this>

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

Inherited Summary

From class Resource
public static

cloneObj(obj: Object): *

Helper method to make a deep copy clone of the passed object 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(url: string, auth: Object) source

Constructor

Override:

Resource#constructor

Params:

NameTypeAttributeDescription
url string

url of the item 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): Promise<this> source

Fetch this item resource from the REST API.

Params:

NameTypeAttributeDescription
timeout number
  • optional
  • default: 30000

request timeout

Return:

Promise<this>

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): Promise 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:

Promise

JS Promise

private _getResource(linkRelation: string, ResourceClass: Object, searchParams: Object, timeout: number): Promise<ResourceClass> 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:

Promise<ResourceClass>

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): Promise<this> 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:

Promise<this>

JS Promise, resolves to this object