### File

`projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts`

### Index

###### Properties

- _headers
- _nodeTemplate
- data
- dataRelationships

###### Methods

- _createNode
- Private Async _fetchResource
- _json

### Constructor

`constructor()`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:29

### Properties

_headers
`_headers: `object``
Type : `object`
Default value : `{ 'Accept': 'application/vnd.api+json', 'Content-Type': 'application/vnd.api+json' }`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:7

_nodeTemplate
`_nodeTemplate: `object``
Type : `object`
Default value : `{ data: { type: "node--page", attributes: { "title": "new: node--page", // "langcode": "en", // "status": true, // "promote": false, // "sticky": false, // "default_langcode": true, "body": { "value": "new: node--page: body", // "format": "full_html", // "summary": "" } } } }`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:12

data
`data: `any``
Type : `any`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:5

dataRelationships
`dataRelationships: `object``
Type : `object`
Default value : `{}`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:6

### Methods

_createNode
`_createNode(nodeObject: any)`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:36

Parameters :

Name | Type | Optional | Default value
nodeObject | `any` | no | `this._nodeTemplate`

Returns : `any`

Private Async _fetchResource
`_fetchResource(url: string, params: any)`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:48

Parameters :

Name | Type | Optional | Default value
url | `string` | no |
params | `any` | no | `undefined`

Returns : `{}`

_json
`_json()`
Defined in projects/app-base-library/src/lib/shared/cms/drupal/entities/node.ts:44
Returns : `any`

    import {Util} from '../../../util/util';

    export class Node {

        data: any;
        dataRelationships = {};
        _headers = {
            'Accept': 'application/vnd.api+json',
            'Content-Type': 'application/vnd.api+json'
        };

        _nodeTemplate = {
            data: {
                type: "node--page",
                attributes: {
                    "title": "new: node--page",
                    // "langcode": "en",
                    // "status": true,
                    // "promote": false,
                    // "sticky": false,
                    // "default_langcode": true,
                    "body": {
                        "value": "new: node--page: body",
                        // "format": "full_html",
                        // "summary": ""
                    }
                }
            }
        };

        constructor() {

        }

        _createNode(nodeObject: any = this._nodeTemplate) {
            let node = Util.copy(this._nodeTemplate);
            node = Util.deepAssign(node, nodeObject);

            console.log(node);
            return node;
        }

        _json() {
            return JSON.stringify(this.data);
        }

        private async _fetchResource(url: string, params: any = undefined) {
            if (params) {
                url += '?';
                Object.keys(params).forEach(key => url += key + '=' + params[key] + '&');
            }
            let resource: any = await fetch(url, {headers: this._headers})
                .then((response) => {
                    if (response.status >= 400) {
                        throw new Error('Bad response from server');
                    }
                    return response.json();
                })
                .then((data) => {
                    return data;
                });
            return resource;
        }

    }

# results matching ""

# No results matching ""