-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
95 lines (88 loc) · 2.85 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
import cloneDeep from 'lodash/cloneDeep'
import {
update,
deleteEntity,
fetch,
create
} from '../../../entity'
/**
* Folders refer to Asset Folders.
* @namespace Folder
*/
export function Folder (http, data = {}) {
if (data.stackHeaders) {
this.stackHeaders = data.stackHeaders
}
this.urlPath = `/assets/folders`
if (data.asset) {
Object.assign(this, cloneDeep(data.asset))
this.urlPath = `/assets/folders/${this.uid}`
/**
* @description The Update Folder call lets you update the name and description of an existing Folder.
* @memberof Folder
* @func update
* @returns {Promise<Folder.Folder>} Promise for Folder instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).asset().folder('uid').fetch()
* .then((folder) => {
* folder.name = 'My New folder'
* return folder.update()
* })
* .then((folder) => console.log(folder))
*
*/
this.update = update(http, 'asset')
/**
* @description The Delete folder call will delete an existing folder from the stack.
* @memberof Folder
* @func delete
* @returns {Object} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).asset().folder('uid').delete()
* .then((response) => console.log(response.notice))
*/
this.delete = deleteEntity(http)
/**
* @description The fetch an asset call returns comprehensive information about a specific version of an asset of a stack.
* @memberof Folder
* @func fetch
* @returns {Promise<Folder.Folder>} Promise for Folder instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).asset().folder('uid').fetch()
* .then((folder) => console.log(folder))
*
*/
this.fetch = fetch(http, 'asset')
} else {
/**
* @description The Create a folder into the assets.
* @memberof Folder
* @func create
* @returns {Promise<Folder.Folder>} Promise for Folder instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const asset = {name: 'My New contentType'}
* client.stack().asset().folder().create({ asset })
* .then((folder) => console.log(folder))
*/
this.create = create({ http: http })
}
}
export function FolderCollection (http, data) {
const obj = cloneDeep(data.assets) || []
const assetCollection = obj.map((userdata) => {
return new Folder(http, { asset: userdata, stackHeaders: data.stackHeaders })
})
return assetCollection
}