Skip to content

Commit 9263fde

Browse files
replaced query with fetchAll function
1 parent 57e0dfb commit 9263fde

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

lib/organization/team/stackRoleMapping/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*/
44
import cloneDeep from 'lodash/cloneDeep'
55
import {
6-
deleteEntity,
7-
fetchAll
6+
deleteEntity
87
} from '../../../entity'
98
import error from '../../../core/contentstackError'
109

@@ -98,11 +97,20 @@ export function StackRoleMappings (http, data) {
9897
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll
9998
* .then((response) => console.log(response))
10099
*/
101-
this.fetchAll = fetchAll(http, stackRoleMappingsCollection)
100+
this.fetchAll = async () => {
101+
try {
102+
const response = await http.get(this.urlPath)
103+
if (response.data) {
104+
return response.data
105+
}
106+
} catch (err) {
107+
throw error(err)
108+
}
109+
}
102110
}
103111
}
104112
export function stackRoleMappingsCollection (http, data) {
105-
const obj = cloneDeep(data) || []
113+
const obj = cloneDeep(data.stackRoleMappings) || []
106114
const stackRoleMappingCollection = obj.map((stackRoleMappings) => {
107115
return stackRoleMappings(http, { stackRoleMappings: stackRoleMappings })
108116
})

lib/organization/team/teamUsers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cloneDeep from 'lodash/cloneDeep'
22
import {
33
create,
44
deleteEntity,
5-
query
5+
fetchAll
66
} from '../../../entity'
77

88
export function TeamUsers (http, data) {
@@ -60,7 +60,7 @@ export function TeamUsers (http, data) {
6060
* .then((response) => console.log(response))
6161
*
6262
*/
63-
this.query = query({ http: http, wrapperCollection: UsersCollection })
63+
this.fetchAll = fetchAll(http, UsersCollection)
6464
}
6565
}
6666
export function UsersCollection (http, data) {

test/api/team-stack-role-mapping-test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ describe('Teams API Test', () => {
1616
})
1717
it('should fetch all stackRoleMappings', done => {
1818
makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => {
19-
response.items.forEach((stackRoleMapping) => {
20-
console.log(stackRoleMapping)
21-
})
22-
expect(response).to.be.not.equal(null)
19+
expect(response.stackRoleMappings).to.be.not.equal(undefined)
2320
done()
2421
})
2522
.catch(done)

test/api/team-users-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const organizationUid = 'organizationUid'
99
const teamUid = 'teamUid'
1010
const userId = 'userId'
1111

12-
describe('Teams API Test', () => {
12+
describe('Teams Users API Test', () => {
1313
beforeEach(() => {
1414
const user = jsonReader('loggedinuser.json')
1515
client = contentstackClient(user.authtoken)
@@ -32,8 +32,7 @@ describe('Teams API Test', () => {
3232
})
3333
it('should fetch all users', async () => {
3434
makeUsers(organizationUid, teamUid)
35-
.query()
36-
.find()
35+
.fetchAll()
3736
.then((response) => {
3837
response.items.forEach((user) => {
3938
expect(user.uidId).to.be.not.equal(null)

test/unit/team-users-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Contentstack Team Users test', () => {
99
it('should query and find all users', done => {
1010
var mock = new MockAdapter(Axios)
1111
mock.onGet(`/organizations/organization_uid/teams/team_uid/users`).reply(200, teamUsersMock)
12-
makeTeamUsers().query().find()
12+
makeTeamUsers().fetchAll()
1313
.then((users) => {
1414
users.items.forEach((user) => {
1515
expect(user.uidId).to.be.not.equal(null)

0 commit comments

Comments
 (0)