@@ -5,7 +5,9 @@ import { PropertyCache } from 'default';
5
5
6
6
const TTL = 5 * 60 * 1000 ; // 5 Minute TTL in milliseconds
7
7
8
- const createPropertyGroup = async ( accessToken : string ) :Promise < void > => {
8
+
9
+ export const createPropertyGroupForContacts = async ( accessToken : string ) => {
10
+
9
11
hubspotClient . setAccessToken ( accessToken ) ;
10
12
try {
11
13
await hubspotClient . crm . properties . groupsApi . create ( "contact" , {
@@ -18,7 +20,24 @@ const createPropertyGroup = async (accessToken: string):Promise => {
18
20
}
19
21
} ;
20
22
21
- const createRequiredProperty = async ( accessToken : string ) : Promise < void > => {
23
+
24
+ export const createPropertyGroupForCompanies = async ( accessToken : string ) => {
25
+ hubspotClient . setAccessToken ( accessToken ) ;
26
+ try {
27
+ const propertyGroupCreateResponse =
28
+ await hubspotClient . crm . properties . groupsApi . create ( "company" , {
29
+ name : "integration_properties" ,
30
+ label : "Integration Properties" ,
31
+ displayOrder : 13 ,
32
+ } ) ;
33
+ } catch ( error ) {
34
+ console . error ( error ) ;
35
+ }
36
+ } ;
37
+
38
+
39
+ export const createRequiredContactProperty = async ( accessToken : string ) => {
40
+
22
41
hubspotClient . setAccessToken ( accessToken ) ;
23
42
try {
24
43
await hubspotClient . crm . properties . coreApi . create ( "contact" , {
@@ -34,8 +53,46 @@ const createRequiredProperty = async (accessToken: string): Promise => {
34
53
}
35
54
} ;
36
55
56
+ export const createContactIdProperty = async ( accessToken : string ) => {
57
+ hubspotClient . setAccessToken ( accessToken ) ;
58
+ try {
59
+ const propertyCreateResponse =
60
+ await hubspotClient . crm . properties . coreApi . create ( "contact" , {
61
+ name : "native_system_contact_identifier" ,
62
+ label : "Native System Contact Identifier" ,
63
+ type : "string" ,
64
+ description : "This can be used in place of email adress ot uniquely identify a contact" ,
65
+ fieldType : "text" ,
66
+ groupName : "integration_properties" ,
67
+ hasUniqueValue :true
68
+ } ) ;
69
+ } catch ( error ) {
70
+ console . error ( error ) ;
71
+ }
72
+ } ;
73
+
74
+ export const createCompanyIdProperty = async ( accessToken : string ) => {
75
+ hubspotClient . setAccessToken ( accessToken ) ;
76
+ try {
77
+ const propertyCreateResponse =
78
+ await hubspotClient . crm . properties . coreApi . create ( "company" , {
79
+ name : "native_system_company_identifier" ,
80
+ label : "Native System Company Identifier" ,
81
+ type : "string" ,
82
+ description : "This can be used in place of email adress ot uniquely identify a contact" ,
83
+ fieldType : "text" ,
84
+ groupName : "integration_properties" ,
85
+ hasUniqueValue : true
86
+ } ) ;
87
+ } catch ( error ) {
88
+ console . error ( error ) ;
89
+ }
90
+ } ;
91
+
92
+
37
93
const checkPropertiesCache = async ( customerId : string ) : Promise < PropertyCache | undefined > => {
38
94
try {
95
+
39
96
const cacheResults = await prisma . hubSpotPropertiesCache . findFirst ( {
40
97
where : { customerId } ,
41
98
select : { updatedAt : true , propertyData : true } ,
@@ -72,7 +129,9 @@ const saveHubSpotPropertiesToCache = async (
72
129
}
73
130
} ;
74
131
75
- const getHubSpotProperties = async ( customerId : string , skipCache : boolean ) : Promise < { contactProperties : any ; companyProperties : any ; } | undefined > => {
132
+
133
+ export const getHubSpotProperties = async ( customerId : string , skipCache : boolean ) : Promise < { contactProperties : any ; companyProperties : any ; } | undefined > => {
134
+
76
135
// const propertiesCacheIsValid = await checkPropertiesCache(customerId);
77
136
78
137
const accessToken : string = await getAccessToken ( customerId ) ;
@@ -106,8 +165,10 @@ const getHubSpotProperties = async (customerId: string, skipCache: boolean): Pro
106
165
}
107
166
} ;
108
167
109
- const getNativeProperties = async ( customerId : string ) : Promise < Properties [ ] | undefined > => {
168
+
169
+ export const getNativeProperties = async ( customerId : string ) : Promise < Properties [ ] | undefined > => {
110
170
try {
171
+
111
172
const properties = await prisma . properties . findMany ( {
112
173
select : {
113
174
name : true ,
@@ -127,9 +188,3 @@ const getNativeProperties = async (customerId: string): Promise
127
188
}
128
189
} ;
129
190
130
- export {
131
- getHubSpotProperties ,
132
- getNativeProperties ,
133
- createPropertyGroup ,
134
- createRequiredProperty ,
135
- } ;
0 commit comments