UNPKG

1.14 kBJavaScriptView Raw
1const Group = require('./company_property_group')
2
3class Properties {
4 constructor(client) {
5 this.client = client
6 this.groups = new Group(this.client)
7 }
8
9 getAll(options) {
10 return this.client._request({
11 method: 'GET',
12 path: '/properties/v1/companies/properties',
13 qs: options,
14 })
15 }
16
17 get(options) {
18 return this.getAll(options)
19 }
20
21 getByName(name) {
22 return this.client._request({
23 method: 'GET',
24 path: `/properties/v1/companies/properties/named/${name}`,
25 })
26 }
27
28 create(data) {
29 return this.client._request({
30 method: 'POST',
31 path: '/properties/v1/companies/properties',
32 body: data,
33 })
34 }
35
36 update(name, data) {
37 return this.client._request({
38 method: 'PUT',
39 path: `/properties/v1/companies/properties/named/${name}`,
40 body: data,
41 })
42 }
43
44 upsert(data) {
45 return this.create(data).catch((err) => {
46 if (err.statusCode === 409) {
47 // if 409, the property already exists, update it
48 return this.update(data.name, data)
49 } else {
50 throw err
51 }
52 })
53 }
54}
55
56module.exports = Properties