@@ -100,22 +100,24 @@ function clean(groupData) {
100
100
cleanArray ( groupData , "rules" ) ;
101
101
cleanArray ( groupData , "transformation" ) ;
102
102
103
- for ( let i = 0 ; groupData . objects && i < groupData . objects . length ; i ++ ) {
104
- Object . values ( idTypes ) . forEach ( ( idType ) => {
105
- if ( groupData . objects [ i ] [ idType ] ) {
106
- cleanArray ( groupData . objects [ i ] , idType ) ;
103
+ if ( groupData . objects ) {
104
+ groupData . objects = groupData . objects . filter ( ( { shared_ids, ...extIds } , i ) => {
105
+ const shouldKeep = shared_ids || getCommonElements ( Object . keys ( extIds ) , Object . values ( idTypes ) ) . length ;
106
+
107
+ if ( shouldKeep ) {
108
+ Object . values ( idTypes ) . forEach ( ( idType ) => {
109
+ if ( groupData . objects [ i ] [ idType ] ) {
110
+ cleanArray ( groupData . objects [ i ] , idType ) ;
111
+ }
112
+ } ) ;
113
+
114
+ if ( groupData . objects [ i ] . shared_ids ) {
115
+ cleanArray ( groupData . objects [ i ] , "shared_ids" ) ;
116
+ groupData . objects [ i ] . shared_ids = groupData . objects [ i ] . shared_ids . map ( x => utils . uuidToString ( x ) ) ;
117
+ }
107
118
}
108
- } ) ;
109
119
110
- if ( groupData . objects [ i ] . shared_ids ) {
111
- cleanArray ( groupData . objects [ i ] , "shared_ids" ) ;
112
- groupData . objects [ i ] . shared_ids = groupData . objects [ i ] . shared_ids . map ( x => utils . uuidToString ( x ) ) ;
113
- }
114
- }
115
-
116
- if ( groupData . objects ) {
117
- groupData . objects = groupData . objects . filter ( ( { shared_ids, ...extIds } ) => {
118
- return shared_ids || Object . keys ( extIds ) . some ( ( v ) => Object . values ( idTypes ) . includes ( v ) ) ;
120
+ return shouldKeep ;
119
121
} ) ;
120
122
}
121
123
@@ -132,8 +134,7 @@ async function getObjectIds(account, model, branch, revId, groupData, convertSha
132
134
if ( groupData . rules && groupData . rules . length > 0 ) {
133
135
return Meta . findObjectIdsByRules ( account , model , groupData . rules , branch , revId , convertSharedIDsToString , showIfcGuids ) ;
134
136
} else {
135
- const res = await getObjectsArray ( model , branch , revId , groupData , convertSharedIDsToString , showIfcGuids ) ;
136
- return res ;
137
+ return getObjectsArray ( model , branch , revId , groupData , convertSharedIDsToString , showIfcGuids ) ;
137
138
}
138
139
}
139
140
@@ -142,10 +143,10 @@ async function getObjectsArray(model, branch, revId, groupData, convertSharedIDs
142
143
return Promise . all ( groupData . objects . map ( async ( { account, model :container , shared_ids, ...extIds } ) => {
143
144
144
145
if ( showIfcGuids ) {
145
- if ( extIds [ idTypes . IFC ] ) {
146
- return { account, model : container , [ idTypes . IFC ] : extIds [ idTypes . IFC ] } ;
146
+ if ( ! shared_ids ) {
147
+ // if we're storing other external Ids, just return empty array (not converting).
148
+ return { account, model : container , [ idTypes . IFC ] : extIds [ idTypes . IFC ] ?? [ ] } ;
147
149
}
148
- return { account, model : container , [ idTypes . IFC ] : [ ] } ;
149
150
} else if ( shared_ids ) {
150
151
return { account, model : container , shared_ids : convertSharedIDsToString ? shared_ids . map ( utils . uuidToString ) : shared_ids . map ( utils . stringToUUID ) } ;
151
152
}
@@ -199,16 +200,16 @@ function getObjectsArrayAsExternalIds(account, model, branch, rId, data) {
199
200
200
201
// have to have shared_ids, IFC or RVT ids, but not more than one
201
202
if (
202
- ( ! containerEntry [ idTypes . IFC ] && ! containerEntry [ idTypes . RVT ] && ! containerEntry . shared_ids ) &&
203
- ! ( containerEntry [ idTypes . IFC ] && ! containerEntry [ idTypes . RVT ] && ! containerEntry . shared_ids ) &&
204
- ! ( ! containerEntry [ idTypes . IFC ] && containerEntry [ idTypes . RVT ] && ! containerEntry . shared_ids ) &&
203
+ ( ! containerEntry [ idTypes . IFC ] && ! containerEntry [ idTypes . RVT ] && ! containerEntry . shared_ids ) ||
204
+ ! ( containerEntry [ idTypes . IFC ] && ! containerEntry [ idTypes . RVT ] && ! containerEntry . shared_ids ) ||
205
+ ! ( ! containerEntry [ idTypes . IFC ] && containerEntry [ idTypes . RVT ] && ! containerEntry . shared_ids ) ||
205
206
! ( ! containerEntry [ idTypes . IFC ] && ! containerEntry [ idTypes . RVT ] && containerEntry . shared_ids )
206
207
) {
207
208
return Promise . reject ( responseCodes . INVALID_GROUP ) ;
208
209
}
209
210
210
211
if ( ! containerEntry . shared_ids ) {
211
- return data ;
212
+ return containerEntry ;
212
213
}
213
214
214
215
try {
0 commit comments