@@ -347,15 +347,21 @@ export async function getOrganizationMergeSuggestions(
347347 continue
348348 }
349349
350- // Calculate similarity score between organizations
350+ const secondaryOrg = opensearchToFullOrg ( organizationToMerge . _source )
351+
351352 const similarityConfidenceScore = OrganizationSimilarityCalculator . calculateSimilarity (
352353 fullOrg ,
353- opensearchToFullOrg ( organizationToMerge . _source ) ,
354+ secondaryOrg ,
354355 )
355356
356- // Sort organizations: primary has more identities/activity, secondary is the one to merge
357- const organizationsSorted = [ fullOrg , opensearchToFullOrg ( organizationToMerge . _source ) ] . sort (
358- ( a , b ) => {
357+ let organizationsSorted : IOrganizationFullAggregatesOpensearch [ ]
358+ if ( secondaryOrgWithLfxMembership && ! primaryOrgWithLfxMembership ) {
359+ organizationsSorted = [ secondaryOrg , fullOrg ]
360+ } else if ( primaryOrgWithLfxMembership && ! secondaryOrgWithLfxMembership ) {
361+ organizationsSorted = [ fullOrg , secondaryOrg ]
362+ } else {
363+ // Sort organizations: primary has more identities/activity, secondary is the one to merge
364+ organizationsSorted = [ fullOrg , secondaryOrg ] . sort ( ( a , b ) => {
359365 if (
360366 a . identities . length > b . identities . length ||
361367 ( a . identities . length === b . identities . length && a . activityCount > b . activityCount )
@@ -368,8 +374,8 @@ export async function getOrganizationMergeSuggestions(
368374 return 1
369375 }
370376 return 0
371- } ,
372- )
377+ } )
378+ }
373379
374380 mergeSuggestions . push ( {
375381 similarity : similarityConfidenceScore ,
0 commit comments