33 */
44import cloneDeep from 'lodash/cloneDeep'
55import {
6- create ,
7- update ,
86 deleteEntity ,
97 fetchAll
108} from '../../../entity'
9+ import error from '../../../core/contentstackError'
1110
1211export function StackRoleMappings ( http , data ) {
13- console . log ( "🚀 ~ file: index.js:13 ~ StackRoleMappings ~ data:" , data )
1412 const _urlPath = `/organizations/${ data . organizationUid } /teams/${ data . teamUid } /stack_role_mappings`
1513 if ( data && data . stackApiKey ) {
1614 Object . assign ( this , cloneDeep ( data ) )
1715
18- this . urlPath = `${ _urlPath } /${ this . stackApiKey } `
16+ if ( this . organizationUid ) this . urlPath = `${ _urlPath } /${ this . stackApiKey } `
1917 /**
2018 * @description The update stackRoleMappings call is used to update the roles.
2119 * @memberof StackRoleMappings
@@ -33,7 +31,16 @@ export function StackRoleMappings (http, data) {
3331 * client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles)
3432 * .then((response) => console.log(response))
3533 */
36- this . update = update ( http , 'stackRoleMapping' )
34+ this . update = async ( updateData , params = { } ) => {
35+ try {
36+ const response = await http . put ( this . urlPath , updateData , { params } )
37+ if ( response . data ) {
38+ return response . data
39+ }
40+ } catch ( err ) {
41+ throw error ( err )
42+ }
43+ }
3744
3845 /**
3946 * @description The delete stackRoleMappings call is used to delete the roles.
@@ -49,7 +56,6 @@ export function StackRoleMappings (http, data) {
4956 */
5057 this . delete = deleteEntity ( http )
5158 } else {
52- // const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings`
5359 this . urlPath = _urlPath
5460 /**
5561 * @description The add stackRoleMappings call is used to add the roles.
@@ -69,7 +75,16 @@ export function StackRoleMappings (http, data) {
6975 * client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole)
7076 * .then((response) => console.log(response))
7177 */
72- this . add = create ( { http } )
78+ this . add = async ( updateData , params = { } ) => {
79+ try {
80+ const response = await http . post ( this . urlPath , updateData , { params } )
81+ if ( response . data ) {
82+ return response . data
83+ }
84+ } catch ( err ) {
85+ throw error ( err )
86+ }
87+ }
7388
7489 /**
7590 * @description The fetchAll stackRoleMappings call is used to fetchAll the roles.
@@ -87,9 +102,9 @@ export function StackRoleMappings (http, data) {
87102 }
88103}
89104export function stackRoleMappingsCollection ( http , data ) {
90- const obj = cloneDeep ( data . stackRoleMappings ) || [ ]
105+ const obj = cloneDeep ( data ) || [ ]
91106 const stackRoleMappingCollection = obj . map ( ( stackRoleMappings ) => {
92- return new StackRoleMappings ( http , { stackRoleMappings : stackRoleMappings } )
107+ return stackRoleMappings ( http , { stackRoleMappings : stackRoleMappings } )
93108 } )
94- return stackRoleMappingCollection
109+ return new StackRoleMappings ( http , stackRoleMappingCollection )
95110}
0 commit comments