1 | class Groups {
|
2 | constructor(client) {
|
3 | this.client = client
|
4 | }
|
5 |
|
6 | getAll(options) {
|
7 | return this.client._request({
|
8 | method: 'GET',
|
9 | path: '/properties/v1/companies/groups',
|
10 | qs: options,
|
11 | })
|
12 | }
|
13 |
|
14 | get(options) {
|
15 | return this.getAll(options)
|
16 | }
|
17 |
|
18 | create(data) {
|
19 | return this.client._request({
|
20 | method: 'POST',
|
21 | path: '/properties/v1/companies/groups',
|
22 | body: data,
|
23 | })
|
24 | }
|
25 |
|
26 | update(name, data) {
|
27 | return this.client._request({
|
28 | method: 'PUT',
|
29 | path: `/properties/v1/companies/groups/named/${name}`,
|
30 | body: data,
|
31 | })
|
32 | }
|
33 |
|
34 | upsert(data) {
|
35 | return this.create(data).catch((err) => {
|
36 | if (err.statusCode === 409) {
|
37 |
|
38 | return this.update(data.name, data)
|
39 | } else {
|
40 | throw err
|
41 | }
|
42 | })
|
43 | }
|
44 | }
|
45 |
|
46 | module.exports = Groups
|