ProjectContent
The ProjectContent class wraps custom API endpoints in a simple and quick set of objects /
methods. This object will contain many properties belonging to the type when returned from the
server. A ProjectContent for a car, for example, may have myCar.make
or myCar.model
in
addition to the listed properties.
Example:
let labs1 = new ProjectContent('site_start/labs'); // commonly used
let labs2 = new ProjectContent('site_start/labs', { version: 'v2' });
let labs3 = new ProjectContent('site_start/labs', { id: 23 }); // commonly used
let labs4 = new ProjectContent('site_start/labs', {}, { make: 'corolla' });
Constructor Summary
Public Constructor | ||
public |
constructor(type: String, options: any, data: any) Creates an instance of ProjectContent. |
Member Summary
Public Members | ||
public get |
Return meta data for the project content. |
|
public set |
This is used to manage the
|
|
public get |
This is used to manage the |
Private Members | ||
private set |
Set _data to set information to the current object. |
|
private get |
Get _data to quickly get the raw data without options. |
|
private |
|
|
private |
|
Method Summary
Public Methods | ||
public |
Add child of type belonging to the ProjectContent |
|
public |
getAll(): Promise<ProjectContent[]> Gets all data belonging to the ProjectContent ownerType |
|
public |
Get one child with id and type belonging to the ProjectContent |
|
public |
getChildren(type: String): Promise<Array> Get all children with type belonging to the ProjectContent |
|
public |
Gets data belonging to this ProjectContent (ownerType and owner). |
|
public |
getSibling(id: Number): Promise<ProjectContent> Get data belonging to a sibling provided the id assuming ProjectContent's type |
|
public |
removeChild(type: String, id: Number): Promise<any> Remove child of type belonging to the ProjectContent |
|
public |
Saves the current ProjectContent object. |
|
public |
updateChild(type: String, child: Object, id: Number): Promise<any> Update child of type belonging to the ProjectContent |
Public Constructors
public constructor(type: String, options: any, data: any) source
Creates an instance of ProjectContent.
Params:
Name | Type | Attribute | Description |
type | String |
|
Type of the ProjectContent ('site_start/labs') |
options | any |
|
Options available to support the API. Version = 'v2' |
data | any |
|
The data of the object |
Public Members
public get meta: Object source
Return meta data for the project content. The data it consumes is required to come at the
root of the API endpoint with the meta
key containing keys pointing to arrays of data.
For example {"meta": { "certificate_types": [ {"value": ..., "label": ...} ] }}
could then
be obtained through myProjectContent.meta['certificate_types']
public set options: Object source
This is used to manage the _options
property
- owner (unique identifier / id)
- ownerType (content type)
- version
Private Members
Public Methods
public addChild(type: String, child: Object): Promise<Object> source
Add child of type belonging to the ProjectContent
Example:
let lab = new ProjectContent('site_start/labs', { id: 23 });
let lab_director = { first_name: 'Joe', last_name: 'Waldron' };
await lab.addChild('lab_directors', lab_director).then((data) => (lab_director = data));
public getAll(): Promise<ProjectContent[]> source
Gets all data belonging to the ProjectContent ownerType
Example:
let labs = new ProjectContent('site_start/labs');
labs.getAll().then((list) => {
console.log(list);
});
// or alternatively in one line
(new ProjectContent('site_start/labs')).getAll().then((list) => console.log(list));
public getChild(type: String, id: Number): Promise<Object> source
Get one child with id and type belonging to the ProjectContent
Example:
let lab = new ProjectContent('site_start/labs', { id: 23 });
let lab_director = await lab.getChild('lab_directors', 512);
public getChildren(type: String): Promise<Array> source
Get all children with type belonging to the ProjectContent
Params:
Name | Type | Attribute | Description |
type | String | The type of the children to be returned |
Example:
let lab = new ProjectContent('site_start/labs', { id: 23 });
let lab_directors = await lab.getChildren('lab_directors');
public getData(): Promise<Object> source
Gets data belonging to this ProjectContent (ownerType and owner). Stores data in ProjectContent.
Example:
let lab = new ProjectContent('site_start/labs');
lab.getAll().then((list) => {
list[0].getData().then(() => console.log(list[0])); // should have new properties
});
lab = new ProjectContent('site_start/labs', { id: 23 });
lab.getData().then(() => console.log(lab)); // should have new properties
lab.meta; // Accumulates through getData, getChildren, and getSibling calls
public getSibling(id: Number): Promise<ProjectContent> source
Get data belonging to a sibling provided the id assuming ProjectContent's type
Params:
Name | Type | Attribute | Description |
id | Number | The id of the sibling |
Example:
let lab = new ProjectContent('site_start/labs', { id: 23 });
let other_lab = await lab.getSibling(24);
public removeChild(type: String, id: Number): Promise<any> source
Remove child of type belonging to the ProjectContent
Example:
let lab = new ProjectContent('site_start/labs', { id: 23 });
let lab_director = await lab.removeChild('lab_directors', 512);
public save(): Promise<any> source
Saves the current ProjectContent object. If it has an id, then update else insert.
Example:
// Create new lab
let lab = new ProjectContent('site_start/labs');
lab.name = 'La Jolla Clinic';
await lab.save(); // id does not exist so it inserts, but will now have name
// Update existing lab name
lab.name = 'New Name';
lab.save();
public updateChild(type: String, child: Object, id: Number): Promise<any> source
Update child of type belonging to the ProjectContent
Example:
let lab = new ProjectContent('site_start/labs', { id: 23 });
let lab_directors = await lab.getChildren('lab_directors');
lab_directors[0].first_name = 'Joe';
lab.updateChild('lab_directors', lab_directors[0]);