@@ -36,25 +36,33 @@ export class OrganizationService extends LoggerBase {
36
36
// if exists in cache update it
37
37
const updateData : Partial < IOrganization > = { }
38
38
// no need to update name since it's aka primary key
39
- if ( data . url ) updateData . url = data . url
40
- if ( data . description ) updateData . description = data . description
41
- if ( data . emails ) updateData . emails = data . emails
42
- if ( data . logo ) updateData . logo = data . logo
43
- if ( data . tags ) updateData . tags = data . tags
44
- if ( data . github ) updateData . github = data . github as IOrganizationSocial
45
- if ( data . twitter ) updateData . twitter = data . twitter as IOrganizationSocial
46
- if ( data . linkedin ) updateData . linkedin = data . linkedin as IOrganizationSocial
47
- if ( data . crunchbase ) updateData . crunchbase = data . crunchbase as IOrganizationSocial
48
- if ( data . employees ) updateData . employees = data . employees
49
- if ( data . location ) updateData . location = data . location
50
- if ( data . website ) updateData . website = data . website
51
- if ( data . type ) updateData . type = data . type
52
- if ( data . size ) updateData . size = data . size
53
- if ( data . headline ) updateData . headline = data . headline
54
- if ( data . industry ) updateData . industry = data . industry
55
- if ( data . founded ) updateData . founded = data . founded
39
+ const fields = [
40
+ 'url' ,
41
+ 'description' ,
42
+ 'emails' ,
43
+ 'logo' ,
44
+ 'tags' ,
45
+ 'github' ,
46
+ 'twitter' ,
47
+ 'linkedin' ,
48
+ 'crunchbase' ,
49
+ 'employees' ,
50
+ 'location' ,
51
+ 'website' ,
52
+ 'type' ,
53
+ 'size' ,
54
+ 'headline' ,
55
+ 'industry' ,
56
+ 'founded' ,
57
+ ]
58
+ fields . forEach ( ( field ) => {
59
+ if ( data [ field ] && ! isEqual ( data [ field ] , cached [ field ] ) ) {
60
+ updateData [ field ] = data [ field ]
61
+ }
62
+ } )
56
63
if ( Object . keys ( updateData ) . length > 0 ) {
57
64
await this . repo . updateCache ( cached . id , updateData )
65
+ cached = { ...cached , ...updateData } // Update the cached data with the new data
58
66
}
59
67
} else {
60
68
// if it doesn't exists in cache create it
@@ -91,11 +99,9 @@ export class OrganizationService extends LoggerBase {
91
99
// now check if exists in this tenant
92
100
const existing = await this . repo . findByName ( tenantId , segmentId , data . name )
93
101
94
- const displayName = existing ?. displayName ? existing ?. displayName : data ?. name
95
-
96
102
let attributes = existing ?. attributes
97
103
98
- if ( data . attributes ) {
104
+ if ( data ? .attributes ) {
99
105
const temp = mergeWith ( { } , existing ?. attributes , data ?. attributes )
100
106
if ( ! isEqual ( temp , existing ?. attributes ) ) {
101
107
attributes = temp
@@ -104,28 +110,37 @@ export class OrganizationService extends LoggerBase {
104
110
105
111
if ( existing ) {
106
112
// if it does exists update it
107
- await this . repo . update ( existing . id , {
108
- name : cached . name ,
109
- displayName,
110
- url : cached . url ,
111
- description : cached . description ,
112
- emails : cached . emails ,
113
- logo : cached . logo ,
114
- tags : cached . tags ,
115
- github : cached . github ,
116
- twitter : cached . twitter ,
117
- linkedin : cached . linkedin ,
118
- crunchbase : cached . crunchbase ,
119
- employees : cached . employees ,
120
- location : cached . location ,
121
- website : cached . website ,
122
- type : cached . type ,
123
- size : cached . size ,
124
- headline : cached . headline ,
125
- industry : cached . industry ,
126
- founded : cached . founded ,
127
- attributes,
113
+ const updateData : Partial < IOrganization > = { }
114
+ const fields = [
115
+ 'name' ,
116
+ 'displayName' ,
117
+ 'url' ,
118
+ 'description' ,
119
+ 'emails' ,
120
+ 'logo' ,
121
+ 'tags' ,
122
+ 'github' ,
123
+ 'twitter' ,
124
+ 'linkedin' ,
125
+ 'crunchbase' ,
126
+ 'employees' ,
127
+ 'location' ,
128
+ 'website' ,
129
+ 'type' ,
130
+ 'size' ,
131
+ 'headline' ,
132
+ 'industry' ,
133
+ 'founded' ,
134
+ 'attributes' ,
135
+ ]
136
+ fields . forEach ( ( field ) => {
137
+ if ( cached [ field ] && ! isEqual ( cached [ field ] , existing [ field ] ) ) {
138
+ updateData [ field ] = cached [ field ]
139
+ }
128
140
} )
141
+ if ( Object . keys ( updateData ) . length > 0 ) {
142
+ await this . repo . update ( existing . id , updateData )
143
+ }
129
144
130
145
return existing . id
131
146
} else {
0 commit comments