-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
111 lines (107 loc) · 3.57 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
/**
* @namespace StackRoleMappings
*/
import cloneDeep from 'lodash/cloneDeep'
import {
deleteEntity
} from '../../../entity'
import error from '../../../core/contentstackError'
export function StackRoleMappings (http, data) {
const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings`
if (data && data.stackApiKey) {
Object.assign(this, cloneDeep(data))
if (this.organizationUid) this.urlPath = `${_urlPath}/${this.stackApiKey}`
/**
* @description The update stackRoleMappings call is used to update the roles.
* @memberof StackRoleMappings
* @func update
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const updateRoles = {
* roles: [
* 'roles_uid1',
* 'roles_uid2'
* ]
* }
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles)
* .then((response) => console.log(response))
*/
this.update = async (updateData, params = {}) => {
try {
const response = await http.put(this.urlPath, updateData, { params })
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}
/**
* @description The delete stackRoleMappings call is used to delete the roles.
* @memberof StackRoleMappings
* @func delete
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').delete()
* .then((response) => console.log(response))
*/
this.delete = deleteEntity(http)
} else {
this.urlPath = _urlPath
/**
* @description The add stackRoleMappings call is used to add the roles.
* @memberof StackRoleMappings
* @func add
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* const addRole = {
* 'stackApiKey: 'stackApiKey',
* 'roles': [
* 'role_uid'
* ]
* }
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole)
* .then((response) => console.log(response))
*/
this.add = async (updateData, params = {}) => {
try {
const response = await http.post(this.urlPath, updateData, { params })
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}
/**
* @description The fetchAll stackRoleMappings call is used to fetchAll the roles.
* @memberof StackRoleMappings
* @func fetchAll
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll
* .then((response) => console.log(response))
*/
this.fetchAll = async () => {
try {
const response = await http.get(this.urlPath)
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}
}
}