-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
72 lines (67 loc) · 2.39 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
import cloneDeep from 'lodash/cloneDeep'
import {
create,
deleteEntity,
fetchAll
} from '../../../entity'
export function TeamUsers (http, data) {
if (data && data.userId) {
Object.assign(this, cloneDeep(data))
const _urlPath = `/organizations/${this.organizationUid}/teams/${this.teamUid}/users/${data.userId}`
if (this.organizationUid) this.urlPath = _urlPath
/**
* @description The Remove teamUser call is used to remove an existing user of that team.
* @memberof TeamUsers
* @func remove
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').remove()
* .then((response) => console.log(response))
*
*/
this.remove = deleteEntity(http)
} else {
this.urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/users`
/**
* @description The Add teamUser call is used to add an user the team.
* @memberof TeamUsers
* @func add
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const usersMail = {
* emails: ['emailId1','emailId2' ]
* }
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').add(usersMail)
* .then((response) => console.log(response))
*
*/
this.add = create({ http })
/**
* @description The Query on teamUser will allow to fetch details of all teamUsers.
* @memberof TeamUsers
* @func query
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const usersMail = {
* emails: ['emailId1','emailId2' ]}
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').query().find()
* .then((response) => console.log(response))
*
*/
this.fetchAll = fetchAll(http, UsersCollection)
}
}
export function UsersCollection (http, data) {
const obj = cloneDeep(data.users) || []
const usersCollection = obj.map((userId) => {
return new TeamUsers(http, { userId })
})
return usersCollection
}