-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
111 lines (106 loc) · 3.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import cloneDeep from 'lodash/cloneDeep'
import {
update,
deleteEntity,
fetch,
query,
create
} from '../../entity'
/**
* Labels allow you to group a collection of content within a stack. Using labels you can group content types that need to work together. Read more about <a href='https://www.contentstack.com/docs/developers/create-content-types/manage-labels'>Labels</a>.
* @namespace Label
*/
export function Label (http, data) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/labels`
if (data.label) {
Object.assign(this, cloneDeep(data.label))
this.urlPath = `/labels/${this.uid}`
/**
* @description The Update label call is used to update an existing label.
* @memberof Label
* @func update
* @returns {Promise<Label.Label>} Promise for Label instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).label('label_uid').fetch()
* .then((label) => {
* label.name = 'My New Content Type'
* return label.update()
* })
* .then((label) => console.log(label))
*
*/
this.update = update(http, 'label')
/**
* @description The Delete label call is used to delete a specific label.
* @memberof Label
* @func delete
* @returns {Object} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).label('label_uid').delete()
* .then((response) => console.log(response.notice))
*/
this.delete = deleteEntity(http)
/**
* @description The fetch Label returns information about a particular label of a stack.
* @memberof Label
* @func fetch
* @returns {Promise<Label.Label>} Promise for Label instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).label('label_uid').fetch()
* .then((label) => console.log(label))
*
*/
this.fetch = fetch(http, 'label')
} else {
/**
* @description The Create an label call creates a new label.
* @memberof Label
* @func create
* @returns {Promise<Label.Label>} Promise for Label instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const label = {
* name: 'First label',
* content_types: [singlepageCT.content_type.uid]
* }
* client.stack().label().create({ label })
* .then((label) => console.log(label))
*/
this.create = create({ http })
/**
* @description The Query on Label will allow to fetch details of all or specific Label.
* @memberof Label
* @param {Object} params - URI parameters
* @prop {Object} params.query - Queries that you can use to fetch filtered results.
* @func query
* @returns {Array<Label>} Array of Label.
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack().label().query({ query: { name: 'Label Name' } }).find()
* .then((label) => console.log(label))
*/
this.query = query({ http: http, wrapperCollection: LabelCollection })
}
}
export function LabelCollection (http, data) {
const obj = cloneDeep(data.labels) || []
const labelCollection = obj.map((userdata) => {
return new Label(http, { label: userdata, stackHeaders: data.stackHeaders })
})
return labelCollection
}