UNPKG

2.36 kBJavaScriptView Raw
1const Property = require('./company_property')
2
3class Company {
4 constructor(client) {
5 this.client = client
6 this.properties = new Property(this.client)
7 }
8
9 getById(id) {
10 return this.client._request({
11 method: 'GET',
12 path: `/companies/v2/companies/${id}`,
13 })
14 }
15
16 get(options) {
17 return this.client._request({
18 method: 'GET',
19 path: '/companies/v2/companies/paged',
20 qs: options,
21 qsStringifyOptions: {
22 arrayFormat: 'repeat',
23 },
24 })
25 }
26
27 getAll(options) {
28 return this.get(options)
29 }
30
31 getRecentlyCreated(options) {
32 return this.client._request({
33 method: 'GET',
34 path: '/companies/v2/companies/recent/created',
35 qs: options,
36 })
37 }
38
39 getRecentlyModified(options) {
40 return this.client._request({
41 method: 'GET',
42 path: '/companies/v2/companies/recent/modified',
43 qs: options,
44 })
45 }
46
47 getByDomain(domain, data) {
48 return this.client._request({
49 method: 'POST',
50 path: `/companies/v2/domains/${domain}/companies`,
51 body: data,
52 })
53 }
54
55 create(data) {
56 return this.client._request({
57 method: 'POST',
58 path: '/companies/v2/companies',
59 body: data,
60 })
61 }
62
63 delete(id) {
64 return this.client._request({
65 method: 'DELETE',
66 path: `/companies/v2/companies/${id}`,
67 })
68 }
69
70 update(id, data) {
71 return this.client._request({
72 method: 'PUT',
73 path: `/companies/v2/companies/${id}`,
74 body: data,
75 })
76 }
77
78 updateBatch(data) {
79 return this.client._request({
80 method: 'POST',
81 path: '/companies/v1/batch-async/update',
82 body: data,
83 })
84 }
85
86 addContactToCompany(data) {
87 if (!data || !data.companyId || !data.contactVid) {
88 return Promise.reject(new Error('companyId and contactVid params must be provided'))
89 }
90
91 return this.client._request({
92 method: 'PUT',
93 path: `/companies/v2/companies/${data.companyId}/contacts/${data.contactVid}`,
94 })
95 }
96
97 getContactIds(id, options) {
98 return this.client._request({
99 method: 'GET',
100 path: `/companies/v2/companies/${id}/vids`,
101 qs: options,
102 })
103 }
104
105 getContacts(id, options) {
106 return this.client._request({
107 method: 'GET',
108 path: `/companies/v2/companies/${id}/contacts`,
109 qs: options,
110 })
111 }
112}
113
114module.exports = Company