import OlapicCategoriesHandler from 'OlapicDevKit-ES6/src/core/entities/category/category.handler.js'
OlapicCategoriesHandler
Extends:
The entities handler for the Olapic categories in DevKit. It's basically a set of static methods used to create and obtain categories from the API or DevKit itself.
Static Method Summary
Static Public Methods | ||
public static |
entityFromJSON(json: Object): OlapicCategoryEntity It parses a raw API JSON information and returns a category entity. |
|
public static |
extractEntities(obj: Object): Array When requesting a collection of entities, the API response contains an array instead of an
object, so this method will loop the array, create entities using |
|
public static |
Gets an Olapic category by its unique ID. |
|
public static |
Gets an Olapic category by its API url. |
Inherited Summary
From class OlapicEntitiesHandler | ||
public static get |
DevKit: OlapicDevKit: * A quick shortcut to get access to the DevKit singleton. |
|
public static |
getFormsFromObject(obj: Object): Object This will be used when creating an entity to parse any list of action forms and returns them with a better format. |
|
public static |
getResourcesFromObject(obj: Object): Object This will be used when creating an entity to parse any list of linked entities and returns them with a better format. |
Static Public Methods
public static entityFromJSON(json: Object): OlapicCategoryEntity source
It parses a raw API JSON information and returns a category entity.
Params:
Name | Type | Attribute | Description |
json | Object | The raw API JSON object to parse. |
Example:
let JSONInfo = {
metadata: {},
data: {
name: 'My Category',
},
};
let category = OlapicCategoriesHandler.entityFromJSON(JSONInfo);
// It will log 'My Category'
console.log(category.get('name'));
public static extractEntities(obj: Object): Array source
When requesting a collection of entities, the API response contains an array instead of an
object, so this method will loop the array, create entities using .entityFromJSON()
and
return a new array of entities.
Params:
Name | Type | Attribute | Description |
obj | Object | The API response with the array. |
Example:
let JSONInfo = {
metadata: {},
data: {
_embedded: {
category: [
{
name: 'Category One',
},
{
name: 'Category Two',
}
],
},
},
};
let entities = OlapicCategoriesHandler.extractEntities(JSONInfo);
// It will log 'Category One'
console.log(entities[0].get('name'));
public static getCategoryByID(ID: Number): Promise<OlapicCategoryEntity, Error> source
Gets an Olapic category by its unique ID.
Params:
Name | Type | Attribute | Description |
ID | Number | The category ID. |
Return:
Promise<OlapicCategoryEntity, Error> | The category entity or an |
Example:
OlapicCategoriesHandler.getCategoryByID(12)
.then((category) => {
console.log('Category: ', category);
});
public static getCategoryByUrl(url: String): Promise<OlapicCategoryEntity, Error> source
Gets an Olapic category by its API url.
Params:
Name | Type | Attribute | Description |
url | String | The Olapic API url for the category. |
Return:
Promise<OlapicCategoryEntity, Error> | The category entity or an |
Example:
OlapicCategoriesHandler.getCategoryByUrl('http://...')
.then((category) => {
console.log('Category: ', category);
});