UNPKG

1.27 kBJavaScriptView Raw
1const Group = require('./deal_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/deals/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/deals/properties/named/${name}`,
25 })
26 }
27
28 create(data) {
29 return this.client._request({
30 method: 'POST',
31 path: '/properties/v1/deals/properties',
32 body: data,
33 })
34 }
35
36 update(name, data) {
37 return this.client._request({
38 method: 'PUT',
39 path: `/properties/v1/deals/properties/named/${name}`,
40 body: data,
41 })
42 }
43
44 delete(name) {
45 return this.client._request({
46 method: 'DELETE',
47 path: `/properties/v1/deals/properties/named/${name}`,
48 })
49 }
50
51 upsert(data) {
52 return this.create(data).catch((err) => {
53 if (err.statusCode === 409) {
54 // if 409, the property already exists, update it
55 return this.update(data.name, data)
56 } else {
57 throw err
58 }
59 })
60 }
61}
62
63module.exports = Properties